Show / Hide Table of Contents

Class ExpandoBase

Class that provides extensible properties and methods. This dynamic object stores 'extra' properties in a dictionary or checks the actual properties of the instance. This means you can subclass this expando and retrieve either native properties or properties from values in the dictionary.

This type allows you three ways to access its properties:

  • Directlyany explicitly declared properties are accessible
  • Dynamicdynamic cast allows access to dictionary and native properties/methods
  • DictionaryAny of the extended properties are accessible via IDictionary interface

Inheritance
System.Object
System.Dynamic.DynamicObject
ExpandoBase
Expando
Implements
IExpando
System.Dynamic.IDynamicMetaObjectProvider
IIndexable
Inherited Members
System.Dynamic.DynamicObject.GetMetaObject(System.Linq.Expressions.Expression)
System.Dynamic.DynamicObject.TryBinaryOperation(System.Dynamic.BinaryOperationBinder, System.Object, System.Object)
System.Dynamic.DynamicObject.TryConvert(System.Dynamic.ConvertBinder, System.Object)
System.Dynamic.DynamicObject.TryCreateInstance(System.Dynamic.CreateInstanceBinder, System.Object[], System.Object)
System.Dynamic.DynamicObject.TryDeleteIndex(System.Dynamic.DeleteIndexBinder, System.Object[])
System.Dynamic.DynamicObject.TryDeleteMember(System.Dynamic.DeleteMemberBinder)
System.Dynamic.DynamicObject.TryGetIndex(System.Dynamic.GetIndexBinder, System.Object[], System.Object)
System.Dynamic.DynamicObject.TryInvoke(System.Dynamic.InvokeBinder, System.Object[], System.Object)
System.Dynamic.DynamicObject.TrySetIndex(System.Dynamic.SetIndexBinder, System.Object[], System.Object)
System.Dynamic.DynamicObject.TryUnaryOperation(System.Dynamic.UnaryOperationBinder, System.Object)
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: Kephas.Dynamic
Assembly: Kephas.Core.dll
Syntax
public abstract class ExpandoBase : DynamicObject, IExpando, IDynamicMetaObjectProvider, IIndexable

Constructors

| Improve this Doc View Source

ExpandoBase(IDictionary<String, Object>)

Initializes a new instance of the ExpandoBase class. This constructor just works off the internal dictionary.

Declaration
protected ExpandoBase(IDictionary<string, object> innerDictionary = null)
Parameters
Type Name Description
System.Collections.Generic.IDictionary<System.String, System.Object> innerDictionary

The inner dictionary for holding dynamic values (optional). If not provided, a new dictionary will be created.

| Improve this Doc View Source

ExpandoBase(Object, IDictionary<String, Object>)

Initializes a new instance of the ExpandoBase class. Allows passing in an existing instance variable to 'extend'.

Declaration
protected ExpandoBase(object innerObject, IDictionary<string, object> innerDictionary = null)
Parameters
Type Name Description
System.Object innerObject

The instance to be extended.

System.Collections.Generic.IDictionary<System.String, System.Object> innerDictionary

The inner dictionary for holding dynamic values (optional). If not provided, a new dictionary will be created.

Properties

| Improve this Doc View Source

Item[String]

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;.

Declaration
public object this[string key] { get; set; }
Parameters
Type Name Description
System.String key

The key.

Property Value
Type Description
System.Object

The System.Object.

Remarks

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

Methods

| Improve this Doc View Source

GetDynamicMemberNames()

Returns the enumeration of all dynamic member names.

Declaration
public override IEnumerable<string> GetDynamicMemberNames()
Returns
Type Description
System.Collections.Generic.IEnumerable<System.String>

A sequence that contains dynamic member names.

Overrides
System.Dynamic.DynamicObject.GetDynamicMemberNames()
| Improve this Doc View Source

GetInnerObjectTypeInfo()

Gets the ITypeInfo of the inner object.

Declaration
protected virtual ITypeInfo GetInnerObjectTypeInfo()
Returns
Type Description
ITypeInfo

The ITypeInfo of the inner object.

| Improve this Doc View Source

GetThisTypeInfo()

Gets the ITypeInfo of this expando object.

Declaration
protected virtual ITypeInfo GetThisTypeInfo()
Returns
Type Description
ITypeInfo

The ITypeInfo of this expando object.

| Improve this Doc View Source

HasDynamicMember(String)

Indicates whether the memberName is defined in the expando.

Declaration
public virtual bool HasDynamicMember(string memberName)
Parameters
Type Name Description
System.String memberName

Name of the member.

Returns
Type Description
System.Boolean

True if defined, false if not.

| Improve this Doc View Source

ToDictionary(Func<String, String>, Func<Object, Object>)

Converts the expando to a dictionary having as keys the property names and as values the respective properties' values.

Declaration
public virtual IDictionary<string, object> ToDictionary(Func<string, string> keyFunc = null, Func<object, object> valueFunc = null)
Parameters
Type Name Description
System.Func<System.String, System.String> keyFunc

The key transformation function (optional).

System.Func<System.Object, System.Object> valueFunc

The value transformation function (optional).

Returns
Type Description
System.Collections.Generic.IDictionary<System.String, System.Object>

A dictionary of property values with their associated names.

| Improve this Doc View Source

