예제 #1
0
        public unsafe bool TryGetMetadataForNamedType(RuntimeTypeHandle runtimeTypeHandle, out MetadataReader metadataReader, out TypeDefinitionHandle typeDefHandle)
        {
            // Iterate over all modules, starting with the module that defines the EEType
            foreach (IntPtr moduleHandle in ModuleList.Enumerate(RuntimeAugments.GetModuleFromTypeHandle(runtimeTypeHandle)))
            {
                MetadataTable mapTable = MetadataTable.CreateTypeMapTable(moduleHandle);
                foreach (var ptrEntry in mapTable)
                {
                    var pCurrentEntry = (TypeMapEntry*)ptrEntry;
                    RuntimeTypeHandle entryTypeHandle = RuntimeAugments.CreateRuntimeTypeHandle(pCurrentEntry->EEType);
                    Handle entryMetadataHandle = pCurrentEntry->TypeDefinitionHandle.AsHandle();
                    if (entryTypeHandle.Equals(runtimeTypeHandle) &&
                        entryMetadataHandle.HandleType == HandleType.TypeDefinition)
                    {
                        metadataReader = ModuleList.Instance.GetMetadataReaderForModule(moduleHandle);
                        typeDefHandle = entryMetadataHandle.ToTypeDefinitionHandle(metadataReader);
                        return true;
                    }
                }
            }

            metadataReader = null;
            typeDefHandle = default(TypeDefinitionHandle);

            return false;
        }
예제 #2
0
파일: Method.cs 프로젝트: wnxd/e.net
 static bool 载入(RuntimeTypeHandle 窗口类型, ref 窗口 欲载入的窗口, IWin32Window 父窗口 = null, bool 是否采用对话框方式 = true)
 {
     欲载入的窗口 = (窗口)Activator.CreateInstance(Type.GetTypeFromHandle(窗口类型));
     if (是否采用对话框方式) Application.Run(欲载入的窗口);
     else 欲载入的窗口.Show(父窗口);
     return true;
 }
예제 #3
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;
            }
        }
예제 #4
0
 public OpenMethodResolver(RuntimeTypeHandle declaringTypeOfSlot, int slot, int handle)
 {
     _resolveType = DispatchResolve;
     _declaringType = declaringTypeOfSlot;
     _methodHandleOrSlotOrCodePointer = new IntPtr(slot);
     _handle = handle;
 }
예제 #5
0
 public unsafe OpenMethodResolver(RuntimeTypeHandle declaringTypeOfSlot, RuntimeMethodHandle gvmSlot, int handle)
 {
     _resolveType = GVMResolve;
     _methodHandleOrSlotOrCodePointer = *(IntPtr*)&gvmSlot;
     _declaringType = declaringTypeOfSlot;
     _handle = handle;
 }
예제 #6
0
 public OpenMethodResolver(RuntimeTypeHandle declaringType, IntPtr codePointer, int handle)
 {
     _resolveType = OpenNonVirtualResolve;
     _methodHandleOrSlotOrCodePointer = codePointer;
     _declaringType = declaringType;
     _handle = handle;
 }
 /// <summary>
 /// Saves a named field, by accessing its value using reflection
 /// </summary>
 public static void SaveNamedField( IOutput output, RuntimeTypeHandle objTypeHandle, object obj, string fieldName )
 {
     Type objType = Type.GetTypeFromHandle( objTypeHandle );
     FieldInfo fieldInfo = objType.GetField( fieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance );
     object field = fieldInfo.GetValue( obj  );
     output.Write( field );
 }
