GetRuntimeType() private method

private GetRuntimeType ( ) : RuntimeType
return RuntimeType
コード例 #1
0
ファイル: Delegate.cs プロジェクト: randomize/VimConfig
 protected virtual MethodInfo GetMethodImpl()
 {
     if (this._methodBase == null)
     {
         RuntimeMethodHandle methodHandle  = this.FindMethodHandle();
         RuntimeTypeHandle   declaringType = methodHandle.GetDeclaringType();
         if ((declaringType.IsGenericTypeDefinition() || declaringType.HasInstantiation()) && ((methodHandle.GetAttributes() & MethodAttributes.Static) == MethodAttributes.PrivateScope))
         {
             if (!(this._methodPtrAux == IntPtr.Zero))
             {
                 declaringType = base.GetType().GetMethod("Invoke").GetParameters()[0].ParameterType.TypeHandle;
             }
             else
             {
                 Type baseType = this._target.GetType();
                 Type genericTypeDefinition = declaringType.GetRuntimeType().GetGenericTypeDefinition();
                 while (true)
                 {
                     if (baseType.IsGenericType && (baseType.GetGenericTypeDefinition() == genericTypeDefinition))
                     {
                         break;
                     }
                     baseType = baseType.BaseType;
                 }
                 declaringType = baseType.TypeHandle;
             }
         }
         this._methodBase = (MethodInfo)RuntimeType.GetMethodBase(declaringType, methodHandle);
     }
     return((MethodInfo)this._methodBase);
 }
コード例 #2
0
        public TypedReference GetNextArg(RuntimeTypeHandle rth)
        {
            if (sigPtr != IntPtr.Zero)
            {
                // This is an ordinary ArgIterator capable of determining
                // types from a signature. Just do a regular GetNextArg.
                return(GetNextArg());
            }
            else
            {
                // Prevent abuse of this API with a default ArgIterator (it
                // doesn't require permission to create a zero-inited value
                // type). Check that ArgPtr isn't zero or this API will allow a
                // malicious caller to increment the pointer to an arbitrary
                // location in memory and read the contents.
                if (ArgPtr == IntPtr.Zero)
                {
                    throw new ArgumentNullException();
                }

                TypedReference result = new TypedReference();
                // reference to TypedReference is banned, so have to pass result as pointer
                unsafe
                {
                    InternalGetNextArg(&result, rth.GetRuntimeType());
                }
                return(result);
            }
        }
コード例 #3
0
ファイル: Associates.cs プロジェクト: randomize/VimConfig
 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;
 }
コード例 #4
0
ファイル: FieldInfo.cs プロジェクト: nietras/coreclr
        public static FieldInfo GetFieldFromHandle(RuntimeFieldHandle handle, RuntimeTypeHandle declaringType)
        {
            if (handle.IsNullHandle())
                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidHandle"));

            return RuntimeType.GetFieldInfo(declaringType.GetRuntimeType(), handle.GetRuntimeFieldInfo());
        }           
コード例 #5
0
ファイル: ArgIterator.cs プロジェクト: kouvel/coreclr
        public TypedReference GetNextArg(RuntimeTypeHandle rth)
        {
            if (sigPtr != IntPtr.Zero)
            {
                // This is an ordinary ArgIterator capable of determining
                // types from a signature. Just do a regular GetNextArg.
                return GetNextArg();
            }
            else
            {
                // Prevent abuse of this API with a default ArgIterator (it
                // doesn't require permission to create a zero-inited value
                // type). Check that ArgPtr isn't zero or this API will allow a
                // malicious caller to increment the pointer to an arbitrary
                // location in memory and read the contents.
                if (ArgPtr == IntPtr.Zero)
                    throw new ArgumentNullException();

                TypedReference result = new TypedReference ();
                // reference to TypedReference is banned, so have to pass result as pointer
                unsafe
                {
                    InternalGetNextArg(&result, rth.GetRuntimeType());
                }
                return result;
            }
        }
