I'm trying to write a generic utility for use via COM from outside .NET (/skip long story). Anyway, I'm trying to add properties to an ExpandoObject and I need to get PropertyInfo structure back to pass to another routine.
using System.Collections.Generic;
using System.Diagnostics;
using System.Dynamic;
using System.Reflection;
public class ExpandoTest
{
public string testThis(string cVariable)
{
string cOut = "";
ExpandoObject oRec = new ExpandoObject { };
IDictionary<string, object> oDict = (IDictionary<string, object>)oRec;
oDict.Add(cVariable, "Test");
Trace.WriteLine(cVariable);
Trace.WriteLine(oDict[cVariable]);
PropertyInfo thisProp = oRec.GetType().GetProperty(cVariable);
if (thisProp != null)
{
cOut= "Got a property :)";
}
return cOut;
}
}
Why do I always get a null in in thisProp? I clearly don't understand but I've been staring at it for a day and I'm not getting anywhere. All help/criticism thankfully accepted!