internal static RuntimeMethodInfo AssignAssociates(int tkMethod, RuntimeTypeHandle declaredTypeHandle, RuntimeTypeHandle reflectedTypeHandle) { if (MetadataToken.IsNullToken(tkMethod)) { return(null); } bool flag = !declaredTypeHandle.Equals(reflectedTypeHandle); RuntimeMethodHandle methodHandle = declaredTypeHandle.GetModuleHandle().ResolveMethodHandle(tkMethod, declaredTypeHandle.GetInstantiation(), new RuntimeTypeHandle[0]); MethodAttributes attributes = methodHandle.GetAttributes(); bool flag2 = (attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Private; bool flag3 = (attributes & MethodAttributes.Virtual) != MethodAttributes.PrivateScope; if (flag) { if (flag2) { return(null); } if (flag3 && ((declaredTypeHandle.GetAttributes() & TypeAttributes.ClassSemanticsMask) == TypeAttributes.AnsiClass)) { int slot = methodHandle.GetSlot(); methodHandle = reflectedTypeHandle.GetMethodAt(slot); } } MethodAttributes attributes2 = attributes & MethodAttributes.MemberAccessMask; RuntimeMethodInfo methodBase = RuntimeType.GetMethodBase(reflectedTypeHandle, methodHandle) as RuntimeMethodInfo; if (methodBase == null) { methodBase = reflectedTypeHandle.GetRuntimeType().Module.ResolveMethod(tkMethod, null, null) as RuntimeMethodInfo; } return(methodBase); }
public override MethodInfo GetBaseDefinition() { if (!IsVirtual || IsStatic || m_declaringType == null || m_declaringType.IsInterface) { return(this); } int slot = RuntimeMethodHandle.GetSlot(this); RuntimeType declaringType = (RuntimeType)DeclaringType; RuntimeType baseDeclaringType = declaringType; RuntimeMethodHandleInternal baseMethodHandle = new RuntimeMethodHandleInternal(); do { int cVtblSlots = RuntimeTypeHandle.GetNumVirtuals(declaringType); if (cVtblSlots <= slot) { break; } baseMethodHandle = RuntimeTypeHandle.GetMethodAt(declaringType, slot); baseDeclaringType = declaringType; declaringType = (RuntimeType)declaringType.BaseType; } while (declaringType != null); return((MethodInfo)RuntimeType.GetMethodBase(baseDeclaringType, baseMethodHandle)); }
private static RuntimeMethodInfo AssignAssociates(int tkMethod, RuntimeType declaredType, RuntimeType reflectedType) { if (MetadataToken.IsNullToken(tkMethod)) { return(null); } bool flag = declaredType != reflectedType; IntPtr[] array = null; int typeInstCount = 0; RuntimeType[] instantiationInternal = declaredType.GetTypeHandleInternal().GetInstantiationInternal(); if (instantiationInternal != null) { typeInstCount = instantiationInternal.Length; array = new IntPtr[instantiationInternal.Length]; for (int i = 0; i < instantiationInternal.Length; i++) { array[i] = instantiationInternal[i].GetTypeHandleInternal().Value; } } RuntimeMethodHandleInternal runtimeMethodHandleInternal = ModuleHandle.ResolveMethodHandleInternalCore(RuntimeTypeHandle.GetModule(declaredType), tkMethod, array, typeInstCount, null, 0); if (flag) { MethodAttributes attributes = RuntimeMethodHandle.GetAttributes(runtimeMethodHandleInternal); if (!CompatibilitySwitches.IsAppEarlierThanWindowsPhone8 && (attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Private) { return(null); } if ((attributes & MethodAttributes.Virtual) != MethodAttributes.PrivateScope) { bool flag2 = (RuntimeTypeHandle.GetAttributes(declaredType) & TypeAttributes.ClassSemanticsMask) == TypeAttributes.NotPublic; if (flag2) { int slot = RuntimeMethodHandle.GetSlot(runtimeMethodHandleInternal); runtimeMethodHandleInternal = RuntimeTypeHandle.GetMethodAt(reflectedType, slot); } } } RuntimeMethodInfo runtimeMethodInfo = RuntimeType.GetMethodBase(reflectedType, runtimeMethodHandleInternal) as RuntimeMethodInfo; if (runtimeMethodInfo == null) { runtimeMethodInfo = (reflectedType.Module.ResolveMethod(tkMethod, null, null) as RuntimeMethodInfo); } return(runtimeMethodInfo); }
[System.Security.SecuritySafeCritical] // auto-generated internal RuntimeMethodInfo GetParentDefinition() { if (!IsVirtual || m_declaringType.IsInterface) return null; RuntimeType parent = (RuntimeType)m_declaringType.BaseType; if (parent == null) return null; int slot = RuntimeMethodHandle.GetSlot(this); if (RuntimeTypeHandle.GetNumVirtuals(parent) <= slot) return null; return (RuntimeMethodInfo)RuntimeType.GetMethodBase(parent, RuntimeTypeHandle.GetMethodAt(parent, slot)); }
private static RuntimeMethodInfo AssignAssociates(int tkMethod, RuntimeType declaredType, RuntimeType reflectedType) { if (MetadataToken.IsNullToken(tkMethod)) { return(null); } bool flag = declaredType != reflectedType; IntPtr[] typeInstantiationContext = null; int typeInstCount = 0; RuntimeType[] instantiationInternal = declaredType.GetTypeHandleInternal().GetInstantiationInternal(); if (instantiationInternal != null) { typeInstCount = instantiationInternal.Length; typeInstantiationContext = new IntPtr[instantiationInternal.Length]; for (int i = 0; i < instantiationInternal.Length; i++) { typeInstantiationContext[i] = instantiationInternal[i].GetTypeHandleInternal().Value; } } RuntimeMethodHandleInternal method = ModuleHandle.ResolveMethodHandleInternalCore(RuntimeTypeHandle.GetModule(declaredType), tkMethod, typeInstantiationContext, typeInstCount, null, 0); if (flag) { MethodAttributes attributes = RuntimeMethodHandle.GetAttributes(method); if ((attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Private) { return(null); } if (((attributes & MethodAttributes.Virtual) != MethodAttributes.PrivateScope) && ((RuntimeTypeHandle.GetAttributes(declaredType) & TypeAttributes.ClassSemanticsMask) == TypeAttributes.AnsiClass)) { int slot = RuntimeMethodHandle.GetSlot(method); method = RuntimeTypeHandle.GetMethodAt(reflectedType, slot); } } RuntimeMethodInfo methodBase = RuntimeType.GetMethodBase(reflectedType, method) as RuntimeMethodInfo; if (methodBase == null) { methodBase = reflectedType.Module.ResolveMethod(tkMethod, null, null) as RuntimeMethodInfo; } return(methodBase); }
private static RuntimeMethodInfo AssignAssociates(int tkMethod, RuntimeType declaredType, RuntimeType reflectedType) { if (MetadataToken.IsNullToken(tkMethod)) { return((RuntimeMethodInfo)null); } bool flag = declaredType != reflectedType; IntPtr[] typeInstantiationContext = (IntPtr[])null; int typeInstCount = 0; RuntimeType[] instantiationInternal = declaredType.GetTypeHandleInternal().GetInstantiationInternal(); if (instantiationInternal != null) { typeInstCount = instantiationInternal.Length; typeInstantiationContext = new IntPtr[instantiationInternal.Length]; for (int index = 0; index < instantiationInternal.Length; ++index) { typeInstantiationContext[index] = instantiationInternal[index].GetTypeHandleInternal().Value; } } RuntimeMethodHandleInternal methodHandleInternal = ModuleHandle.ResolveMethodHandleInternalCore(RuntimeTypeHandle.GetModule(declaredType), tkMethod, typeInstantiationContext, typeInstCount, (IntPtr[])null, 0); if (flag) { MethodAttributes attributes = RuntimeMethodHandle.GetAttributes(methodHandleInternal); if (!CompatibilitySwitches.IsAppEarlierThanWindowsPhone8 && (attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Private) { return((RuntimeMethodInfo)null); } if ((attributes & MethodAttributes.Virtual) != MethodAttributes.PrivateScope && (RuntimeTypeHandle.GetAttributes(declaredType) & TypeAttributes.ClassSemanticsMask) == TypeAttributes.NotPublic) { int slot = RuntimeMethodHandle.GetSlot(methodHandleInternal); methodHandleInternal = RuntimeTypeHandle.GetMethodAt(reflectedType, slot); } } RuntimeMethodInfo runtimeMethodInfo = RuntimeType.GetMethodBase(reflectedType, methodHandleInternal) as RuntimeMethodInfo; if ((MethodInfo)runtimeMethodInfo == (MethodInfo)null) { runtimeMethodInfo = reflectedType.Module.ResolveMethod(tkMethod, (Type[])null, (Type[])null) as RuntimeMethodInfo; } return(runtimeMethodInfo); }
internal RuntimeMethodInfo GetParentDefinition() { if (!base.IsVirtual || this.m_declaringType.IsInterface) { return(null); } RuntimeType baseType = (RuntimeType)this.m_declaringType.BaseType; if (baseType == null) { return(null); } int slot = RuntimeMethodHandle.GetSlot(this); if (RuntimeTypeHandle.GetNumVirtuals(baseType) <= slot) { return(null); } return((RuntimeMethodInfo)RuntimeType.GetMethodBase(baseType, RuntimeTypeHandle.GetMethodAt(baseType, slot))); }
internal RuntimeMethodInfo?GetParentDefinition() { if (!IsVirtual || m_declaringType.IsInterface) { return(null); } RuntimeType?parent = (RuntimeType?)m_declaringType.BaseType; if (parent == null) { return(null); } int slot = RuntimeMethodHandle.GetSlot(this); if (RuntimeTypeHandle.GetNumVirtuals(parent) <= slot) { return(null); } return((RuntimeMethodInfo?)RuntimeType.GetMethodBase(parent, RuntimeTypeHandle.GetMethodAt(parent, slot))); }
public override MethodInfo GetBaseDefinition() { if ((!base.IsVirtual || base.IsStatic) || ((this.m_declaringType == null) || this.m_declaringType.IsInterface)) { return(this); } int slot = RuntimeMethodHandle.GetSlot(this); RuntimeType declaringType = (RuntimeType)this.DeclaringType; RuntimeType reflectedType = declaringType; RuntimeMethodHandleInternal methodHandle = new RuntimeMethodHandleInternal(); do { if (RuntimeTypeHandle.GetNumVirtuals(declaringType) <= slot) { break; } methodHandle = RuntimeTypeHandle.GetMethodAt(declaringType, slot); reflectedType = declaringType; declaringType = (RuntimeType)declaringType.BaseType; }while (declaringType != null); return((MethodInfo)RuntimeType.GetMethodBase(reflectedType, methodHandle)); }
public override MethodInfo GetBaseDefinition() { if (!this.IsVirtual || this.IsStatic || (this.m_declaringType == (RuntimeType)null || this.m_declaringType.IsInterface)) { return((MethodInfo)this); } int slot = RuntimeMethodHandle.GetSlot((IRuntimeMethodInfo)this); RuntimeType type = (RuntimeType)this.DeclaringType; RuntimeType reflectedType = type; RuntimeMethodHandleInternal methodHandle = new RuntimeMethodHandleInternal(); while (RuntimeTypeHandle.GetNumVirtuals(type) > slot) { methodHandle = RuntimeTypeHandle.GetMethodAt(type, slot); reflectedType = type; type = (RuntimeType)type.BaseType; if (!(type != (RuntimeType)null)) { break; } } return((MethodInfo)RuntimeType.GetMethodBase(reflectedType, methodHandle)); }
public override MethodInfo GetBaseDefinition() { if (!base.IsVirtual || base.IsStatic || this.m_declaringType == null || this.m_declaringType.IsInterface) { return(this); } int slot = RuntimeMethodHandle.GetSlot(this); RuntimeType runtimeType = (RuntimeType)this.DeclaringType; RuntimeType reflectedType = runtimeType; RuntimeMethodHandleInternal methodHandle = default(RuntimeMethodHandleInternal); do { int numVirtuals = RuntimeTypeHandle.GetNumVirtuals(runtimeType); if (numVirtuals <= slot) { break; } methodHandle = RuntimeTypeHandle.GetMethodAt(runtimeType, slot); reflectedType = runtimeType; runtimeType = (RuntimeType)runtimeType.BaseType; }while (runtimeType != null); return((MethodInfo)RuntimeType.GetMethodBase(reflectedType, methodHandle)); }
public override MethodInfo GetBaseDefinition() { if ((!base.IsVirtual || base.IsStatic) || ((this.m_declaringType == null) || this.m_declaringType.IsInterface)) { return(this); } int slot = this.m_handle.GetSlot(); Type declaringType = this.DeclaringType; Type type2 = this.DeclaringType; RuntimeMethodHandle methodHandle = new RuntimeMethodHandle(); do { RuntimeTypeHandle typeHandleInternal = declaringType.GetTypeHandleInternal(); if (typeHandleInternal.GetNumVirtuals() <= slot) { break; } methodHandle = typeHandleInternal.GetMethodAt(slot); type2 = declaringType; declaringType = declaringType.BaseType; }while (declaringType != null); return((MethodInfo)RuntimeType.GetMethodBase(type2.GetTypeHandleInternal(), methodHandle)); }
private static RuntimeMethodInfo?AssignAssociates( int tkMethod, RuntimeType declaredType, RuntimeType reflectedType) { if (MetadataToken.IsNullToken(tkMethod)) { return(null); } Debug.Assert(declaredType != null); Debug.Assert(reflectedType != null); bool isInherited = declaredType != reflectedType; Span <IntPtr> genericArgumentHandles = stackalloc IntPtr[0]; RuntimeType[] genericArguments = declaredType.TypeHandle.GetInstantiationInternal(); if (genericArguments != null) { genericArgumentHandles = genericArguments.Length <= 16 ? // arbitrary stackalloc limit stackalloc IntPtr[genericArguments.Length] : new IntPtr[genericArguments.Length]; for (int i = 0; i < genericArguments.Length; i++) { genericArgumentHandles[i] = genericArguments[i].TypeHandle.Value; } } RuntimeMethodHandleInternal associateMethodHandle = ModuleHandle.ResolveMethodHandleInternal(RuntimeTypeHandle.GetModule(declaredType), tkMethod, genericArgumentHandles, default); Debug.Assert(!associateMethodHandle.IsNullHandle(), "Failed to resolve associateRecord methodDef token"); if (isInherited) { MethodAttributes methAttr = RuntimeMethodHandle.GetAttributes(associateMethodHandle); // ECMA MethodSemantics: "All methods for a given Property or Event shall have the same accessibility // (ie the MemberAccessMask subfield of their Flags row) and cannot be CompilerControlled [CLS]" // Consequently, a property may be composed of public and private methods. If the declared type != // the reflected type, the private methods should not be exposed. Note that this implies that the // identity of a property includes it's reflected type. if ((methAttr & MethodAttributes.MemberAccessMask) == MethodAttributes.Private) { return(null); } // Note this is the first time the property was encountered walking from the most derived class // towards the base class. It would seem to follow that any associated methods would not // be overriden -- but this is not necessarily true. A more derived class may have overriden a // virtual method associated with a property in a base class without associating the override with // the same or any property in the derived class. if ((methAttr & MethodAttributes.Virtual) != 0) { bool declaringTypeIsClass = (RuntimeTypeHandle.GetAttributes(declaredType) & TypeAttributes.ClassSemanticsMask) == TypeAttributes.Class; // It makes no sense to search for a virtual override of a method declared on an interface. if (declaringTypeIsClass) { int slot = RuntimeMethodHandle.GetSlot(associateMethodHandle); // Find the override visible from the reflected type associateMethodHandle = RuntimeTypeHandle.GetMethodAt(reflectedType, slot); } } } RuntimeMethodInfo?associateMethod = RuntimeType.GetMethodBase(reflectedType, associateMethodHandle) as RuntimeMethodInfo; // suppose a property was mapped to a method not in the derivation hierarchy of the reflectedTypeHandle return(associateMethod ?? reflectedType.Module.ResolveMethod(tkMethod, null, null) as RuntimeMethodInfo); }
[System.Security.SecurityCritical] // auto-generated private static unsafe RuntimeMethodInfo AssignAssociates( int tkMethod, RuntimeType declaredType, RuntimeType reflectedType) { if (MetadataToken.IsNullToken(tkMethod)) { return(null); } Contract.Assert(declaredType != null); Contract.Assert(reflectedType != null); bool isInherited = declaredType != reflectedType; IntPtr[] genericArgumentHandles = null; int genericArgumentCount = 0; RuntimeType [] genericArguments = declaredType.GetTypeHandleInternal().GetInstantiationInternal(); if (genericArguments != null) { genericArgumentCount = genericArguments.Length; genericArgumentHandles = new IntPtr[genericArguments.Length]; for (int i = 0; i < genericArguments.Length; i++) { genericArgumentHandles[i] = genericArguments[i].GetTypeHandleInternal().Value; } } RuntimeMethodHandleInternal associateMethodHandle = ModuleHandle.ResolveMethodHandleInternalCore(RuntimeTypeHandle.GetModule(declaredType), tkMethod, genericArgumentHandles, genericArgumentCount, null, 0); Contract.Assert(!associateMethodHandle.IsNullHandle(), "Failed to resolve associateRecord methodDef token"); if (isInherited) { MethodAttributes methAttr = RuntimeMethodHandle.GetAttributes(associateMethodHandle); // ECMA MethodSemantics: "All methods for a given Property or Event shall have the same accessibility //(ie the MemberAccessMask subfield of their Flags row) and cannot be CompilerControlled [CLS]" // Consequently, a property may be composed of public and private methods. If the declared type != // the reflected type, the private methods should not be exposed. Note that this implies that the // identity of a property includes it's reflected type. // NetCF actually includes private methods from parent classes in Reflection results // We will mimic that in Mango Compat mode. if (!CompatibilitySwitches.IsAppEarlierThanWindowsPhone8) { if ((methAttr & MethodAttributes.MemberAccessMask) == MethodAttributes.Private) { return(null); } } // Note this is the first time the property was encountered walking from the most derived class // towards the base class. It would seem to follow that any associated methods would not // be overriden -- but this is not necessarily true. A more derived class may have overriden a // virtual method associated with a property in a base class without associating the override with // the same or any property in the derived class. if ((methAttr & MethodAttributes.Virtual) != 0) { bool declaringTypeIsClass = (RuntimeTypeHandle.GetAttributes(declaredType) & TypeAttributes.ClassSemanticsMask) == TypeAttributes.Class; // It makes no sense to search for a virtual override of a method declared on an interface. if (declaringTypeIsClass) { int slot = RuntimeMethodHandle.GetSlot(associateMethodHandle); // Find the override visible from the reflected type associateMethodHandle = RuntimeTypeHandle.GetMethodAt(reflectedType, slot); } } } RuntimeMethodInfo associateMethod = RuntimeType.GetMethodBase(reflectedType, associateMethodHandle) as RuntimeMethodInfo; // suppose a property was mapped to a method not in the derivation hierarchy of the reflectedTypeHandle if (associateMethod == null) { associateMethod = reflectedType.Module.ResolveMethod(tkMethod, null, null) as RuntimeMethodInfo; } return(associateMethod); }