当前位置: 首页>>代码示例>>C#>>正文


C# TypeDesc.ConvertToCanonForm方法代码示例

本文整理汇总了C#中Internal.TypeSystem.TypeDesc.ConvertToCanonForm方法的典型用法代码示例。如果您正苦于以下问题:C# TypeDesc.ConvertToCanonForm方法的具体用法?C# TypeDesc.ConvertToCanonForm怎么用?C# TypeDesc.ConvertToCanonForm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Internal.TypeSystem.TypeDesc的用法示例。


在下文中一共展示了TypeDesc.ConvertToCanonForm方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TryGetMetadataNativeLayout

        /// <summary>
        /// Get the NativeLayout for a type from a ReadyToRun image. 
        /// </summary>
        public bool TryGetMetadataNativeLayout(TypeDesc concreteType, out IntPtr nativeLayoutInfoModule, out uint nativeLayoutInfoToken)
        {
            nativeLayoutInfoModule = default(IntPtr);
            nativeLayoutInfoToken = 0;
#if SUPPORTS_NATIVE_METADATA_TYPE_LOADING
            var nativeMetadataType = concreteType.GetTypeDefinition() as TypeSystem.NativeFormat.NativeFormatType;
            if (nativeMetadataType == null)
                return false;

            var canonForm = concreteType.ConvertToCanonForm(CanonicalFormKind.Specific);
            var hashCode = canonForm.GetHashCode();

            var loadedModulesCount = RuntimeAugments.GetLoadedModules(null);
            var loadedModuleHandles = new IntPtr[loadedModulesCount];
            var loadedModules = RuntimeAugments.GetLoadedModules(loadedModuleHandles);
            Debug.Assert(loadedModulesCount == loadedModules);

#if SUPPORTS_R2R_LOADING
            foreach (var moduleHandle in loadedModuleHandles)
            {
                ExternalReferencesTable externalFixupsTable;
                NativeHashtable typeTemplatesHashtable = LoadHashtable(moduleHandle, ReflectionMapBlob.MetadataBasedTypeTemplateMap, out externalFixupsTable);

                if (typeTemplatesHashtable.IsNull)
                    continue;

                var enumerator = typeTemplatesHashtable.Lookup(hashCode);
                var nativeMetadataUnit = nativeMetadataType.Context.ResolveMetadataUnit(moduleHandle);

                NativeParser entryParser;
                while (!(entryParser = enumerator.GetNext()).IsNull)
                {
                    var entryTypeHandle = entryParser.GetUnsigned().AsHandle();
                    TypeDesc typeDesc = nativeMetadataUnit.GetType(entryTypeHandle);
                    Debug.Assert(typeDesc != null);
                    if (typeDesc == canonForm)
                    {
                        TypeLoaderLogger.WriteLine("Found metadata template for type " + concreteType.ToString() + ": " + typeDesc.ToString());
                        nativeLayoutInfoToken = (uint)externalFixupsTable.GetRvaFromIndex(entryParser.GetUnsigned());
                        if (nativeLayoutInfoToken == BadTokenFixupValue)
                        {
                            throw new BadImageFormatException();
                        }

                        nativeLayoutInfoModule = moduleHandle;
                        return true;
                    }
                }
            }
#endif
#endif

            return false;
        }
开发者ID:nattress,项目名称:corert,代码行数:57,代码来源:TemplateLocator.cs

示例2: ConvertToCanon

 /// <summary>
 /// Helper API to convert a type to its canonical or universal canonical form.
 /// Note that for now, there is no mixture between specific canonical and universal canonical forms,
 /// meaning that the canonical form or Foo<string, int> can either be Foo<__Canon, int> or
 /// Foo<__UniversalCanon, __UniversalCanon>. It cannot be Foo<__Canon, __UniversalCanon> (yet)
 /// for simplicity. We can always change that rule in the futue and add support for the mixture, but
 /// for now we are keeping it simple.
 /// </summary>
 public static TypeDesc ConvertToCanon(TypeDesc typeToConvert, CanonicalFormKind kind)
 {
     TypeSystemContext context = typeToConvert.Context;
     if (kind == CanonicalFormKind.Universal)
     {
         return context.UniversalCanonType;
     }
     else if (kind == CanonicalFormKind.Specific)
     {
         if (typeToConvert == context.UniversalCanonType)
         {
             return context.UniversalCanonType;
         }
         else if (typeToConvert.IsDefType)
         {
             if (!typeToConvert.IsValueType)
                 return context.CanonType;
             else if (typeToConvert.HasInstantiation)
                 return typeToConvert.ConvertToCanonForm(CanonicalFormKind.Specific);
             else
                 return typeToConvert;
         }
         else if (typeToConvert.IsArray)
         {
             return context.CanonType;
         }
         else
         {
             return typeToConvert.ConvertToCanonForm(CanonicalFormKind.Specific);
         }
     }
     else
     {
         Debug.Assert(false);
         return null;
     }
 }
