Show / Hide Table of Contents

Class DispatchingUserDataDescriptor

An abstract user data descriptor which accepts members described by IMemberDescriptor objects and correctly dispatches to them. Metamethods are also by default dispatched to operator overloads and other similar methods - see MetaIndex(Script, Object, String) .

Inheritance
System.Object
DispatchingUserDataDescriptor
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: System.Dynamic.ExpandoObject
Assembly: cs.temp.dll.dll
Syntax
public abstract class DispatchingUserDataDescriptor : IUserDataDescriptor, IOptimizableDescriptor

Constructors

DispatchingUserDataDescriptor(Type, String)

Initializes a new instance of the StandardUserDataDescriptor class.

Declaration
protected DispatchingUserDataDescriptor(Type type, string friendlyName = null)
Parameters
Type type

The type this descriptor refers to.

System.String friendlyName

A friendly name for the type, or null.

Fields

SPECIALNAME_CAST_EXPLICIT

The special name used by CLR for explicit cast conversions

Declaration
protected const string SPECIALNAME_CAST_EXPLICIT = "op_Explicit"
Field Value
System.String

SPECIALNAME_CAST_IMPLICIT

The special name used by CLR for implicit cast conversions

Declaration
protected const string SPECIALNAME_CAST_IMPLICIT = "op_Implicit"
Field Value
System.String

SPECIALNAME_INDEXER_GET

The special name used by CLR for indexer getters

Declaration
protected const string SPECIALNAME_INDEXER_GET = "get_Item"
Field Value
System.String

SPECIALNAME_INDEXER_SET

The special name used by CLR for indexer setters

Declaration
protected const string SPECIALNAME_INDEXER_SET = "set_Item"
Field Value
System.String

Properties

FriendlyName

Gets a human readable friendly name of the descriptor

Declaration
public string FriendlyName { get; }
Property Value
System.String

MemberNames

Gets the member names.

Declaration
public IEnumerable<string> MemberNames { get; }
Property Value
IEnumerable<System.String>

Members

Gets the members.

Declaration
public IEnumerable<KeyValuePair<string, IMemberDescriptor>> Members { get; }
Property Value
IEnumerable<KeyValuePair<System.String, IMemberDescriptor>>

MetaMemberNames

Gets the meta member names.

Declaration
public IEnumerable<string> MetaMemberNames { get; }
Property Value
IEnumerable<System.String>

MetaMembers

Gets the meta members.

Declaration
public IEnumerable<KeyValuePair<string, IMemberDescriptor>> MetaMembers { get; }
Property Value
IEnumerable<KeyValuePair<System.String, IMemberDescriptor>>

Name

Gets the name of the descriptor (usually, the name of the type described).

Declaration
public string Name { get; }
Property Value
System.String

Implements
IUserDataDescriptor.Name

Type

Gets the type this descriptor refers to

Declaration
public Type Type { get; }
Property Value
Type

Implements
IUserDataDescriptor.Type

Methods

AddDynValue(String, DynValue)

Adds a DynValue as a member

Declaration
public void AddDynValue(string name, DynValue value)
Parameters
System.String name

The name.

DynValue value

The value.

AddMember(String, IMemberDescriptor)

Adds a property to the member list

Declaration
public void AddMember(string name, IMemberDescriptor desc)
Parameters
System.String name

The name.

IMemberDescriptor desc

The descriptor.

Exceptions
System.ArgumentException

Thrown if a name conflict is detected and one of the conflicting members does not support overloads.

AddMetaMember(String, IMemberDescriptor)

Adds a member to the meta-members list.

Declaration
public void AddMetaMember(string name, IMemberDescriptor desc)
Parameters
System.String name

The name of the metamethod.

IMemberDescriptor desc

The desc.

Exceptions
System.ArgumentException

Thrown if a name conflict is detected and one of the conflicting members does not support overloads.

AsString(Object)

Converts this userdata to string

Declaration
public virtual string AsString(object obj)
Parameters
System.Object obj

The object.

Returns
System.String

Implements
IUserDataDescriptor.AsString(Object)

Camelify(String)

Converts the specified name from underscore_case to camelCase. Just a wrapper over the DescriptorHelpers method with the same name,

Declaration
protected static string Camelify(string name)
Parameters
System.String name

The name.

Returns
System.String

ExecuteIndexer(IMemberDescriptor, Script, Object, DynValue, DynValue)

Executes the specified indexer method.

Declaration
protected virtual DynValue ExecuteIndexer(IMemberDescriptor mdesc, Script script, object obj, DynValue index, DynValue value)
Parameters
IMemberDescriptor mdesc

The method descriptor

Script script

The script.

System.Object obj

The object.

DynValue index

The indexer parameter

DynValue value

The dynvalue to set on a setter, or null.

Returns
DynValue

Exceptions
System.NotImplementedException

FindMember(String)

Finds the member with a given name. If not found, null is returned.

Declaration
public IMemberDescriptor FindMember(string memberName)
Parameters
System.String memberName

Name of the member.

Returns
IMemberDescriptor

FindMetaMember(String)