예제 #8
0
        internal RuntimeType(RuntimeTypeHandle handle)
        {
            this.handle = handle;
            typeStruct = (MetadataTypeStruct*)((uint**)&handle)[0];

            assemblyQualifiedName = Mosa.Runtime.Internal.InitializeMetadataString(typeStruct->Name);    // TODO
            name = Mosa.Runtime.Internal.InitializeMetadataString(typeStruct->Name);                 // TODO
            @namespace = Mosa.Runtime.Internal.InitializeMetadataString(typeStruct->Name);               // TODO
            fullname = Mosa.Runtime.Internal.InitializeMetadataString(typeStruct->Name);

            typeCode = (TypeCode)(typeStruct->Attributes >> 24);
            attributes = (TypeAttributes)(typeStruct->Attributes & 0x00FFFFFF);

            // Declaring Type
            if (typeStruct->DeclaringType != null)
            {
                RuntimeTypeHandle declaringHandle = new RuntimeTypeHandle();
                ((uint**)&declaringHandle)[0] = (uint*)typeStruct->DeclaringType;
                declaringTypeHandle = declaringHandle;
            }

            // Element Type
            if ((*typeStruct).ElementType != null)
            {
                RuntimeTypeHandle elementHandle = new RuntimeTypeHandle();
                ((uint**)&elementHandle)[0] = (uint*)typeStruct->ElementType;
                elementTypeHandle = elementHandle;
            }
        }
        public bool TryGetGenericVirtualTargetForTypeAndSlot(RuntimeTypeHandle targetHandle, ref RuntimeTypeHandle declaringType, RuntimeTypeHandle[] genericArguments, ref string methodName, ref RuntimeMethodSignature methodSignature, out IntPtr methodPointer, out IntPtr dictionaryPointer, out bool slotUpdated)
        {
            MethodNameAndSignature methodNameAndSignature = new MethodNameAndSignature(methodName, methodSignature);

#if REFLECTION_EXECUTION_TRACE
            ReflectionExecutionLogger.WriteLine("GVM resolution starting for " + GetTypeNameDebug(declaringType) + "." + methodNameAndSignature.Name + "(...)  on a target of type " + GetTypeNameDebug(targetHandle) + " ...");
#endif

            if (RuntimeAugments.IsInterface(declaringType))
            {
                methodPointer = IntPtr.Zero;
                dictionaryPointer = IntPtr.Zero;

                slotUpdated = ResolveInterfaceGenericVirtualMethodSlot(targetHandle, ref declaringType, ref methodNameAndSignature);

                methodName = methodNameAndSignature.Name;
                methodSignature = methodNameAndSignature.Signature;
                return slotUpdated;
            }
            else
            {
                slotUpdated = false;
                return ResolveGenericVirtualMethodTarget(targetHandle, declaringType, genericArguments, methodNameAndSignature, out methodPointer, out dictionaryPointer);
            }
        }
 private NativeFormatRuntimeNamedTypeInfo(MetadataReader reader, TypeDefinitionHandle typeDefinitionHandle, RuntimeTypeHandle typeHandle) :
     base(typeHandle)
 {
     _reader = reader;
     _typeDefinitionHandle = typeDefinitionHandle;
     _typeDefinition = _typeDefinitionHandle.GetTypeDefinition(reader);
 }
 protected override void SerializeWithXsiType(XmlWriterDelegator xmlWriter, object obj, RuntimeTypeHandle objectTypeHandle, Type objectType, int declaredTypeID, RuntimeTypeHandle declaredTypeHandle, Type declaredType)
 {
     DataContract dataContract;
     bool verifyKnownType = false;
     bool isInterface = declaredType.IsInterface;
     if (isInterface && CollectionDataContract.IsCollectionInterface(declaredType))
     {
         dataContract = this.GetDataContract(declaredTypeHandle, declaredType);
     }
     else if (declaredType.IsArray)
     {
         dataContract = this.GetDataContract(declaredTypeHandle, declaredType);
     }
     else
     {
         dataContract = this.GetDataContract(objectTypeHandle, objectType);
         DataContract declaredContract = (declaredTypeID >= 0) ? this.GetDataContract(declaredTypeID, declaredTypeHandle) : this.GetDataContract(declaredTypeHandle, declaredType);
         verifyKnownType = this.WriteTypeInfo(xmlWriter, dataContract, declaredContract);
         this.HandleCollectionAssignedToObject(declaredType, ref dataContract, ref obj, ref verifyKnownType);
     }
     if (isInterface)
     {
         VerifyObjectCompatibilityWithInterface(dataContract, obj, declaredType);
     }
     base.SerializeAndVerifyType(dataContract, xmlWriter, obj, verifyKnownType, declaredType.TypeHandle, declaredType);
 }
예제 #12
0
 public GetFieldBinder(string name, RuntimeTypeHandle classContext, RuntimeTypeHandle returnType, AccessFlags access)
 {
     _name = name;
     _returnType = Type.GetTypeFromHandle(returnType); // should correspond to AccessFlags
     _classContext = Type.GetTypeFromHandle(classContext);
     _access = access;
 }
예제 #13
0
 /// <summary>
 ///  Setter for RuntimeTypeHandle. Seperate from normal property as all uses should be done with great care.
 ///  Must not be set with partially constructed type handles
 /// </summary>
 public void SetRuntimeTypeHandleUnsafe(RuntimeTypeHandle runtimeTypeHandle)
 {
     Debug.Assert(!runtimeTypeHandle.IsNull());
     Debug.Assert(_runtimeTypeHandle.IsNull() || runtimeTypeHandle.Equals(_runtimeTypeHandle));
     Debug.Assert(runtimeTypeHandle.GetHashCode() == GetHashCode());
     _runtimeTypeHandle = runtimeTypeHandle;
 }