开发者ID:shahid-pk,项目名称:corert,代码行数:45,代码来源:CanonUtilites.cs

示例3: ConvertToCanon

        public static TypeDesc ConvertToCanon(TypeDesc typeToConvert, ref CanonicalFormKind kind)
        {
            TypeSystemContext context = typeToConvert.Context;
            if (kind == CanonicalFormKind.Universal)
            {
                return context.UniversalCanonType;
            }
            else if (kind == CanonicalFormKind.Specific)
            {
                if (typeToConvert == context.UniversalCanonType)
                {
                    kind = CanonicalFormKind.Universal;
                    return context.UniversalCanonType;
                }
                else if (typeToConvert.IsSignatureVariable)
                {
                    return typeToConvert;
                }
                else if (typeToConvert.IsDefType)
                {
                    if (!typeToConvert.IsValueType)
                    {
                        return context.CanonType;
                    }
                    else if (typeToConvert.HasInstantiation)
                    {
                        TypeDesc canonicalType = typeToConvert.ConvertToCanonForm(CanonicalFormKind.Specific);

                        // This is a generic struct type. If the generic struct is instantiated over universal canon,
                        // the entire struct becomes universally canonical.
                        if (canonicalType.IsCanonicalSubtype(CanonicalFormKind.Universal))
                        {
                            kind = CanonicalFormKind.Universal;
                            return context.UniversalCanonType;
                        }

                        return canonicalType;
                    }
                    else if (typeToConvert.IsRuntimeDeterminedType)
                    {
                        // For non-universal canon cases, RuntimeDeterminedType's passed into this function are either
                        // reference types (which are turned into normal Canon), or instantiated types (which are handled 
                        // by the above case.). But for UniversalCanon, we can have non-instantiated universal canon
                        // which will reach this case.

                        // We should only ever reach this for T__UniversalCanon.
                        Debug.Assert(((RuntimeDeterminedType)typeToConvert).CanonicalType == context.UniversalCanonType);

                        kind = CanonicalFormKind.Universal;
                        return context.UniversalCanonType;
                    }
                    else
                    {
                        return typeToConvert;
                    }
                }
                else if (typeToConvert.IsArray)
                {
                    return context.CanonType;
                }
                else
                {
                    if (typeToConvert.IsCanonicalSubtype(CanonicalFormKind.Universal))
                    {
                        kind = CanonicalFormKind.Universal;
                        return context.UniversalCanonType;
                    }

                    return typeToConvert.ConvertToCanonForm(CanonicalFormKind.Specific);
                }
            }
            else
            {
                Debug.Assert(false);
                return null;
            }
        }
开发者ID:nattress,项目名称:corert,代码行数:77,代码来源:RuntimeDeterminedCanonicalizationAlgorithm.cs

