how to filter out DateTime type of values from all hashtable value?

I need to convert all DateTime values to String, though out my project, all of my code at the end follows 1 function, where I have 4 different Hashtables (actually XmlRpcStruct Object of CookComputing xmlrpc library).

is there any way that without iterating on each hash table - I can convert the values of hashtable having datetime -> string.

without iterating - I mean just to make the processing faster, but I need to solve it for nested hashtables where key contains another hashtable too.

Answers


You could process your hashtable, just before sending to that server. Inspect each object. Is it really a DateTime, then replace it with a .ToString with the appropriate format.

public static void ProcessHT(Hashtable ht)
{
    Hashtable dates = new Hashtable();

    foreach(DictionaryEntry de in ht)
    {
        if (de.Value is DateTime)
            dates.Add(de.Key, de.Value);
    }

    foreach(DictionaryEntry de in dates)
    {
        ht.Remove(de.Key);
        ht.Add(de.Key, ((DateTime)de.Value).ToString("s"));
    }
}

public static void RunSnippet()
{
    Hashtable ht = new Hashtable();

    ht.Add("1", "one");
    ht.Add("date", DateTime.Today);
    ht.Add("num", 1);
    Print(ht);
    WL("---");
    ProcessHT(ht);
    Print(ht);
}

private static void Print(Hashtable ht)
{
    foreach (DictionaryEntry de in ht)
    {
        WL("{0} = {1}", de.Key, de.Value);
    }
}

Why can't you just convert the date to a time when you are adding it into the hashtable?

myHashTable.Add("ADate", DateTime.Now.ToString());

Need Your Help

why my dropzone doesn't work properly

c# jquery asp.net-mvc dropzone.js

i used this tutorial for create dropzone area in my web application mvc 5.

which jboss-javaee-6.0 version on jboss 7.1.0

java maven jboss version pom.xml

i create a example maven application and deployed it to jboss 7.1.0 thunder.