ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

ExpandoObject Print

Dynamic Print method for ExpandoObject

Source

public static void Print(this ExpandoObject dynamicObject)
{
    var dynamicDictionary = dynamicObject as IDictionary<string, object>;

    foreach(KeyValuePair<string, object> property in dynamicDictionary)
    {
        Console.WriteLine("{0}: {1}", property.Key, property.Value.ToString());
    }
    Console.WriteLine();
}

Example

var dynamicObject = new ExpandoObject();

dynamicObject["Property"] = "Value";
dynamicObject.OtherProperty = 46;

dynamicObject.Print();

Author: Radu Matei

Submitted on: 4 aug. 2016

Language: C#

Type: ExpandoObject

Views: 5927