示例4: TryGetTypeTemplate_Internal

        private TypeDesc TryGetTypeTemplate_Internal(TypeDesc concreteType, CanonicalFormKind kind, out IntPtr nativeLayoutInfoModule, out uint nativeLayoutInfoToken)
        {
            nativeLayoutInfoModule = default(IntPtr);
            nativeLayoutInfoToken = 0;
            var canonForm = concreteType.ConvertToCanonForm(kind);
            var hashCode = canonForm.GetHashCode();

            var loadedModulesCount = RuntimeAugments.GetLoadedModules(null);
            var loadedModuleHandles = new IntPtr[loadedModulesCount];
            var loadedModules = RuntimeAugments.GetLoadedModules(loadedModuleHandles);
            Debug.Assert(loadedModulesCount == loadedModules);

            foreach (var moduleHandle in loadedModuleHandles)
            {
                ExternalReferencesTable externalFixupsTable;
                NativeHashtable typeTemplatesHashtable = LoadHashtable(moduleHandle, ReflectionMapBlob.TypeTemplateMap, out externalFixupsTable);

                if (typeTemplatesHashtable.IsNull)
                    continue;

                var enumerator = typeTemplatesHashtable.Lookup(hashCode);

                NativeParser entryParser;
                while (!(entryParser = enumerator.GetNext()).IsNull)
                {
                    RuntimeTypeHandle candidateTemplateTypeHandle = externalFixupsTable.GetRuntimeTypeHandleFromIndex(entryParser.GetUnsigned());
                    TypeDesc candidateTemplate = concreteType.Context.ResolveRuntimeTypeHandle(candidateTemplateTypeHandle);

                    if (canonForm == candidateTemplate.ConvertToCanonForm(kind))
                    {
                        TypeLoaderLogger.WriteLine("Found template for type " + concreteType.ToString() + ": " + candidateTemplate.ToString());
                        nativeLayoutInfoToken = (uint)externalFixupsTable.GetRvaFromIndex(entryParser.GetUnsigned());
                        if (nativeLayoutInfoToken == BadTokenFixupValue)
                        {
                            // TODO: once multifile gets fixed up, make this throw a BadImageFormatException
                            TypeLoaderLogger.WriteLine("ERROR: template not fixed up, skipping");
                            continue;
                        }

                        Debug.Assert(
                            (kind != CanonicalFormKind.Universal && candidateTemplate != candidateTemplate.ConvertToCanonForm(kind)) ||
                            (kind == CanonicalFormKind.Universal && candidateTemplate == candidateTemplate.ConvertToCanonForm(kind)));

                        nativeLayoutInfoModule = moduleHandle;
                        return candidateTemplate;
                    }
                }
            }

            TypeLoaderLogger.WriteLine("ERROR: Cannot find a suitable template for type " + concreteType.ToString());
            return null;
        }
开发者ID:nattress,项目名称:corert,代码行数:52,代码来源:TemplateLocator.cs

示例5: ConvertToCanon

 private static TypeDesc ConvertToCanon(TypeDesc typeToConvert, ref CanonicalFormKind kind)
 {
     TypeSystemContext context = typeToConvert.Context;
     if (kind == CanonicalFormKind.Universal)
     {
         return context.UniversalCanonType;
     }
     else if (kind == CanonicalFormKind.Specific)
     {
         if (typeToConvert == context.UniversalCanonType)
         {
             kind = CanonicalFormKind.Universal;
             return context.UniversalCanonType;
         }
         else if (typeToConvert.IsSignatureVariable)
         {
             return typeToConvert;
         }
         else if (typeToConvert.IsDefType)
         {
             if (!typeToConvert.IsValueType)
                 return context.CanonType;
             else if (typeToConvert.HasInstantiation)
             {
                 TypeDesc convertedType = typeToConvert.ConvertToCanonForm(CanonicalFormKind.Specific);
                 if (convertedType.IsCanonicalSubtype(CanonicalFormKind.Universal))
                 {
                     kind = CanonicalFormKind.Universal;
                     return context.UniversalCanonType;
                 }
                 return convertedType;
             }
             else
                 return typeToConvert;
         }
         else if (typeToConvert.IsArray)
         {
             return context.CanonType;
         }
         else
         {
             TypeDesc convertedType = typeToConvert.ConvertToCanonForm(CanonicalFormKind.Specific);
             if (convertedType.IsCanonicalSubtype(CanonicalFormKind.Universal))
             {
                 kind = CanonicalFormKind.Universal;
                 return context.UniversalCanonType;
             }
             return convertedType;
         }
     }
     else
     {
         Debug.Assert(false);
         return null;
     }
 }
开发者ID:nattress,项目名称:corert,代码行数:56,代码来源:StandardCanonicalizationAlgorithm.cs


注:本文中的Internal.TypeSystem.TypeDesc.ConvertToCanonForm方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。