예제 #14
0
        //XStringMapEnumAttribute xStringMapEnumAttr;

        //static readonly System.RuntimeTypeHandle METAXStringToEnumAttr=typeof(XStringMapEnumAttribute).TypeHandle;

        public MapHandler(PropertyInfo pmeta)
        {
            this.setvalueToInstance   = (Action <T, int>)System.Delegate.CreateDelegate(typeof(Action <T, int>), pmeta.GetSetMethod());
            this.getvalueFromInstance = (Func <T, int>)System.Delegate.CreateDelegate(typeof(Func <T, int>), pmeta.GetGetMethod());
            //this.xStringMapEnumAttr = pmeta.GetCustomAttributes(System.Type.GetTypeFromHandle(METAXStringToEnumAttr),false).Cast<XStringMapEnumAttribute>().FirstOrDefault();
            this.propertyRTH = pmeta.PropertyType.TypeHandle;
        }
예제 #15
0
        protected CallBinder(RuntimeTypeHandle returnType, int genericParams)
        {
            Debug.Assert(genericParams >= 0);

            _returnType = Type.GetTypeFromHandle(returnType);
            _genericParamsCount = genericParams;
        }
        public bool IsCanonicallyEquivalent(RuntimeTypeHandle other)
        {
            if (_defType != null)
            {
                TypeDesc typeToFindAsCanon = _defType.ConvertToCanonForm(_canonKind);
                TypeDesc otherTypeAsTypeDesc = _defType.Context.ResolveRuntimeTypeHandle(other);
                TypeDesc otherTypeAsCanon = otherTypeAsTypeDesc.ConvertToCanonForm(_canonKind);
                return typeToFindAsCanon == otherTypeAsCanon;
            }

            if (!_genericDefinition.IsNull())
            {
                if (RuntimeAugments.IsGenericType(other))
                {
                    RuntimeTypeHandle otherGenericDefinition;
                    RuntimeTypeHandle[] otherGenericArgs;
                    otherGenericDefinition = RuntimeAugments.GetGenericInstantiation(other, out otherGenericArgs);

                    return _genericDefinition.Equals(otherGenericDefinition) && TypeLoaderEnvironment.Instance.CanInstantiationsShareCode(_genericArgs, otherGenericArgs, _canonKind);
                }
                else
                    return false;
            }
            else
                return _typeToFind.Equals(other);
        }
예제 #17
0
 private static RuntimeTypeHandle GetTypeHandle(void* obj)
 {
     // TypeDefinition is located at the beginning of object (i.e. *obj )
     RuntimeTypeHandle handle = new RuntimeTypeHandle();
     ((uint*)&handle)[0] = ((uint*)obj)[0];
     return handle;
 }
예제 #18
0
파일: N565.cs 프로젝트: Cestbienmoi/Bridge
        public static void TestUseCase(Assert assert)
        {
            assert.Expect(7);

            var t1 = new Type();
            assert.Ok(t1 != null, "#565 t1");

            var t2 = new ValueType();
            assert.Ok(t2 != null, "#565 t2");

            var t3 = new IntPtr();
            assert.Ok(t3.GetType() == typeof(IntPtr) , "#565 t3");

            var t4 = new UIntPtr();
            assert.Ok(t4.GetType() == typeof(UIntPtr), "#565 t4");

            var t5 = new ParamArrayAttribute();
            assert.Ok(t5 != null, "#565 t5");

            var t6 = new RuntimeTypeHandle();
            assert.Ok(t6.GetType() == typeof(RuntimeTypeHandle), "#565 t6");

            var t7 = new RuntimeFieldHandle();
            assert.Ok(t7.GetType() == typeof(RuntimeFieldHandle), "#565 t7");
        }
예제 #19
0
        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());
        }           
예제 #20
0
        static StackObject *GetFieldFromHandle_20(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 2);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.RuntimeTypeHandle @declaringType = (System.RuntimeTypeHandle) typeof(System.RuntimeTypeHandle).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            System.RuntimeFieldHandle @handle = (System.RuntimeFieldHandle) typeof(System.RuntimeFieldHandle).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);


            var result_of_this_method = System.Reflection.FieldInfo.GetFieldFromHandle(@handle, @declaringType);

            object obj_result_of_this_method = result_of_this_method;

            if (obj_result_of_this_method is CrossBindingAdaptorType)
            {
                return(ILIntepreter.PushObject(__ret, __mStack, ((CrossBindingAdaptorType)obj_result_of_this_method).ILInstance));
            }
            return(ILIntepreter.PushObject(__ret, __mStack, result_of_this_method));
        }
