當前位置: 首頁>>代碼示例>>C#>>正文


C# TypeScope.GetTypeDesc方法代碼示例

本文整理匯總了C#中System.Xml.Serialization.TypeScope.GetTypeDesc方法的典型用法代碼示例。如果您正苦於以下問題:C# TypeScope.GetTypeDesc方法的具體用法?C# TypeScope.GetTypeDesc怎麽用?C# TypeScope.GetTypeDesc使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Xml.Serialization.TypeScope的用法示例。


在下文中一共展示了TypeScope.GetTypeDesc方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: WriteTypeInfo

        string WriteTypeInfo(TypeScope scope, TypeDesc typeDesc, Type type){
            InitTheFirstTime();
            string typeFullName = typeDesc.CSharpName;
            string typeVariable = (string)reflectionVariables[typeFullName];
            if (typeVariable != null)
                return typeVariable;

            if (type.IsArray)
            {
                typeVariable = GenerateVariableName("array", typeDesc.CSharpName);
                TypeDesc elementTypeDesc = typeDesc.ArrayElementTypeDesc;
                if (elementTypeDesc.UseReflection)
                {
                    string elementTypeVariable = WriteTypeInfo(scope, elementTypeDesc, scope.GetTypeFromTypeDesc(elementTypeDesc));
                    writer.WriteLine("static "+typeof(Type).FullName+" "+typeVariable +" = " + elementTypeVariable + ".MakeArrayType();");
                }
                else
                {
                    string assemblyVariable = WriteAssemblyInfo(type);
                    writer.Write("static "+typeof(Type).FullName+" "+typeVariable +" = "+assemblyVariable+".GetType(");
                    WriteQuotedCSharpString(type.FullName);
                    writer.WriteLine(");");
                }
            }
            else
            {
                typeVariable = GenerateVariableName("type", typeDesc.CSharpName);

                Type parameterType = Nullable.GetUnderlyingType(type);
                if (parameterType != null)
                {
                    string parameterTypeVariable = WriteTypeInfo(scope, scope.GetTypeDesc(parameterType), parameterType);
                    writer.WriteLine("static "+typeof(Type).FullName+" "+typeVariable +" = typeof(System.Nullable<>).MakeGenericType(new " + typeof(Type).FullName + "[] {"+parameterTypeVariable+"});");
                }
                else
                {
                    string assemblyVariable = WriteAssemblyInfo(type);
                    writer.Write("static "+typeof(Type).FullName+" "+typeVariable +" = "+assemblyVariable+".GetType(");
                    WriteQuotedCSharpString(type.FullName);
                    writer.WriteLine(");");
                }
            }
            
            reflectionVariables.Add(typeFullName, typeVariable);

            TypeMapping mapping = scope.GetTypeMappingFromTypeDesc(typeDesc);
            if (mapping != null)
                WriteMappingInfo(mapping, typeVariable, type);
            if (typeDesc.IsCollection || typeDesc.IsEnumerable){// Arrays use the generic item_Array
                TypeDesc elementTypeDesc = typeDesc.ArrayElementTypeDesc;
                if (elementTypeDesc.UseReflection)
                    WriteTypeInfo(scope, elementTypeDesc, scope.GetTypeFromTypeDesc(elementTypeDesc));
                WriteCollectionInfo(typeVariable, typeDesc, type);
            }
            return typeVariable;
        }
開發者ID:uQr,項目名稱:referencesource,代碼行數:56,代碼來源:XmlSerializationWriter.cs

示例2: WriteReflectionInit

 internal void WriteReflectionInit(TypeScope scope)
 {
     foreach (Type type in scope.Types)
     {
         TypeDesc typeDesc = scope.GetTypeDesc(type);
     }
 }
開發者ID:shiftkey-tester,項目名稱:corefx,代碼行數:7,代碼來源:XmlSerializationWriterILGen.cs

示例3: WriteReflectionInit

 internal void WriteReflectionInit(TypeScope scope){
     foreach (Type type in scope.Types) {
         TypeDesc typeDesc = scope.GetTypeDesc(type);
         if (typeDesc.UseReflection)
             WriteTypeInfo(scope, typeDesc, type);
     }
 }
開發者ID:uQr,項目名稱:referencesource,代碼行數:7,代碼來源:XmlSerializationWriter.cs

示例4: WriteTypeInfo

 private string WriteTypeInfo(TypeScope scope, TypeDesc typeDesc, Type type)
 {
     this.InitTheFirstTime();
     string cSharpName = typeDesc.CSharpName;
     string str2 = (string) this.reflectionVariables[cSharpName];
     if (str2 == null)
     {
         if (type.IsArray)
         {
             str2 = this.GenerateVariableName("array", typeDesc.CSharpName);
             TypeDesc arrayElementTypeDesc = typeDesc.ArrayElementTypeDesc;
             if (arrayElementTypeDesc.UseReflection)
             {
                 string str3 = this.WriteTypeInfo(scope, arrayElementTypeDesc, scope.GetTypeFromTypeDesc(arrayElementTypeDesc));
                 this.writer.WriteLine("static " + typeof(Type).FullName + " " + str2 + " = " + str3 + ".MakeArrayType();");
             }
             else
             {
                 string str4 = this.WriteAssemblyInfo(type);
                 this.writer.Write("static " + typeof(Type).FullName + " " + str2 + " = " + str4 + ".GetType(");
                 this.WriteQuotedCSharpString(type.FullName);
                 this.writer.WriteLine(");");
             }
         }
         else
         {
             str2 = this.GenerateVariableName("type", typeDesc.CSharpName);
             Type underlyingType = Nullable.GetUnderlyingType(type);
             if (underlyingType != null)
             {
                 string str5 = this.WriteTypeInfo(scope, scope.GetTypeDesc(underlyingType), underlyingType);
                 this.writer.WriteLine("static " + typeof(Type).FullName + " " + str2 + " = typeof(System.Nullable<>).MakeGenericType(new " + typeof(Type).FullName + "[] {" + str5 + "});");
             }
             else
             {
                 string str6 = this.WriteAssemblyInfo(type);
                 this.writer.Write("static " + typeof(Type).FullName + " " + str2 + " = " + str6 + ".GetType(");
                 this.WriteQuotedCSharpString(type.FullName);
                 this.writer.WriteLine(");");
             }
         }
         this.reflectionVariables.Add(cSharpName, str2);
         TypeMapping typeMappingFromTypeDesc = scope.GetTypeMappingFromTypeDesc(typeDesc);
         if (typeMappingFromTypeDesc != null)
         {
             this.WriteMappingInfo(typeMappingFromTypeDesc, str2, type);
         }
         if (typeDesc.IsCollection || typeDesc.IsEnumerable)
         {
             TypeDesc desc2 = typeDesc.ArrayElementTypeDesc;
             if (desc2.UseReflection)
             {
                 this.WriteTypeInfo(scope, desc2, scope.GetTypeFromTypeDesc(desc2));
             }
             this.WriteCollectionInfo(str2, typeDesc, type);
         }
     }
     return str2;
 }
開發者ID:pritesh-mandowara-sp,項目名稱:DecompliedDotNetLibraries,代碼行數:59,代碼來源:ReflectionAwareCodeGen.cs


注:本文中的System.Xml.Serialization.TypeScope.GetTypeDesc方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。