namespace Qwerty
{
public static class Asdfg
{
private static dynamic xp = new ExpandoObject();
public static void BuildTheExpandoObject(string[] arrayOfPropNames, double[] arrayOfDoubles)
{
System.Diagnostics.Debug.Assert(arrayOfPropNames.Count() == arrayOfDoubles.Count());
Asdfg.xp.DoubleArray = arrayOfDoubles;
Func<int, double> funcintdouble = (i) => Asdfg.xp.DoubleArray[i];
Asdfg.xp.DoubleArrayValue = funcintdouble;
string s0 = arrayOfPropNames[0];
Asdfg.xp.s0 = arrayOfDoubles[0];
string s1 = arrayOfPropNames[1];
Asdfg.xp.s1 = arrayOfDoubles[1];
string s2 = arrayOfPropNames[2];
Asdfg.xp.s2 = arrayOfDoubles[2];
}
public static dynamic GetExpandoObject()
{
return Asdfg.xp;
}
}
}
namespace Example_ExpandoObject
{
class Program
{
static void Main(string[] args)
{
string[] arrayOfPropNames = { "SiO2", "Al2O3", "Fe2O3", };
double[] arrayOfDoubles = { -12345, 0, 67890, };
Qwerty.Asdfg.BuildTheExpandoObject(arrayOfPropNames, arrayOfDoubles);
//
// ---
//
int index0 = 0;
Console.WriteLine("value index {0} = {1}"
, index0
, Qwerty
.Asdfg
.GetExpandoObject()
.DoubleArrayValue(index0)
);
int index2 = 2;
Console.WriteLine("value index {0} = {1}"
, index2
, Qwerty
.Asdfg
.GetExpandoObject()
.DoubleArrayValue(index2)
);
Console.WriteLine("type at index {0} = {1}"
, index2
, Qwerty
.Asdfg
.GetExpandoObject()
.DoubleArrayValue(index2)
.GetType()
);
//
// ---
//
string s0 = arrayOfPropNames[0];
Console.WriteLine("property {0} = {1}"
, s0
, Qwerty
.Asdfg
.GetExpandoObject()
.s0
);
string s1 = arrayOfPropNames[1];
Console.WriteLine("property {0} = {1}"
, s1
, Qwerty
.Asdfg
.GetExpandoObject()
.s1
);
string s2 = arrayOfPropNames[2];
Console.WriteLine("property {0} = {1}"
, s2
, Qwerty
.Asdfg
.GetExpandoObject()
.s2
);
Console.ReadKey();
}
}
}
Ridiculously simple.
•
... after VC# team, of course.
•
... don't disturb ... life is short, and I have to think what I'll do next ...
No comments:
Post a Comment