예제 #21
0
파일: Delegate.cs 프로젝트: noahfalk/corert
        /// <summary>
        /// Used by various parts of the runtime as a replacement for Delegate.Method
        /// 
        /// The Interop layer uses this to distinguish between different methods on a 
        /// single type, and to get the function pointer for delegates to static functions
        /// 
        /// The reflection apis use this api to figure out what MethodInfo is related
        /// to a delegate.
        /// 
        /// </summary>
        /// <param name="typeOfFirstParameterIfInstanceDelegate"> 
        ///   This value indicates which type an delegate's function pointer is associated with
        ///   This value is ONLY set for delegates where the function pointer points at an instance method
        /// </param>
        /// <param name="isOpenResolver"> 
        ///   This value indicates if the returned pointer is an open resolver structure.
        /// </param>
        /// <returns></returns>
        unsafe internal IntPtr GetFunctionPointer(out RuntimeTypeHandle typeOfFirstParameterIfInstanceDelegate, out bool isOpenResolver)
        {
            typeOfFirstParameterIfInstanceDelegate = default(RuntimeTypeHandle);
            isOpenResolver = false;

            if (GetThunk(MulticastThunk) == m_functionPointer)
            {
                return IntPtr.Zero;
            }
            else if (m_extraFunctionPointerOrData != IntPtr.Zero)
            {
                if (GetThunk(OpenInstanceThunk) == m_functionPointer)
                {
                    typeOfFirstParameterIfInstanceDelegate = ((OpenMethodResolver*)m_extraFunctionPointerOrData)->DeclaringType;
                    isOpenResolver = true;
                }
                return m_extraFunctionPointerOrData;
            }
            else
            {
                if (m_firstParameter != null)
                    typeOfFirstParameterIfInstanceDelegate = new RuntimeTypeHandle(m_firstParameter.EETypePtr);

                // TODO! Implementation issue for generic invokes here ... we need another IntPtr for uniqueness.

                return m_functionPointer;
            }
        }
        private RuntimeTypeHandle GetTypeDefinition(RuntimeTypeHandle typeHandle)
        {
            if (RuntimeAugments.IsGenericType(typeHandle))
                return RuntimeAugments.GetGenericDefinition(typeHandle);

            return typeHandle;
        }
        private bool FindMatchingInterfaceSlot(IntPtr moduleHandle, NativeReader nativeLayoutReader, ref NativeParser entryParser, ref ExternalReferencesTable extRefs, ref RuntimeTypeHandle declaringType, ref MethodNameAndSignature methodNameAndSignature, RuntimeTypeHandle openTargetTypeHandle, RuntimeTypeHandle[] targetTypeInstantiation, bool variantDispatch)
        {
            uint numTargetImplementations = entryParser.GetUnsigned();

            for (uint j = 0; j < numTargetImplementations; j++)
            {
                uint nameAndSigToken = extRefs.GetRvaFromIndex(entryParser.GetUnsigned());
                MethodNameAndSignature targetMethodNameAndSignature = GetMethodNameAndSignatureFromNativeReader(nativeLayoutReader, nameAndSigToken);
                RuntimeTypeHandle targetTypeHandle = extRefs.GetRuntimeTypeHandleFromIndex(entryParser.GetUnsigned());

#if REFLECTION_EXECUTION_TRACE
                ReflectionExecutionLogger.WriteLine("    Searching for GVM implementation on targe type = " + GetTypeNameDebug(targetTypeHandle));
#endif

                uint numIfaceImpls = entryParser.GetUnsigned();

                for (uint k = 0; k < numIfaceImpls; k++)
                {
                    RuntimeTypeHandle implementingTypeHandle = extRefs.GetRuntimeTypeHandleFromIndex(entryParser.GetUnsigned());

                    uint numIfaceSigs = entryParser.GetUnsigned();

                    if (!openTargetTypeHandle.Equals(implementingTypeHandle))
                    {
                        // Skip over signatures data
                        for (uint l = 0; l < numIfaceSigs; l++)
                            entryParser.GetUnsigned();

                        continue;
                    }

                    for (uint l = 0; l < numIfaceSigs; l++)
                    {
                        RuntimeTypeHandle currentIfaceTypeHandle = default(RuntimeTypeHandle);

                        NativeParser ifaceSigParser = new NativeParser(nativeLayoutReader, extRefs.GetRvaFromIndex(entryParser.GetUnsigned()));
                        IntPtr currentIfaceSigPtr = ifaceSigParser.Reader.OffsetToAddress(ifaceSigParser.Offset);

                        if (TypeLoaderEnvironment.Instance.GetTypeFromSignatureAndContext(currentIfaceSigPtr, targetTypeInstantiation, null, out currentIfaceTypeHandle, out currentIfaceSigPtr))
                        {
                            Debug.Assert(!currentIfaceTypeHandle.IsNull());

                            if ((!variantDispatch && declaringType.Equals(currentIfaceTypeHandle)) ||
                                (variantDispatch && RuntimeAugments.IsAssignableFrom(declaringType, currentIfaceTypeHandle)))
                            {
#if REFLECTION_EXECUTION_TRACE
                                ReflectionExecutionLogger.WriteLine("    " + (declaringType.Equals(currentIfaceTypeHandle) ? "Exact" : "Variant-compatible") + " match found on this target type!");
#endif
                                // We found the GVM slot target for the input interface GVM call, so let's update the interface GVM slot and return success to the caller
                                declaringType = targetTypeHandle;
                                methodNameAndSignature = targetMethodNameAndSignature;
                                return true;
                            }
                        }
                    }
                }
            }

            return false;
        }