Finds the meta member with a given name. If not found, null is returned.

Declaration
public IMemberDescriptor FindMetaMember(string memberName)
Parameters
System.String memberName

Name of the member.

Returns
IMemberDescriptor

HasMember(String)

Determines whether the descriptor contains the specified member (by exact name)

Declaration
public bool HasMember(string exactName)
Parameters
System.String exactName

Name of the member.

Returns
System.Boolean

HasMetaMember(String)

Determines whether the descriptor contains the specified member in the meta list (by exact name)

Declaration
public bool HasMetaMember(string exactName)
Parameters
System.String exactName

Name of the meta-member.

Returns
System.Boolean

Index(Script, Object, DynValue, Boolean)

Performs an "index" "get" operation. This tries to resolve minor variations of member names.

Declaration
public virtual DynValue Index(Script script, object obj, DynValue index, bool isDirectIndexing)
Parameters
Script script

The script originating the request

System.Object obj

The object (null if a static request is done)

DynValue index

The index.

System.Boolean isDirectIndexing

If set to true, it's indexed with a name, if false it's indexed through brackets.

Returns
DynValue

Implements
IUserDataDescriptor.Index(Script, Object, DynValue, Boolean)

IsTypeCompatible(Type, Object)

Determines whether the specified object is compatible with the specified type. Unless a very specific behaviour is needed, the correct implementation is a simple " return type.IsInstanceOfType(obj); "

Declaration
public virtual bool IsTypeCompatible(Type type, object obj)
Parameters
Type type

The type.

System.Object obj

The object.

Returns
System.Boolean

Implements
IUserDataDescriptor.IsTypeCompatible(Type, Object)

MetaIndex(Script, Object, String)

Gets a "meta" operation on this userdata. If a descriptor does not support this functionality, it should return "null" (not a nil). See MetaIndex(Script, Object, String) for further details.

If a method exists marked with MoonSharpUserDataMetamethodAttribute for the specific metamethod requested, that method is returned.

If the above fails, the following dispatching occur:

__add, __sub, __mul, __div, __mod and __unm are dispatched to C# operator overloads (if they exist) __eq is dispatched to System.Object.Equals. __lt and __le are dispatched IComparable.Compare, if the type implements IComparable or IComparable{object} __len is dispatched to Length and Count properties, if those exist. __iterator is handled if the object implements IEnumerable or IEnumerator. __tonumber is dispatched to implicit or explicit conversion operators to standard numeric types. __tobool is dispatched to an implicit or explicit conversion operator to bool. If that fails, operator true is used.

The script originating the request The object (null if a static request is done) The name of the metamember.
Declaration
public virtual DynValue MetaIndex(Script script, object obj, string metaname)
Parameters
Script script

System.Object obj

System.String metaname

Returns
DynValue

Implements
IUserDataDescriptor.MetaIndex(Script, Object, String)

RemoveMember(String)

Removes the member with a given name. In case of overloaded functions, all overloads are removed.

Declaration
public void RemoveMember(string memberName)
Parameters
System.String memberName

Name of the member.

RemoveMetaMember(String)

Removes the meta member with a given name. In case of overloaded functions, all overloads are removed.

Declaration
public void RemoveMetaMember(string memberName)
Parameters
System.String memberName

Name of the member.

SetIndex(Script, Object, DynValue, DynValue, Boolean)

Performs an "index" "set" operation. This tries to resolve minor variations of member names.

Declaration
public virtual bool SetIndex(Script script, object obj, DynValue index, DynValue value, bool isDirectIndexing)
Parameters
Script script

The script originating the request

System.Object obj

The object (null if a static request is done)

DynValue index

The index.

DynValue value

The value to be set

System.Boolean isDirectIndexing

If set to true, it's indexed with a name, if false it's indexed through brackets.

Returns
System.Boolean

Implements
IUserDataDescriptor.SetIndex(Script, Object, DynValue, DynValue, Boolean)

TryIndex(Script, Object, String)

Tries to perform an indexing operation by checking methods and properties for the given indexName

Declaration
protected virtual DynValue TryIndex(Script script, object obj, string indexName)
Parameters
Script script

The script.

System.Object obj

The object.

System.String indexName

Member name to be indexed.

Returns
DynValue

TrySetIndex(Script, Object, String, DynValue)

Tries to perform an indexing "set" operation by checking methods and properties for the given indexName

Declaration
protected virtual bool TrySetIndex(Script script, object obj, string indexName, DynValue value)
Parameters
Script script

The script.

System.Object obj

The object.

System.String indexName

Member name to be indexed.

DynValue value

The value.

Returns
System.Boolean

UpperFirstLetter(String)

Converts the specified name to one with an uppercase first letter (something to Something). Just a wrapper over the DescriptorHelpers method with the same name,

Declaration
protected static string UpperFirstLetter(string name)
Parameters
System.String name

The name.

Returns
System.String

Explicit Interface Implementations

IOptimizableDescriptor.Optimize()

Declaration
void IOptimizableDescriptor.Optimize()
Implements
IOptimizableDescriptor.Optimize()
Back to top Built by Itinero, MIT licensed.