Skip to content

ExpandoObject

Coding Seb edited this page May 30, 2019 · 4 revisions

From version 1.2.2 ExpressionEvaluator manage ExpandObject class. ExpandoObject are object that can dynamically create new properties when you assign a value to it. It is also a dictionnary of properties. In ExpressionEvaluator you can use it as a object or as a dictionnary.

Here some examples :

myVar = new ExpandoObject();

myVar.X = 23.5;
myVar.Y = 34.8;

return myVar.X + myVar.Y;
// 58.3
myVar = new ExpandoObject();

myVar["Text"] = "Hello ";

return myVar["Text"] + " Bob" ;
// "Hello Bob"
myVar = new ExpandoObject();

myVar["Text"] = "Hello ";

return myVar.Text + " Bob" ;
// "Hello Bob"
myVar = new ExpandoObject();

myVar.Text = "Hello ";

return myVar["Text"] + " Bob" ;
// "Hello Bob"
obj = new ExpandoObject();

obj.Add = (x, y) => 
{
    text = "The result is : ";
    return text + (x+y).ToString();
};

return obj.Add(3, 4);
// "The result is : 7"

Anonymous Objects

And from version 1.3.7 ExpandoObject can be created as anonymous objects:

obj = new {
    Text = "Hello",
    IntValue = 8,
    Add = (x, y) =>
    {
        text = "The result is : ";
        return text + (x+y).ToString();
    }
};

Table Of Content

Clone this wiki locally