예제 #24
0
 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;
 }
예제 #25
0
 public static MethodBase GetMethodFromHandle(RuntimeMethodHandle handle, RuntimeTypeHandle declaringType)
 {
     if (handle.IsNullHandle())
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_InvalidHandle"));
     }
     return RuntimeType.GetMethodBase(declaringType, handle);
 }
예제 #26
0
 // TODO!! BEGIN REMOVE THIS CODE WHEN WE REMOVE ICASTABLE
 RuntimeTypeHandle ICastable.GetImplType(RuntimeTypeHandle interfaceType)
 {
     // TODO! Remove this hack that forces the il2il pipeline to not remove the ICastableObject interface or the _hiddenCacheField
     Exception junk;
     _hiddenCacheField = ((ICastableObject)this).CastToInterface(default(EETypePtr), false, out junk);
     // ENDTODO!
     return default(RuntimeTypeHandle);
 }
 internal CanonicallyEquivalentEntryLocator(DefType typeToFind, CanonicalFormKind kind)
 {
     _genericArgs = null;
     _genericDefinition = default(RuntimeTypeHandle);
     _typeToFind = default(RuntimeTypeHandle);
     _canonKind = kind;
     _defType = typeToFind;
 }
예제 #28
0
        public FuncNoKeyRegistration(IRegistration delegateRegistration)
        {
            this.delegateRegistration = delegateRegistration;
            this.funcType = Expression.GetFuncType(Type.GetTypeFromHandle(delegateRegistration.TypeHandle)).TypeHandle;

            var registrationContext = Expression.Parameter(typeof(IRegistrationContext), "registrationContext");
            this.generator = Expression.Lambda<Func<IRegistrationContext, object>>(this.GetInstanceExpression(registrationContext), registrationContext).Compile();
        }
예제 #29
0
        public FixupRuntimeTypeHandle(RuntimeTypeHandle runtimeTypeHandle)
        {
#if CLR_RUNTIMETYPEHANDLE
            throw new NotImplementedException(); // CORERT-TODO: RuntimeTypeHandle
#else
            _value = *(IntPtr*)&runtimeTypeHandle;
#endif
        }
        private RuntimeTypeHandle GetOpenTypeDefinition(RuntimeTypeHandle typeHandle, out RuntimeTypeHandle[] typeArgumentsHandles)
        {
            if (RuntimeAugments.IsGenericType(typeHandle))
                return RuntimeAugments.GetGenericInstantiation(typeHandle, out typeArgumentsHandles);

            typeArgumentsHandles = null;
            return typeHandle;
        }
 public override void WriteJsonValueCore(XmlWriterDelegator jsonWriter, object obj, XmlObjectSerializerWriteContextComplexJson context, RuntimeTypeHandle declaredTypeHandle)
 {
     DataContractSerializer serializer = new DataContractSerializer(Type.GetTypeFromHandle(declaredTypeHandle), this.GetKnownTypesFromContext(context, (context == null) ? null : context.SerializerKnownTypeList), 1, false, false, null);
     MemoryStream stream = new MemoryStream();
     serializer.WriteObject(stream, obj);
     stream.Position = 0L;
     string str = new StreamReader(stream).ReadToEnd();
     jsonWriter.WriteString(str);
 }