コード例 #6
0
 internal RuntimeConstructorInfo(RuntimeMethodHandle handle, RuntimeTypeHandle declaringTypeHandle, RuntimeType.RuntimeTypeCache reflectedTypeCache, MethodAttributes methodAttributes, System.Reflection.BindingFlags bindingFlags)
 {
     this.m_bindingFlags = bindingFlags;
     this.m_handle = handle;
     this.m_reflectedTypeCache = reflectedTypeCache;
     this.m_declaringType = declaringTypeHandle.GetRuntimeType();
     this.m_parameters = null;
     this.m_toString = null;
     this.m_methodAttributes = methodAttributes;
 }
コード例 #7
0
        internal static unsafe Type GetTypeByNameUsingCARules(string name, Module scope)
        {
            if ((name == null) || (name.Length == 0))
            {
                throw new ArgumentException();
            }
            RuntimeTypeHandle handle2 = new RuntimeTypeHandle(_GetTypeByNameUsingCARules(name, (IntPtr)scope.GetModuleHandle().Value));

            return(handle2.GetRuntimeType());
        }
コード例 #8
0
		public unsafe TypedReference GetNextArg(RuntimeTypeHandle rth)
		{
			if (this.sigPtr != IntPtr.Zero)
			{
				return this.GetNextArg();
			}
			if (this.ArgPtr == IntPtr.Zero)
			{
				throw new ArgumentNullException();
			}
			TypedReference result = default(TypedReference);
			this.InternalGetNextArg((void*)(&result), rth.GetRuntimeType());
			return result;
		}
コード例 #9
0
ファイル: argiterator.cs プロジェクト: wwkkww1983/ZJCredit
        public unsafe TypedReference GetNextArg(RuntimeTypeHandle rth)
        {
            if (this.sigPtr != IntPtr.Zero)
            {
                return(this.GetNextArg());
            }
            if (this.ArgPtr == IntPtr.Zero)
            {
                throw new ArgumentNullException();
            }
            TypedReference typedReference = new TypedReference();

            this.InternalGetNextArg((void *)&typedReference, rth.GetRuntimeType());
            return(typedReference);
        }
コード例 #10
0
        internal unsafe static IntPtr GetTypeHelper(IntPtr th, IntPtr pGenericArgs, int cGenericArgs, IntPtr pModifiers, int cModifiers)
        {
            RuntimeTypeHandle typeHandle = new RuntimeTypeHandle(th.ToPointer());
            Type type = typeHandle.GetRuntimeType();
            if (type == null)
                return th;

            if (cGenericArgs > 0)
            {
                Type[] genericArgs = new Type[cGenericArgs];
                void** arGenericArgs = (void**)pGenericArgs.ToPointer();
                for (int i = 0; i < genericArgs.Length; i++)
                {
                    RuntimeTypeHandle genericArg = new RuntimeTypeHandle((void*)Marshal.ReadIntPtr((IntPtr)arGenericArgs, i * sizeof(void*)));
                    genericArgs[i] = Type.GetTypeFromHandle(genericArg);
                    
                    if (genericArgs[i] == null)
                        return (IntPtr)0;
                }

                type = type.MakeGenericType(genericArgs);
            }

            if (cModifiers > 0)
            {
                int* arModifiers = (int*)pModifiers.ToPointer();
                for(int i = 0; i < cModifiers; i++)
                {
                    if ((CorElementType)Marshal.ReadInt32((IntPtr)arModifiers, i * sizeof(int)) == CorElementType.Ptr)
                        type = type.MakePointerType();
                    
                    else if ((CorElementType)Marshal.ReadInt32((IntPtr)arModifiers, i * sizeof(int)) == CorElementType.ByRef)
                        type = type.MakeByRefType();

                    else if ((CorElementType)Marshal.ReadInt32((IntPtr)arModifiers, i * sizeof(int)) == CorElementType.SzArray)
                        type = type.MakeArrayType();

                    else
                        type = type.MakeArrayType(Marshal.ReadInt32((IntPtr)arModifiers, ++i * sizeof(int)));
                }
            }
            
            return type.GetTypeHandleInternal().Value;
        }
