VB has had a "sort-of" dynamic (via Options), but can this be done in VB.NET
for Framework 3.5 or 4.0 ? I don't think so -
var json = "";
// a couple of lines of code omitted = getting the json as a string from a
URL
dynamic result = new JsonFx.Json.JsonReader().Read(json);
DisplayDynamicProperties(result);
Then
// recursive
public static void DisplayDynamicProperties(dynamic obj)
{
Boolean bFlag = true;
if (obj is System.Array)
{
foreach (var item in obj)
{
DisplayDynamicProperties(item);
}
}
else
{
foreach (var property in (IDictionary<string, object>)obj)
{
if (property.Value is System.Array)
{
var array = property.Value as System.Array;
for (int i = 0; i < array.Length; i++)
DisplayDynamicProperties(array.GetValue(i));
}
else
{
Console.WriteLine(property.Key + ": " +
property.Value);
s1 = s1 + property.Key + ": " + property.Value +
Environment.NewLine;
if (property.Key == "a" &&
(Convert.ToString(property.Value).Length == 7))
{
if
(Convert.ToString(property.Value).Substring(0, 3) != "999")
{
s2 = s2 + property.Value + " ";
bFlag = true;
}
else
{
bFlag = false;
}
}
else if (property.Key == "a" &&
(Convert.ToString(property.Value).Length == 6))
{
s2 = s2 + " " + property.Value + ": ";
}
else if ((property.Key == "b") && (bFlag == true))
{
s2 = s2 + property.Value +
Environment.NewLine;
nSeries += 1;
}
else if ((property.Key == "f") && (bFlag == true))
{
s2 = s2 + " (" + property.Value + " to ";
}
else if ((property.Key == "g") && (bFlag == true))
{
s2 = s2 + property.Value + ")" +
Environment.NewLine;
}
}
}
}
}
}
This is a bit convoluted and has some code extraneous to the C# to VB issue,
but I've edited out a lot of the additional cr4p to make it readable. It's
just some json parsing which attempts to be reasonably flexible for my small
test project.
_____
Ian Thomas
Victoria Park, Western Australia
_____
From: [email protected] [mailto:[email protected]]
On Behalf Of David Kean
Sent: Tuesday, October 04, 2011 9:35 AM
To: ozDotNet
Subject: RE: In praise of DirectoryInfo Framework 4
While I like C#'s dynamic better than VB's (although I'm sure if Bill's
still floating around he'll argue differently) - VB actually supported
'dynamic' from day 1 . :-)
From: [email protected] [mailto:[email protected]]
On Behalf Of Ian Thomas
Sent: Monday, October 03, 2011 6:15 PM
To: 'ozDotNet'
Subject: RE: In praise of DirectoryInfo Framework 4
You are right of course, David.
Strange that this
<http://msdn.microsoft.com/en-us/library/system.io.directoryinfo.enumeratedi
rectories(VS.90).aspx> page exists, more than a year after its last edit
date . obviously it is a problem with the MSDN doco since the
.enumeratedirectory (etc) doesn't work with v3.5 target.
I have been using v4.0 for all disk file traversing, and for the Dynamic
keyword in C# 4.0 - I think this will be in Visual Basic too, when the v4.5
Framework is released.
_____
Ian Thomas
Victoria Park, Western Australia