C# Class Westwind.Utilities.Expando

Inheritance: System.Dynamic.DynamicObject, IDynamicMetaObjectProvider
Mostra file Open project: RickStrahl/WestwindToolkit Class Usage Examples

Public Properties

Property Type Description
Properties PropertyBag

Private Properties

Property Type Description

Public Methods

Method Description
Contains ( object>.KeyValuePair item, bool includeInstanceProperties = false ) : bool

Checks whether a property exists in the Property collection or as a property on the instance

Expando ( ) : System

This constructor just works off the internal dictionary and any public properties of this object. Note you can subclass Expando.

Expando ( object>.IDictionary dict ) : System

Create an Expando from a dictionary

Expando ( object instance ) : System

Allows passing in an existing instance variable to 'extend'.

You can pass in null here if you don't want to check native properties and only check the Dictionary!

GetDynamicMemberNames ( ) : IEnumerable

Return both instance and dynamic names. Important to return both so JSON serialization with Json.NET works.

GetProperties ( bool includeInstanceProperties = false ) : object>>.IEnumerable

Returns and the properties of

TryGetMember ( GetMemberBinder binder, object &result ) : bool

Try to retrieve a member by name first from instance properties followed by the collection entries.

TryInvokeMember ( InvokeMemberBinder binder, object args, object &result ) : bool

Dynamic invocation method. Currently allows only for Reflection based operation (no ability to add methods dynamically).

TrySetMember ( SetMemberBinder binder, object value ) : bool

Property setter implementation tries to retrieve value from instance first then into this object

this ( string key ) : object

Convenience method that provides a string Indexer to the Properties collection AND the strongly typed properties of the object by name. // dynamic exp["Address"] = "112 nowhere lane"; // strong var name = exp["StronglyTypedProperty"] as string;

The getter checks the Properties dictionary first then looks in PropertyInfo for properties. The setter checks the instance properties before checking the Properties dictionary.

Protected Methods

Method Description
GetProperty ( object instance, string name, object &result ) : bool

Reflection Helper method to retrieve a property

Initialize ( object instance ) : void
InvokeMethod ( object instance, string name, object args, object &result ) : bool

Reflection helper method to invoke a method

SetProperty ( object instance, string name, object value ) : bool

Reflection helper method to set a property value

Method Details

Contains() public method

Checks whether a property exists in the Property collection or as a property on the instance
public Contains ( object>.KeyValuePair item, bool includeInstanceProperties = false ) : bool
item object>.KeyValuePair
includeInstanceProperties bool
return bool

Expando() public method

This constructor just works off the internal dictionary and any public properties of this object. Note you can subclass Expando.
public Expando ( ) : System
return System

Expando() public method

Create an Expando from a dictionary
public Expando ( object>.IDictionary dict ) : System
dict object>.IDictionary
return System

Expando() public method

Allows passing in an existing instance variable to 'extend'.
You can pass in null here if you don't want to check native properties and only check the Dictionary!
public Expando ( object instance ) : System
instance object
return System

GetDynamicMemberNames() public method

Return both instance and dynamic names. Important to return both so JSON serialization with Json.NET works.
public GetDynamicMemberNames ( ) : IEnumerable
return IEnumerable

GetProperties() public method

Returns and the properties of
public GetProperties ( bool includeInstanceProperties = false ) : object>>.IEnumerable
includeInstanceProperties bool
return object>>.IEnumerable

GetProperty() protected method

Reflection Helper method to retrieve a property
protected GetProperty ( object instance, string name, object &result ) : bool
instance object
name string
result object
return bool

Initialize() protected method

protected Initialize ( object instance ) : void
instance object
return void

InvokeMethod() protected method

Reflection helper method to invoke a method
protected InvokeMethod ( object instance, string name, object args, object &result ) : bool
instance object
name string
args object
result object
return bool

SetProperty() protected method

Reflection helper method to set a property value
protected SetProperty ( object instance, string name, object value ) : bool
instance object
name string
value object
return bool

TryGetMember() public method

Try to retrieve a member by name first from instance properties followed by the collection entries.
public TryGetMember ( GetMemberBinder binder, object &result ) : bool
binder System.Dynamic.GetMemberBinder
result object
return bool

TryInvokeMember() public method

Dynamic invocation method. Currently allows only for Reflection based operation (no ability to add methods dynamically).
public TryInvokeMember ( InvokeMemberBinder binder, object args, object &result ) : bool
binder System.Dynamic.InvokeMemberBinder
args object
result object
return bool

TrySetMember() public method

Property setter implementation tries to retrieve value from instance first then into this object
public TrySetMember ( SetMemberBinder binder, object value ) : bool
binder System.Dynamic.SetMemberBinder
value object
return bool

this() public method

Convenience method that provides a string Indexer to the Properties collection AND the strongly typed properties of the object by name. // dynamic exp["Address"] = "112 nowhere lane"; // strong var name = exp["StronglyTypedProperty"] as string;
The getter checks the Properties dictionary first then looks in PropertyInfo for properties. The setter checks the instance properties before checking the Properties dictionary.
public this ( string key ) : object
key string
return object

Property Details

Properties public_oe property

String Dictionary that contains the extra dynamic values stored on this object/instance
Using PropertyBag to support XML Serialization of the dictionary
public PropertyBag Properties
return PropertyBag