コード例 #11
0
        public static FieldInfo GetFieldFromHandle(RuntimeFieldHandle handle, RuntimeTypeHandle declaringType)
        {
            if (handle.IsNullHandle())
                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidHandle"));

#if !FEATURE_CORECLR
            if (FrameworkEventSource.IsInitialized && FrameworkEventSource.Log.IsEnabled(EventLevel.Informational, FrameworkEventSource.Keywords.DynamicTypeUsage))
            {
                FrameworkEventSource.Log.BeginGetFieldFromHandle();
            }
#endif

            FieldInfo f = RuntimeType.GetFieldInfo(declaringType.GetRuntimeType(), handle.GetRuntimeFieldInfo());

#if !FEATURE_CORECLR
            if (FrameworkEventSource.IsInitialized && FrameworkEventSource.Log.IsEnabled(EventLevel.Informational, FrameworkEventSource.Keywords.DynamicTypeUsage) && declaringType != null && f != null)
            {
                FrameworkEventSource.Log.EndGetFieldFromHandle(declaringType.GetRuntimeType().GetFullNameForEtw(), f.GetFullNameForEtw());
            }
#endif

            return f;
        }           
コード例 #12
0
ファイル: Associates.cs プロジェクト: randomize/VimConfig
 internal static unsafe void AssignAssociates(AssociateRecord* associates, int cAssociates, RuntimeTypeHandle declaringTypeHandle, RuntimeTypeHandle reflectedTypeHandle, out RuntimeMethodInfo addOn, out RuntimeMethodInfo removeOn, out RuntimeMethodInfo fireOn, out RuntimeMethodInfo getter, out RuntimeMethodInfo setter, out MethodInfo[] other, out bool composedOfAllPrivateMethods, out BindingFlags bindingFlags)
 {
     RuntimeMethodInfo info2;
     RuntimeMethodInfo info3;
     RuntimeMethodInfo info4;
     setter = (RuntimeMethodInfo) (info2 = null);
     getter = info3 = info2;
     fireOn = info4 = info3;
     addOn = removeOn = info4;
     other = null;
     Attributes attributes = Attributes.ComposedOfNoStaticMembers | Attributes.ComposedOfNoPublicMembers | Attributes.ComposedOfAllPrivateMethods | Attributes.ComposedOfAllVirtualMethods;
     while (reflectedTypeHandle.IsGenericVariable())
     {
         reflectedTypeHandle = reflectedTypeHandle.GetRuntimeType().BaseType.GetTypeHandleInternal();
     }
     bool isInherited = !declaringTypeHandle.Equals(reflectedTypeHandle);
     ArrayList list = new ArrayList();
     for (int i = 0; i < cAssociates; i++)
     {
         RuntimeMethodInfo info = AssignAssociates(associates[i].MethodDefToken, declaringTypeHandle, reflectedTypeHandle);
         if (info != null)
         {
             MethodAttributes attributes2 = info.Attributes;
             bool flag2 = (attributes2 & MethodAttributes.MemberAccessMask) == MethodAttributes.Private;
             bool flag3 = (attributes2 & MethodAttributes.Virtual) != MethodAttributes.PrivateScope;
             MethodAttributes attributes3 = attributes2 & MethodAttributes.MemberAccessMask;
             bool flag4 = attributes3 == MethodAttributes.Public;
             bool flag5 = (attributes2 & MethodAttributes.Static) != MethodAttributes.PrivateScope;
             if (flag4)
             {
                 attributes &= ~Attributes.ComposedOfNoPublicMembers;
                 attributes &= ~Attributes.ComposedOfAllPrivateMethods;
             }
             else if (!flag2)
             {
                 attributes &= ~Attributes.ComposedOfAllPrivateMethods;
             }
             if (flag5)
             {
                 attributes &= ~Attributes.ComposedOfNoStaticMembers;
             }
             if (!flag3)
             {
                 attributes &= ~Attributes.ComposedOfAllVirtualMethods;
             }
             if (associates[i].Semantics == MethodSemanticsAttributes.Setter)
             {
                 setter = info;
             }
             else if (associates[i].Semantics == MethodSemanticsAttributes.Getter)
             {
                 getter = info;
             }
             else if (associates[i].Semantics == MethodSemanticsAttributes.Fire)
             {
                 fireOn = info;
             }
             else if (associates[i].Semantics == MethodSemanticsAttributes.AddOn)
             {
                 addOn = info;
             }
             else if (associates[i].Semantics == MethodSemanticsAttributes.RemoveOn)
             {
                 removeOn = info;
             }
             else
             {
                 list.Add(info);
             }
         }
     }
     bool isPublic = (attributes & Attributes.ComposedOfNoPublicMembers) == 0;
     bool isStatic = (attributes & Attributes.ComposedOfNoStaticMembers) == 0;
     bindingFlags = RuntimeType.FilterPreCalculate(isPublic, isInherited, isStatic);
     composedOfAllPrivateMethods = (attributes & Attributes.ComposedOfAllPrivateMethods) != 0;
     other = (MethodInfo[]) list.ToArray(typeof(MethodInfo));
 }