예제 #32
0
        static FeatureMerger()
        {
            Type adoMergerType = Type.GetType("System.Data.Merger, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
            _adoMergerTypeHandle = adoMergerType.TypeHandle;

            _createMerger = generateCreateMergerDelegate();
            _mergeSchema = generateMergeSchemaDelegate();
            _getKeyIndex = generateGetKeyIndexDelegate();
        }
        /// <summary>
        /// Initializes a new instance of Complex Type with properties from the type.
        /// </summary>
        /// <param name="type">The CLR type to construct from</param>
        internal ClrEntityType(Type type, string cspaceNamespaceName, string cspaceTypeName)
            : base(EntityUtil.GenericCheckArgumentNull(type, "type").Name, type.Namespace ?? string.Empty,
                   DataSpace.OSpace)
        {
            System.Diagnostics.Debug.Assert(!String.IsNullOrEmpty(cspaceNamespaceName) &&
                                            !String.IsNullOrEmpty(cspaceTypeName), "Mapping information must never be null");

            _type = type.TypeHandle;
            _cspaceNamespaceName = cspaceNamespaceName;
            _cspaceTypeName      = cspaceNamespaceName + "." + cspaceTypeName;
            this.Abstract        = type.IsAbstract;
        }
예제 #34
0
파일: ModuleRuntime.cs 프로젝트: znw333/sod
 /// <summary>
 /// 在所有的模块中查找并实例化指定的模块提供程序对象
 /// </summary>
 /// <typeparam name="T">模块提供程序对象类型/typeparam>
 /// <returns>模块提供程序对象</returns>
 public T ResolveProvider <T>() where T : IModuleProvider
 {
     System.RuntimeTypeHandle handle = typeof(T).TypeHandle;
     foreach (IModuleContext module in this.RegContext.GetAllModules())
     {
         try
         {
             return(module.GetProvider <T>());
         }
         catch
         {
         }
     }
     throw new Exception("类型未在相关的 ModuleRegistration实现类中注册,类型名称:" + typeof(T).Name);
 }
예제 #35
0
 public MethodInfo GetActionMethod(string providerName, string actionName)
 {
     if (dictModuleProviders.ContainsKey(providerName))
     {
         System.RuntimeTypeHandle providerHandle  = dictModuleProviders[providerName];
         MethodHandleInfo[]       actionHandleArr = dictProviderMethods[providerHandle];
         MethodHandleInfo         actionInfo      = actionHandleArr.FirstOrDefault(p => p.MethodName == actionName);
         if (actionInfo == null)
         {
             throw new Exception("未找到名称为 " + actionName + " 并且返回值是IActionResult 类型的方法");
         }
         return((MethodInfo)MethodInfo.GetMethodFromHandle(actionInfo.MethodHandle));
     }
     throw new Exception("未找到名称为" + providerName + " 的模块提供程序,请检查此类型是否在 ModuleRegistration 注册。");
 }
예제 #36
0
        static StackObject *GetTypeFromHandle_0(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 1);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.RuntimeTypeHandle @handle = (System.RuntimeTypeHandle) typeof(System.RuntimeTypeHandle).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack), (CLR.Utils.Extensions.TypeFlags) 16);
            __intp.Free(ptr_of_this_method);


            var result_of_this_method = System.Type.GetTypeFromHandle(@handle);

            return(ILIntepreter.PushObject(__ret, __mStack, result_of_this_method));
        }
예제 #37
0
        public T GetProvider <T>() where T : IModuleProvider
        {
            System.RuntimeTypeHandle handle         = typeof(T).TypeHandle;
            System.RuntimeTypeHandle providerHandle = dictModuleProviders.Values.FirstOrDefault(p => p.Equals(handle));

            if (providerHandle != null)
            {
                //Type providerType = Type.GetTypeFromHandle(providerHandle);
                //return (IModuleProvider)Activator.CreateInstance(providerType);
                return(Activator.CreateInstance <T>());
            }
            else
            {
                throw new Exception("类型未在 ModuleRegistration 注册,类型名称:" + typeof(T).Name);
            }
        }
예제 #38
0
        // public IModuleRuntime ModuleRuntime { get; set; }

        public void AddProvider(IModuleProvider provider)
        {
            System.RuntimeTypeHandle providerHandle = provider.GetType().TypeHandle;
            dictModuleProviders.Add(provider.PrividerName, providerHandle);
            //反射出所有结果为 IActionResult类型的方法

            List <MethodHandleInfo> actionMethods = new List <MethodHandleInfo>();

            foreach (MethodInfo method in provider.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public))
            {
                if (method.ReturnType.GetInterfaces().Contains(typeof(IActionResult)))
                {
                    MethodHandleInfo info = new MethodHandleInfo();
                    info.MethodHandle = method.MethodHandle;
                    info.MethodName   = method.Name;
                    actionMethods.Add(info);
                }
            }

            dictProviderMethods.Add(providerHandle, actionMethods.ToArray());
        }
예제 #39
0
 public static extern Type GetTypeFromHandle(RuntimeTypeHandle handle);
예제 #40
0
 internal QCallTypeHandle(ref System.RuntimeTypeHandle rth)
 {
     _ptr    = Unsafe.AsPointer(ref rth);
     _handle = rth.Value;
 }
