Search code examples
c#.netvb.netpodio

VB.Net syntax for date range filter


I am coding to the Podio .Net API using VB, but having difficulty porting the example C# code for a date range dictionary item to the VB.Net equivalent. Here is a snippet from their .NET API client documentation:

var filter = new Dictionary<string, object>
{
    {"somekey", from = new DateTime(2013, 9, 1), to = new DateTime(2013, 9, 30) }
};

I am not experienced in C#, so would appreciate any help in the equivalent VB syntax.


Solution

  • The online converters handle this very poorly. SLaks mentioned that we could be calling an extension method here which combines the 2 dates into the Dictionary value, but I could not get this to work in C#, so I don't think that is the case.

    The only way to make sense of your original C# code is if we assume that you either did not copy it correctly or the API documentation was wrong, and that the code was intended to be:

    var filter = new Dictionary<string, object>()
    {
        {"somekey", new { from = new DateTime(2013, 9, 1), to = new DateTime(2013, 9, 30)} }
    };
    

    In this case, the conversion is straightforward and it seems to correspond to what worked for you as mentioned in your comment:

    Dim filter = New Dictionary(Of String, Object)() From {
        {
            "somekey", New With {
                Key .from = New Date(2013, 9, 1),
                Key .to = New Date(2013, 9, 30)
            }
        }
    }
    

    And to be fair, the online converter mentioned previously does convert this adjusted C# code fine.