コード例 #13
0
ファイル: runtimehelpers.cs プロジェクト: uQr/referencesource
 public static void RunClassConstructor(RuntimeTypeHandle type) 
 {
     _RunClassConstructor(type.GetRuntimeType());
 }
コード例 #14
0
ファイル: FieldInfo.cs プロジェクト: nietras/coreclr
 internal MdFieldInfo(
 int tkField, FieldAttributes fieldAttributes, RuntimeTypeHandle declaringTypeHandle, RuntimeTypeCache reflectedTypeCache, BindingFlags bindingFlags)
     : base(reflectedTypeCache, declaringTypeHandle.GetRuntimeType(), bindingFlags)
 {
     m_tkField = tkField;
     m_name = null; 
     m_fieldAttributes = fieldAttributes;
 }
コード例 #15
0
        internal static unsafe void AssignAssociates(
            AssociateRecord* associates,
            int cAssociates, 
            RuntimeTypeHandle declaringTypeHandle,
            RuntimeTypeHandle reflectedTypeHandle,
            out RuntimeMethodInfo addOn,
            out RuntimeMethodInfo removeOn,
            out RuntimeMethodInfo fireOn,
            out RuntimeMethodInfo getter,
            out RuntimeMethodInfo setter,
            out MethodInfo[] other,
            out bool composedOfAllPrivateMethods,
            out BindingFlags bindingFlags)
        {
            addOn = removeOn = fireOn = getter = setter = null;
            other = null;

            Attributes attributes = 
                Attributes.ComposedOfAllPrivateMethods |
                Attributes.ComposedOfAllVirtualMethods |
                Attributes.ComposedOfNoPublicMembers |
                Attributes.ComposedOfNoStaticMembers;

            while(reflectedTypeHandle.IsGenericVariable())
                reflectedTypeHandle = reflectedTypeHandle.GetRuntimeType().BaseType.GetTypeHandleInternal();

            bool isInherited = !declaringTypeHandle.Equals(reflectedTypeHandle);

            ArrayList otherList = new ArrayList();

            for (int i = 0; i < cAssociates; i++)
            {   
                #region Assign each associate
                RuntimeMethodInfo associateMethod = 
                    AssignAssociates(associates[i].MethodDefToken, declaringTypeHandle, reflectedTypeHandle);

                if (associateMethod == null)
                    continue;

                MethodAttributes methAttr = associateMethod.Attributes;
                bool isPrivate =(methAttr & MethodAttributes.MemberAccessMask) == MethodAttributes.Private;
                bool isVirtual =(methAttr & MethodAttributes.Virtual) != 0;

                MethodAttributes visibility = methAttr & MethodAttributes.MemberAccessMask;
                bool isPublic = visibility == MethodAttributes.Public;
                bool isNonProtectedInternal = visibility == MethodAttributes.Assembly;
                bool isStatic =(methAttr & MethodAttributes.Static) != 0;

                if (isPublic)
                {
                    attributes &= ~Attributes.ComposedOfNoPublicMembers;
                    attributes &= ~Attributes.ComposedOfAllPrivateMethods;
                }
                else if (!isPrivate)
                {
                    attributes &= ~Attributes.ComposedOfAllPrivateMethods;
                }

                if (isStatic)
                    attributes &= ~Attributes.ComposedOfNoStaticMembers;

                if (!isVirtual)
                    attributes &= ~Attributes.ComposedOfAllVirtualMethods;
                #endregion

                if (associates[i].Semantics == MethodSemanticsAttributes.Setter)
                    setter = associateMethod;
                else if (associates[i].Semantics == MethodSemanticsAttributes.Getter)
                    getter = associateMethod;
                else if (associates[i].Semantics == MethodSemanticsAttributes.Fire)
                    fireOn = associateMethod;
                else if (associates[i].Semantics == MethodSemanticsAttributes.AddOn)
                    addOn = associateMethod;
                else if (associates[i].Semantics == MethodSemanticsAttributes.RemoveOn)
                    removeOn = associateMethod;
                else
                    otherList.Add(associateMethod);
            }

            bool isPseudoPublic = (attributes & Attributes.ComposedOfNoPublicMembers) == 0;
            bool isPseudoStatic = (attributes & Attributes.ComposedOfNoStaticMembers) == 0;
            bindingFlags = RuntimeType.FilterPreCalculate(isPseudoPublic, isInherited, isPseudoStatic);

            composedOfAllPrivateMethods =(attributes & Attributes.ComposedOfAllPrivateMethods) != 0;

            other = (MethodInfo[])otherList.ToArray(typeof(MethodInfo));
        }