예제 #41
0
 public static System.Reflection.MethodBase GetMethodFromHandle(System.RuntimeMethodHandle handle, System.RuntimeTypeHandle declaringType)
 {
     throw null;
 }
예제 #42
0
 public static System.Reflection.FieldInfo GetFieldFromHandle(System.RuntimeFieldHandle handle, System.RuntimeTypeHandle declaringType)
 {
     throw null;
 }
예제 #43
0
 public static bool operator ==(Type left, Type right)
 {
     return(RuntimeTypeHandle.GetValueInternal(left._typeHandle) == RuntimeTypeHandle.GetValueInternal(right._typeHandle));
 }
예제 #44
0
 public override bool IsInstanceOfType([NotNullWhen(true)] object?o) => RuntimeTypeHandle.IsInstanceOfType(this, o);
예제 #45
0
 public override Type GetElementType() => RuntimeTypeHandle.GetElementType(this);
예제 #46
0
 /// <summary>
 /// Gets the type referenced by the specified type handle.
 /// </summary>
 /// <param name="handle">The object that refers to the type.</param>
 /// <returns></returns>
 public static Type GetTypeFromHandle(RuntimeTypeHandle handle)
 {
     return(Type.GetTypeFromHandleImpl(handle));
 }
예제 #47
0
 public System.TypedReference GetNextArg(System.RuntimeTypeHandle rth)
 {
     throw new PlatformNotSupportedException(SR.PlatformNotSupported_ArgIterator); // https://github.com/dotnet/coreclr/issues/9204
 }
예제 #48
0
 public static IMapHandler Create(PropertyInfo propmeta)
 {
     System.RuntimeTypeHandle handle = propmeta.PropertyType.TypeHandle;
     if (handle.Equals(RTHString))
     {
         return(new MapHandler <T, String>(propmeta, (reader, index) => reader[index].ToString(), x => x));
     }
     else if (handle.Equals(RTHInt))
     {
         return(new MapHandler <T, Int32>(propmeta, (reader, index) => reader.GetInt32(index),
                                          x => { Int32 tmp; int.TryParse(x, out tmp); return tmp; }));
     }
     else if (handle.Equals(RTHIntNullable))
     {
         return(new MapHandler <T, Nullable <Int32> >(propmeta, (reader, index) => reader.IsDBNull(index) ? default(Nullable <Int32>) : reader.GetInt32(index),
                                                      x => { Int32 tmp; return int.TryParse(x, out tmp) ? tmp : default(Nullable <Int32>); }));
     }
     else if (handle.Equals(RTHDateTime))
     {
         return(new MapHandler <T, DateTime>(propmeta, (reader, index) => reader.GetDateTime(index),
                                             x => { DateTime tmp; DateTime.TryParse(x, out tmp); return tmp; }));
     }
     else if (handle.Equals(RTHDateTimeNullable))
     {
         return(new MapHandler <T, Nullable <DateTime> >(propmeta, (reader, index) => reader.IsDBNull(index) ? default(Nullable <DateTime>) : reader.GetDateTime(index),
                                                         x => { DateTime tmp; return DateTime.TryParse(x, out tmp) ? tmp : default(Nullable <DateTime>); }));
     }
     else if (handle.Equals(RTHGuid))
     {
         return(new MapHandler <T, Guid>(propmeta, (reader, index) => reader.GetGuid(index),
                                         x => { Guid tmp; Guid.TryParse(x, out tmp); return tmp; }));
     }
     else if (handle.Equals(RTHGuidNullable))
     {
         return(new MapHandler <T, Nullable <Guid> >(propmeta, (reader, index) => reader.IsDBNull(index) ? default(Nullable <Guid>) : reader.GetGuid(index),
                                                     x => { Guid tmp; return Guid.TryParse(x, out tmp) ? tmp : default(Nullable <Guid>); }));
     }
     else if (handle.Equals(RTHDouble))
     {
         return(new MapHandler <T, double>(propmeta, (reader, index) => reader.GetDouble(index),
                                           x => { double tmp; double.TryParse(x, out tmp); return tmp; }));
     }
     else if (handle.Equals(RTHDoubleNullable))
     {
         return(new MapHandler <T, Nullable <double> >(propmeta, (reader, index) => reader.IsDBNull(index) ? default(Nullable <double>) : reader.GetDouble(index),
                                                       x => { double tmp; return double.TryParse(x, out tmp) ? tmp : default(Nullable <double>); }));
     }
     else if (handle.Equals(RTHInt64))
     {
         return(new MapHandler <T, long>(propmeta, (reader, index) => reader.GetInt64(index),
                                         x => { long tmp; long.TryParse(x, out tmp); return tmp; }));
     }
     else if (handle.Equals(RTHInt64Nullable))
     {
         return(new MapHandler <T, Nullable <long> >(propmeta, (reader, index) => reader.IsDBNull(index) ? default(Nullable <long>) : reader.GetInt64(index),
                                                     x => { long tmp; return long.TryParse(x, out tmp) ? tmp : default(Nullable <long>); }));
     }
     else if (handle.Equals(RTHInt16))
     {
         return(new MapHandler <T, short>(propmeta, (reader, index) => reader.GetInt16(index),
                                          x => { short tmp; short.TryParse(x, out tmp); return tmp; }));
     }
     else if (handle.Equals(RTHInt16Nullable))
     {
         return(new MapHandler <T, Nullable <short> >(propmeta, (reader, index) => reader.IsDBNull(index) ? default(Nullable <short>) : reader.GetInt16(index),
                                                      x => { short tmp; return short.TryParse(x, out tmp) ? tmp : default(Nullable <short>); }));
     }
     else if (handle.Equals(RTHBool))
     {
         return(new MapHandler <T, bool>(propmeta, (reader, index) => reader.GetBoolean(index),
                                         x => { bool tmp; bool.TryParse(x, out tmp); return tmp; }));
     }
     else if (handle.Equals(RTHBoolNullable))
     {
         return(new MapHandler <T, Nullable <bool> >(propmeta, (reader, index) => reader.IsDBNull(index) ? default(Nullable <bool>) : reader.GetBoolean(index),
                                                     x => { bool tmp; return bool.TryParse(x, out tmp) ? tmp : default(Nullable <bool>); }));
     }
     else if (handle.Equals(RTHChar))
     {
         return(new MapHandler <T, char>(propmeta, (reader, index) => reader.GetChar(index),
                                         x => { char tmp; char.TryParse(x, out tmp); return tmp; }));
     }
     else if (handle.Equals(RTHCharNullable))
     {
         return(new MapHandler <T, Nullable <char> >(propmeta, (reader, index) => reader.IsDBNull(index) ? default(Nullable <char>) : reader.GetChar(index),
                                                     x => { char tmp; return char.TryParse(x, out tmp) ? tmp : default(Nullable <char>); }));
     }
     else if (handle.Equals(RTHBytes))
     {
         return(new MapHandler <T, byte[]>(propmeta, (reader, index) => reader.IsDBNull(index) ? default(byte[]) : (byte[])reader.GetValue(index),
                                           x => string.IsNullOrEmpty(x) ? default(byte[]) : System.Text.Encoding.UTF8.GetBytes(x)));
     }
     else if (propmeta.PropertyType.IsEnum)
     {
         return(new MapHandler <T>(propmeta));
     }
     else
     {
         return(new MapHandler(propmeta));
     }
 }