TryGetMember(GetMemberBinder, out Object)

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

Declaration
public override bool TryGetMember(GetMemberBinder binder, out object result)
Parameters
Type Name Description
System.Dynamic.GetMemberBinder binder

Provides information about the object that called the dynamic operation. The binder.Name property provides the name of the member on which the dynamic operation is performed. For example, for the Console.WriteLine(sampleObject.SampleProperty) statement, where sampleObject is an instance of the class derived from the System.Dynamic.DynamicObject class, binder.Name returns "SampleProperty". The binder.IgnoreCase property specifies whether the member name is case-sensitive.

System.Object result

The result of the get operation. For example, if the method is called for a property, you can assign the property value to result.

Returns
Type Description
System.Boolean

The System.Boolean.

Overrides
System.Dynamic.DynamicObject.TryGetMember(System.Dynamic.GetMemberBinder, System.Object)
| Improve this Doc View Source

TryGetValue(String, out Object)

Attempts to get the dynamic value with the given key.

Declaration
protected virtual bool TryGetValue(string key, out object value)
Parameters
Type Name Description
System.String key

The key.

System.Object value

The value to get.

Returns
Type Description
System.Boolean

true if a value is found, false otherwise.

Remarks

First of all, it is tried to get a property value from the inner object, if one is set. The next try is to retrieve the property value from the expando object itself. Lastly, if still a property by the provided name cannot be found, the inner dictionary is searched by the provided key.

| Improve this Doc View Source

TryInvokeMember(InvokeMemberBinder, Object[], out Object)

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

Declaration
public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
Parameters
Type Name Description
System.Dynamic.InvokeMemberBinder binder

Provides information about the dynamic operation. The binder.Name property provides the name of the member on which the dynamic operation is performed. For example, for the statement sampleObject.SampleMethod(100), where sampleObject is an instance of the class derived from the System.Dynamic.DynamicObject class, binder.Name returns "SampleMethod". The binder.IgnoreCase property specifies whether the member name is case-sensitive.

System.Object[] args

The arguments that are passed to the object member during the invoke operation. For example, for the statement sampleObject.SampleMethod(100), where sampleObject is derived from the System.Dynamic.DynamicObject class, args[0] is equal to 100.

System.Object result

The result of the member invocation.

Returns
Type Description
System.Boolean

The System.Boolean.

Overrides
System.Dynamic.DynamicObject.TryInvokeMember(System.Dynamic.InvokeMemberBinder, System.Object[], System.Object)
| Improve this Doc View Source

TrySetMember(SetMemberBinder, Object)

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

Declaration
public override bool TrySetMember(SetMemberBinder binder, object value)
Parameters
Type Name Description
System.Dynamic.SetMemberBinder binder

Provides information about the object that called the dynamic operation. The binder.Name property provides the name of the member to which the value is being assigned. For example, for the statement sampleObject.SampleProperty = "Test", where sampleObject is an instance of the class derived from the System.Dynamic.DynamicObject class, binder.Name returns "SampleProperty". The binder.IgnoreCase property specifies whether the member name is case-sensitive.

System.Object value

The value to set to the member. For example, for sampleObject.SampleProperty = "Test", where sampleObject is an instance of the class derived from the System.Dynamic.DynamicObject class, the value is "Test".

Returns
Type Description
System.Boolean

The System.Boolean.

Overrides
System.Dynamic.DynamicObject.TrySetMember(System.Dynamic.SetMemberBinder, System.Object)
| Improve this Doc View Source

TrySetValue(String, Object)

Attempts to set the value with the given key.

Declaration
protected virtual bool TrySetValue(string key, object value)
Parameters
Type Name Description
System.String key

The key.

System.Object value

The value to set.

Returns
Type Description
System.Boolean

true if the value could be set, false otherwise.

Remarks

First of all, it is tried to set the property value to the inner object, if one is set. The next try is to set the property value to the expando object itself. Lastly, if still a property by the provided name cannot be found, the inner dictionary is used to set the value with the provided key.

Implements

IExpando
System.Dynamic.IDynamicMetaObjectProvider
IIndexable

Extension Methods

DynamicObjectExtensions.SetPropertyValue(Object, String, Object)
DynamicObjectExtensions.TrySetPropertyValue(Object, String, Object)
DynamicObjectExtensions.GetPropertyValue(Object, String)
DynamicObjectExtensions.TryGetPropertyValue(Object, String, out Object)
DynamicObjectExtensions.GetRuntimeTypeInfo(Object)
DynamicObjectExtensions.ToDynamic(Object)
DynamicObjectExtensions.ToExpando(Object)
BehaviorValue.ToBehaviorValue<TValue>(TValue)
CollectionExtensions.AddRange<T, TItem>(T, IEnumerable<TItem>)
ExpandoExtensions.Merge<T>(T, Object)
ExpandoExtensions.GetLaxValue<T>(IIndexable, String, T)
LoggingExtensions.GetLogger(Object, IContext)
TypeExtensions.GetAbstractType(Object)
TypeExtensions.GetAbstractTypeInfo(Object)
ReflectionHelper.GetTypeInfo(Object)
EntityEntryExtensions.TryGetAttachedEntityEntry(Object)
  • Improve this Doc
  • View Source
Back to top Generated by DocFX