コード例 #16
0
        internal static unsafe RuntimeMethodInfo AssignAssociates(
            int tkMethod,
            RuntimeTypeHandle declaredTypeHandle,
            RuntimeTypeHandle reflectedTypeHandle)
        {
            if (MetadataToken.IsNullToken(tkMethod))
                return null;

            ASSERT.PRECONDITION(!declaredTypeHandle.IsNullHandle());
            ASSERT.PRECONDITION(!reflectedTypeHandle.IsNullHandle());

            bool isInherited = !declaredTypeHandle.Equals(reflectedTypeHandle);

            RuntimeMethodHandle associateMethodHandle = declaredTypeHandle.GetModuleHandle().ResolveMethodHandle(tkMethod, declaredTypeHandle.GetInstantiation(), new RuntimeTypeHandle[0]);
            //RuntimeMethodHandle associateMethodHandle = declaredTypeHandle.GetMethodFromToken(tkMethod);
            ASSERT.CONSISTENCY_CHECK(!associateMethodHandle.IsNullHandle(), "Failed to resolve associateRecord methodDef token");

            MethodAttributes methAttr = associateMethodHandle.GetAttributes();
            bool isPrivate =(methAttr & MethodAttributes.MemberAccessMask) == MethodAttributes.Private;
            bool isVirtual =(methAttr & MethodAttributes.Virtual) != 0;

            if (isInherited)
            {
                // 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 (isPrivate)
                    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 (isVirtual)
                {
                    bool declaringTypeIsClass = 
                        (declaredTypeHandle.GetAttributes() & TypeAttributes.ClassSemanticsMask) == TypeAttributes.Class;

                    ASSERT.CONSISTENCY_CHECK(LOGIC.BIJECTION(declaringTypeIsClass, 
                        (reflectedTypeHandle.GetAttributes() & 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 = associateMethodHandle.GetSlot();

                        // Find the override visible from the reflected type
                        associateMethodHandle = reflectedTypeHandle.GetMethodAt(slot);
                    }
                }
            }

            MethodAttributes visibility = methAttr & MethodAttributes.MemberAccessMask;
            bool isPublic = visibility == MethodAttributes.Public;
            bool isNonProtectedInternal = visibility == MethodAttributes.Assembly;
            bool isStatic =(methAttr & MethodAttributes.Static) != 0;

            RuntimeMethodInfo associateMethod = 
                RuntimeType.GetMethodBase(reflectedTypeHandle, associateMethodHandle) as RuntimeMethodInfo;

            // suppose a property was mapped to a method not in the derivation hierarchy of the reflectedTypeHandle
            if (associateMethod == null)
                associateMethod = reflectedTypeHandle.GetRuntimeType().Module.ResolveMethod(tkMethod, null, null) as RuntimeMethodInfo;

            return associateMethod;
        }
コード例 #17
0
        public static MethodBase GetMethodFromHandle(RuntimeMethodHandle handle, RuntimeTypeHandle declaringType)
        {
            if (handle.IsNullHandle())
                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidHandle"));

#if !FEATURE_CORECLR && !MONO
            if (FrameworkEventSource.IsInitialized && FrameworkEventSource.Log.IsEnabled(EventLevel.Informational, FrameworkEventSource.Keywords.DynamicTypeUsage))
            {
                FrameworkEventSource.Log.BeginGetMethodFromHandle();
            }
#endif
            
#if MONO
            MethodBase m = GetMethodFromHandleInternalType (handle.Value, declaringType.Value);
            if (m == null)
                throw new ArgumentException ("The handle is invalid.");
#else
            MethodBase m = RuntimeType.GetMethodBase(declaringType.GetRuntimeType(), handle.GetMethodInfo());
#endif

#if !FEATURE_CORECLR && !MONO
            if (FrameworkEventSource.IsInitialized && FrameworkEventSource.Log.IsEnabled(EventLevel.Informational, FrameworkEventSource.Keywords.DynamicTypeUsage) && declaringType != null && m != null)
            {
                FrameworkEventSource.Log.EndGetMethodFromHandle(declaringType.GetRuntimeType().GetFullNameForEtw(), m.GetFullNameForEtw());
            }
#endif

            return m;
        }
コード例 #18
0
        public static unsafe object GetValue(MetadataImport scope, int token, RuntimeTypeHandle fieldTypeHandle, bool raw)
        {
            int num2;
            long num4;
            CorElementType end = CorElementType.End;
            long num = 0L;
            string str = scope.GetDefaultValue(token, out num, out num2, out end);
            RuntimeType runtimeType = fieldTypeHandle.GetRuntimeType();
            if (!runtimeType.IsEnum || raw)
            {
                if (runtimeType == typeof(DateTime))
                {
                    num4 = 0L;
                    switch (end)
                    {
                        case CorElementType.I8:
                            num4 = num;
                            goto Label_0129;

                        case CorElementType.U8:
                            num4 = num;
                            goto Label_0129;

                        case CorElementType.Void:
                            return DBNull.Value;
                    }
                    throw new FormatException(Environment.GetResourceString("Arg_BadLiteralFormat"));
                }
                switch (end)
                {
                    case CorElementType.Void:
                        return DBNull.Value;

                    case CorElementType.Boolean:
                        return (*(((int*) &num)) != 0);

                    case CorElementType.Char:
                        return (char) *(((ushort*) &num));

                    case CorElementType.I1:
                        return *(((sbyte*) &num));

                    case CorElementType.U1:
                        return *(((byte*) &num));

                    case CorElementType.I2:
                        return *(((short*) &num));

                    case CorElementType.U2:
                        return *(((ushort*) &num));

                    case CorElementType.I4:
                        return *(((int*) &num));

                    case CorElementType.U4:
                        return *(((uint*) &num));

                    case CorElementType.I8:
                        return num;

                    case CorElementType.U8:
                        return (ulong) num;

                    case CorElementType.R4:
                        return *(((float*) &num));

                    case CorElementType.R8:
                        return *(((double*) &num));

                    case CorElementType.String:
                        if (str == null)
                        {
                            return string.Empty;
                        }
                        return str;

                    case CorElementType.Class:
                        return null;
                }
                throw new FormatException(Environment.GetResourceString("Arg_BadLiteralFormat"));
            }
            long num3 = 0L;
            switch (end)
            {
                case CorElementType.Void:
                    return DBNull.Value;

                case CorElementType.Char:
                    num3 = *((ushort*) &num);
                    break;

                case CorElementType.I1:
                    num3 = *((sbyte*) &num);
                    break;

                case CorElementType.U1:
                    num3 = *((byte*) &num);
                    break;

                case CorElementType.I2:
                    num3 = *((short*) &num);
                    break;

                case CorElementType.U2:
                    num3 = *((ushort*) &num);
                    break;

                case CorElementType.I4:
                    num3 = *((int*) &num);
                    break;

                case CorElementType.U4:
                    num3 = *((uint*) &num);
                    break;

                case CorElementType.I8:
                    num3 = num;
                    break;

                case CorElementType.U8:
                    num3 = num;
                    break;

                default:
                    throw new FormatException(Environment.GetResourceString("Arg_BadLiteralFormat"));
            }
            return RuntimeType.CreateEnum(runtimeType, num3);
        Label_0129:
            return new DateTime(num4);
        }
コード例 #19
0
 public static MethodBase GetMethodFromHandle(RuntimeMethodHandle handle, RuntimeTypeHandle declaringType)
 {
     if (handle.IsNullHandle())
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_InvalidHandle"));
     }
     return RuntimeType.GetMethodBase(declaringType.GetRuntimeType(), handle.GetMethodInfo());
 }
コード例 #20
0
ファイル: mdconstant.cs プロジェクト: uQr/referencesource
        [System.Security.SecurityCritical]  // auto-generated
        public static unsafe Object GetValue(MetadataImport scope, int token, RuntimeTypeHandle fieldTypeHandle, bool raw)
        {
            CorElementType corElementType = 0;
            long buffer = 0;
            int length;
            String stringVal;

            stringVal = scope.GetDefaultValue(token, out buffer, out length, out corElementType);

            RuntimeType fieldType = fieldTypeHandle.GetRuntimeType();

            if (fieldType.IsEnum && raw == false)
            {
                long defaultValue = 0;

                switch (corElementType)
                {
                    #region Switch

                    case CorElementType.Void:
                        return DBNull.Value;

                    case CorElementType.Char:
                        defaultValue = *(char*)&buffer;
                        break;

                    case CorElementType.I1:
                        defaultValue = *(sbyte*)&buffer;
                        break;

                    case CorElementType.U1:
                        defaultValue = *(byte*)&buffer;
                        break;

                    case CorElementType.I2:
                        defaultValue = *(short*)&buffer;
                        break;

                    case CorElementType.U2:
                        defaultValue = *(ushort*)&buffer;
                        break;

                    case CorElementType.I4:
                        defaultValue = *(int*)&buffer;
                        break;

                    case CorElementType.U4:
                        defaultValue = *(uint*)&buffer;
                        break;

                    case CorElementType.I8:
                        defaultValue = buffer;
                        break;

                    case CorElementType.U8:
                        defaultValue = buffer;
                        break;
                
                    default:
                        throw new FormatException(Environment.GetResourceString("Arg_BadLiteralFormat"));
                    #endregion
                }

                return RuntimeType.CreateEnum(fieldType, defaultValue);                       
            }
            else if (fieldType == typeof(DateTime))
            {
                long defaultValue = 0;

                switch (corElementType)
                {
                    #region Switch

                    case CorElementType.Void:
                        return DBNull.Value;
                        
                    case CorElementType.I8:
                        defaultValue = buffer;
                        break;

                    case CorElementType.U8:
                        defaultValue = buffer;
                        break;
                
                    default:
                        throw new FormatException(Environment.GetResourceString("Arg_BadLiteralFormat"));
                    #endregion  
                }

                return new DateTime(defaultValue);
            }
            else
            {
                switch (corElementType)
                {
                    #region Switch

                    case CorElementType.Void:
                        return DBNull.Value;

                    case CorElementType.Char:
                        return *(char*)&buffer;

                    case CorElementType.I1:
                        return *(sbyte*)&buffer;

                    case CorElementType.U1:
                        return *(byte*)&buffer;

                    case CorElementType.I2:
                        return *(short*)&buffer;

                    case CorElementType.U2:
                        return *(ushort*)&buffer;

                    case CorElementType.I4:
                        return *(int*)&buffer;

                    case CorElementType.U4:
                        return *(uint*)&buffer;

                    case CorElementType.I8:
                        return buffer;

                    case CorElementType.U8:
                        return (ulong)buffer;
                
                    case CorElementType.Boolean :
                        // The boolean value returned from the metadata engine is stored as a
                        // BOOL, which actually maps to an int. We need to read it out as an int
                        // to avoid problems on big-endian machines.
                        return (*(int*)&buffer != 0);

                    case CorElementType.R4 :
                        return *(float*)&buffer;

                    case CorElementType.R8:
                        return *(double*)&buffer;

                    case CorElementType.String:
                        // A string constant can be empty but never null.
                        // A nullref constant can only be type CorElementType.Class.
                        return stringVal == null ? String.Empty : stringVal;

                    case CorElementType.Class:
                        return null;
                    
                    default:
                        throw new FormatException(Environment.GetResourceString("Arg_BadLiteralFormat"));
                    #endregion
                }
            }
        } 
コード例 #21
0
        public static MethodBase GetMethodFromHandle(RuntimeMethodHandle handle, RuntimeTypeHandle declaringType)
        {
            if (handle.IsNullHandle())
                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidHandle"));

#if MONO
            MethodBase m = GetMethodFromHandleInternalType (handle.Value, declaringType.Value);
            if (m == null)
                throw new ArgumentException ("The handle is invalid.");
            return m;
#else
            return RuntimeType.GetMethodBase(declaringType.GetRuntimeType(), handle.GetMethodInfo());
#endif
        }
コード例 #22
0
 internal static unsafe Type GetTypeByNameUsingCARules(string name, Module scope)
 {
     if ((name == null) || (name.Length == 0))
     {
         throw new ArgumentException();
     }
     RuntimeTypeHandle handle2 = new RuntimeTypeHandle(_GetTypeByNameUsingCARules(name, (IntPtr) scope.GetModuleHandle().Value));
     return handle2.GetRuntimeType();
 }
コード例 #23
0
        internal RuntimeConstructorInfo(
            RuntimeMethodHandle handle, RuntimeTypeHandle declaringTypeHandle, RuntimeTypeCache reflectedTypeCache,
            MethodAttributes methodAttributes, BindingFlags bindingFlags)
        {
            ASSERT.POSTCONDITION(methodAttributes == handle.GetAttributes());

            m_bindingFlags = bindingFlags;
            m_handle = handle;
            m_reflectedTypeCache = reflectedTypeCache;
            m_declaringType = declaringTypeHandle.GetRuntimeType();
            m_parameters = null; // Created lazily when GetParameters() is called.
            m_toString = null;
            m_methodAttributes = methodAttributes;
        }