예제 #49
0
 private Type(RuntimeTypeHandle typeHandle)
 {
     _typeHandle = typeHandle;
 }
예제 #50
0
 public static Type GetTypeFromHandle(RuntimeTypeHandle rh)
 {
     return(new Type(rh));
 }
예제 #51
0
 public bool Equals(RuntimeTypeHandle handle)
 {
     return(value == handle.Value);
 }
예제 #52
0
 private static extern unsafe void InternalMakeTypedReference(void *result, object target, RuntimeFieldHandle[] flds, RuntimeTypeHandle lastFieldType);
예제 #53
0
 extern public TypedReference GetNextArg(RuntimeTypeHandle type);
예제 #54
0
 public MapHandler(PropertyInfo pmeta)
 {
     this.setvalueHandler = pmeta.SetValue;
     this.getvalueHandler = pmeta.GetValue;
     this.propertyRTH     = pmeta.PropertyType.TypeHandle;
 }
예제 #55
0
 protected override bool IsCOMObjectImpl() => RuntimeTypeHandle.IsComObject(this, false);
예제 #56
0
 public System.TypedReference GetNextArg(System.RuntimeTypeHandle rth)
 {
     throw new PlatformNotSupportedException(); //The JIT requires work to enable ArgIterator see: https://github.com/dotnet/coreclr/issues/9204.
 }
예제 #57
0
 internal QCallTypeHandle(ref System.RuntimeTypeHandle rth)
     : this(ref rth.m_type)
 {
 }
예제 #58
0
 protected override TypeAttributes GetAttributeFlagsImpl() => RuntimeTypeHandle.GetAttributes(this);
예제 #59
0
 protected override bool IsPointerImpl() => RuntimeTypeHandle.IsPointer(this);
예제 #60
0
 private static extern Type GetTypeFromHandleImpl(RuntimeTypeHandle handle);