C# Class IronPython.Runtime.Types.TypeInfo

Helpers for interacting w/ .NET types. This includes: Member resolution via GetMember/GetMembers. This performs a member lookup which includes the registered extension types in the PythonBinder. Internally the class has many MemberResolver's which provide the various resolution behaviors. Cached member access - this is via static classes such as Object and provides various MemberInfo's so we're not constantly looking up via reflection.
显示文件 Open project: jschementi/iron

Private Properties

Property Type Description
AllResolver MemberGroup
AreTypesCompatible bool
ContainsResolver MemberGroup
DirResolver MemberGroup
DocResolver MemberGroup
EnsureOperatorTable void
EnterResolver MemberGroup
ExitResolver MemberGroup
FallbackInequalityResolver MemberGroup
FilterFieldAndEvent MemberGroup
FilterForwardReverseMethods MemberGroup
FilterSpecialNames MemberGroup
FindCastMethod System.Reflection.MethodInfo
FormatResolver MemberGroup
GetCastNames string[]
GetEnumeratorContains void
GetEqualityMethods Microsoft.Scripting.Actions.MethodTracker[]
GetExtensionMemberGroup MemberGroup
GetInstanceOpsMethod MemberGroup
GetMemberGroup MemberGroup
GetMethodSet System.Reflection.MethodInfo[]
GetResolvedMembers IList
HashResolver MemberGroup
IncludeOperatorMethod bool
IsMethodDefaultMember bool
IsPropertyDefaultMember bool
IsPropertyWithParameters bool
IsPythonRecognizedOperator bool
IsReverseOperator bool
IterResolver MemberGroup
LengthResolver MemberGroup
MakeConversionResolver Func
MakeIndexerResolver Func
MakeListWithPreviousMembers List
MakeResolverTable MemberResolver[]
NewResolver MemberGroup
NextResolver MemberGroup
ProtectedOnly bool
ReprResolver MemberGroup
SerializationResolver MemberGroup
StringResolver MemberGroup
TypeOverridesMethod bool

Public Methods

Method Description
GetMember ( PythonBinder binder, MemberRequestKind action, Type type, string name ) : MemberGroup

Gets the statically known member from the type with the specific name. Searches only the specified type to find the member.

GetMemberAll ( PythonBinder binder, MemberRequestKind action, Type type, string name ) : MemberGroup

Gets the statically known member from the type with the specific name. Searches the entire type hierarchy to find the specified member.

GetMembers ( PythonBinder binder, MemberRequestKind action, Type type ) : IList

Gets all the statically known members from the specified type. Searches only the specified type to find the members. The result may include multiple resolution. It is the callers responsibility to only treat the 1st one by name as existing.

GetMembersAll ( PythonBinder binder, MemberRequestKind action, Type type ) : IList

Gets all the statically known members from the specified type. Searches the entire type hierarchy to get all possible members. The result may include multiple resolution. It is the callers responsibility to only treat the 1st one by name as existing.

Private Methods

Method Description
AllResolver ( MemberBinder binder, Type type ) : MemberGroup
AreTypesCompatible ( Type paramType, Type declaringType ) : bool

Checks to see if the parameter type and the declaring type are compatible to determine if an operator is forward or reverse.

ContainsResolver ( MemberBinder binder, Type type ) : MemberGroup

Provides an implementation of __contains__. We can pull contains from: ICollection of T which defines Contains directly IList which defines Contains directly IDictionary which defines Contains directly IDictionary of K,V which defines Contains directly IEnumerable of K which we have an InstaceOps helper for IEnumerable which we have an instance ops helper for IEnumerator of K which we have an InstanceOps helper for IEnumerator which we have an instance ops helper for String is ignored here because it defines __contains__ via extension methods already. The lookup is well ordered and not dependent upon the order of values returned by reflection.

DirResolver ( MemberBinder binder, Type type ) : MemberGroup
DocResolver ( MemberBinder binder, Type type ) : MemberGroup
EnsureOperatorTable ( ) : void
EnterResolver ( MemberBinder binder, Type type ) : MemberGroup
ExitResolver ( MemberBinder binder, Type type ) : MemberGroup
FallbackInequalityResolver ( MemberBinder binder, Type type ) : MemberGroup

Looks for an Equals overload defined on the type and if one is present binds __ne__ to an InstanceOps helper.

FilterFieldAndEvent ( MemberGroup members ) : MemberGroup

When private binding is enabled we can have a collision between the private Event and private field backing the event. We filter this out and favor the event. This matches the v1.0 behavior of private binding.

FilterForwardReverseMethods ( string name, MemberGroup group, Type type, PythonOperationKind oper ) : MemberGroup

If an operator is a reverisble operator (e.g. addition) then we need to filter down to just the forward/reverse versions of the .NET method. For example consider: String.op_Multiplication(int, string) String.op_Multiplication(string, int) If this method were defined on string it defines that you can do: 2 * 'abc' or: 'abc' * 2 either of which will produce 'abcabc'. The 1st form is considered the reverse form because it is declared on string but takes a non-string for the 1st argument. The 2nd is considered the forward form because it takes a string as the 1st argument. When dynamically dispatching for 2 * 'abc' we'll first try __mul__ on int, which will fail with a string argument. Then we'll try __rmul__ on a string which will succeed and dispatch to the (int, string) overload. For multiplication in this case it's not too interesting because it's commutative. For addition this might be more interesting if, for example, we had unicode and ASCII strings. In that case Unicode strings would define addition taking both unicode and ASCII strings in both forms.

FilterSpecialNames ( MemberGroup group, string name, MemberRequestKind action ) : MemberGroup
FindCastMethod ( MemberBinder binder, Type fromType, List toTypes ) : MethodInfo

Helper to get the proper typecasting method, according to the following precedence rules: 1. Strongest (most specific) declaring type 2. Strongest (most specific) parameter type 3. Type of conversion i. Implicit ii. Explicit 4. Return type (order specified in toTypes)

FormatResolver ( MemberBinder binder, Type type ) : MemberGroup
GetCastNames ( Type fromType, Type toType ) : string[]
GetEnumeratorContains ( Type type, IList intf, List &containsMembers, bool &hasObjectContains, Type ienumOfT, Type ienum, string name ) : void

Helper for IEnumerable/IEnumerator __contains__

GetEqualityMethods ( Type type, string name ) : Microsoft.Scripting.Actions.MethodTracker[]
GetExtensionMemberGroup ( Type type, MemberInfo news ) : MemberGroup
GetInstanceOpsMethod ( Type extends ) : MemberGroup

Helper to get a MemberGroup for methods declared on InstanceOps

GetMemberGroup ( MemberBinder memberBinder, MemberRequestKind action, Type type, string name ) : MemberGroup

Primary worker for getting the member(s) associated with a single name. Can be called with different MemberBinder's to alter the scope of the search.

GetMethodSet ( string name, int expected ) : System.Reflection.MethodInfo[]
GetResolvedMembers ( MemberBinder memberBinder, MemberRequestKind action, Type type ) : IList

Primary worker for returning a list of all members in a type. Can be called with different MemberBinder's to alter the scope of the search.

HashResolver ( MemberBinder binder, Type type ) : MemberGroup

Provides a resolution for __hash__, first looking for IStructuralEquatable.GetHashCode, then IValueEquality.GetValueHashCode.

IncludeOperatorMethod ( Type t, PythonOperationKind op ) : bool

Filters out methods which are present on standard .NET types but shouldn't be there in Python

IsMethodDefaultMember ( MethodTracker pt ) : bool
IsPropertyDefaultMember ( PropertyTracker pt ) : bool
IsPropertyWithParameters ( MethodTracker meth ) : bool
IsPythonRecognizedOperator ( string name ) : bool

Checks to see if this is an operator method which Python recognizes. For example op_Comma is not recognized by Python and therefore should exposed to the user as a method that is callable by name.

IsReverseOperator ( PythonOperationKind op ) : bool
IterResolver ( MemberBinder binder, Type type ) : MemberGroup

Provides a resolution for __iter__

LengthResolver ( MemberBinder binder, Type type ) : MemberGroup

Provides a resolution for __len__

MakeConversionResolver ( List castPrec ) : Func

Helper for creating a typecast resolver

MakeIndexerResolver ( bool set ) : Func

Helper for creating __getitem__/__setitem__ resolvers

MakeListWithPreviousMembers ( MemberGroup group, List mts, int i ) : List
MakeResolverTable ( ) : MemberResolver[]

Creates the resolver table which includes all the possible resolutions.

NewResolver ( MemberBinder binder, Type type ) : MemberGroup

Provides a resolution for __new__. For standard .NET types __new__ resolves to their constructor. For Python types they inherit __new__ from their base class. TODO: Can we just always fallback to object.__new__? If not why not?

NextResolver ( MemberBinder binder, Type type ) : MemberGroup

Provides a resolution for next

ProtectedOnly ( MemberInfo input ) : bool

Filters down to include only protected methods

ReprResolver ( MemberBinder binder, Type type ) : MemberGroup

Provides a resolution for __repr__

SerializationResolver ( MemberBinder binder, Type type ) : MemberGroup
StringResolver ( MemberBinder binder, Type type ) : MemberGroup

Provides a resolution for __str__.

TypeOverridesMethod ( MemberBinder binder, Type type, string methodName ) : bool

Helper to see if the type explicitly overrides the method. This ignores members defined on object.

Method Details

GetMember() public static method

Gets the statically known member from the type with the specific name. Searches only the specified type to find the member.
public static GetMember ( PythonBinder binder, MemberRequestKind action, Type type, string name ) : MemberGroup
binder IronPython.Runtime.Binding.PythonBinder
action MemberRequestKind
type System.Type
name string
return MemberGroup

GetMemberAll() public static method

Gets the statically known member from the type with the specific name. Searches the entire type hierarchy to find the specified member.
public static GetMemberAll ( PythonBinder binder, MemberRequestKind action, Type type, string name ) : MemberGroup
binder IronPython.Runtime.Binding.PythonBinder
action MemberRequestKind
type System.Type
name string
return MemberGroup

GetMembers() public static method

Gets all the statically known members from the specified type. Searches only the specified type to find the members. The result may include multiple resolution. It is the callers responsibility to only treat the 1st one by name as existing.
public static GetMembers ( PythonBinder binder, MemberRequestKind action, Type type ) : IList
binder IronPython.Runtime.Binding.PythonBinder
action MemberRequestKind
type System.Type
return IList

GetMembersAll() public static method

Gets all the statically known members from the specified type. Searches the entire type hierarchy to get all possible members. The result may include multiple resolution. It is the callers responsibility to only treat the 1st one by name as existing.
public static GetMembersAll ( PythonBinder binder, MemberRequestKind action, Type type ) : IList
binder IronPython.Runtime.Binding.PythonBinder
action MemberRequestKind
type System.Type
return IList