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


C# CodeGenerator.InitObj方法代码示例

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


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

示例1: GenerateCreateXmlSerializableDelegate

 internal System.Runtime.Serialization.CreateXmlSerializableDelegate GenerateCreateXmlSerializableDelegate()
 {
     Type underlyingType = base.UnderlyingType;
     CodeGenerator generator = new CodeGenerator();
     bool allowPrivateMemberAccess = this.RequiresMemberAccessForCreate(null);
     try
     {
         generator.BeginMethod("Create" + DataContract.GetClrTypeFullName(underlyingType), typeof(System.Runtime.Serialization.CreateXmlSerializableDelegate), allowPrivateMemberAccess);
     }
     catch (SecurityException exception)
     {
         if (!allowPrivateMemberAccess || !exception.PermissionType.Equals(typeof(ReflectionPermission)))
         {
             throw;
         }
         this.RequiresMemberAccessForCreate(exception);
     }
     if (underlyingType.IsValueType)
     {
         LocalBuilder localBuilder = generator.DeclareLocal(underlyingType, underlyingType.Name + "Value");
         generator.Ldloca(localBuilder);
         generator.InitObj(underlyingType);
         generator.Ldloc(localBuilder);
     }
     else
     {
         generator.New(this.GetConstructor());
     }
     generator.ConvertValue(base.UnderlyingType, Globals.TypeOfIXmlSerializable);
     generator.Ret();
     return (System.Runtime.Serialization.CreateXmlSerializableDelegate) generator.EndMethod();
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:32,代码来源:XmlDataContract.cs

示例2: GenerateCreateXmlSerializableDelegate

 internal CreateXmlSerializableDelegate GenerateCreateXmlSerializableDelegate()
 {
     Type type = this.UnderlyingType;
     CodeGenerator ilg = new CodeGenerator();
     bool memberAccessFlag = RequiresMemberAccessForCreate(null) && !(type.FullName == "System.Xml.Linq.XElement");
     try
     {
         ilg.BeginMethod("Create" + DataContract.GetClrTypeFullName(type), typeof(CreateXmlSerializableDelegate), memberAccessFlag);
     }
     catch (SecurityException securityException)
     {
         if (memberAccessFlag)
         {
             RequiresMemberAccessForCreate(securityException);
         }
         else
         {
             throw;
         }
     }
     if (type.GetTypeInfo().IsValueType)
     {
         System.Reflection.Emit.LocalBuilder local = ilg.DeclareLocal(type, type.Name + "Value");
         ilg.Ldloca(local);
         ilg.InitObj(type);
         ilg.Ldloc(local);
     }
     else
     {
         // Special case XElement
         // codegen the same as 'internal XElement : this("default") { }'
         ConstructorInfo ctor = GetConstructor();
         if (!ctor.IsPublic && type.FullName == "System.Xml.Linq.XElement")
         {
             Type xName = type.GetTypeInfo().Assembly.GetType("System.Xml.Linq.XName");
             if (xName != null)
             {
                 MethodInfo XName_op_Implicit = xName.GetMethod(
                     "op_Implicit",
                     BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public,
                     new Type[] { typeof(String) }
                     );
                 ConstructorInfo XElement_ctor = type.GetConstructor(
                     BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public,
                     new Type[] { xName }
                     );
                 if (XName_op_Implicit != null && XElement_ctor != null)
                 {
                     ilg.Ldstr("default");
                     ilg.Call(XName_op_Implicit);
                     ctor = XElement_ctor;
                 }
             }
         }
         ilg.New(ctor);
     }
     ilg.ConvertValue(this.UnderlyingType, Globals.TypeOfIXmlSerializable);
     ilg.Ret();
     return (CreateXmlSerializableDelegate)ilg.EndMethod();
 }
开发者ID:ChuangYang,项目名称:corefx,代码行数:60,代码来源:XmlDataContract.cs

示例3: GenerateCreateXmlSerializableDelegate

 internal CreateXmlSerializableDelegate GenerateCreateXmlSerializableDelegate()
 {
     Type type = this.UnderlyingType;
     CodeGenerator ilg = new CodeGenerator();
     bool memberAccessFlag = RequiresMemberAccessForCreate(null);
     try
     {
         ilg.BeginMethod("Create" + DataContract.GetClrTypeFullName(type), typeof(CreateXmlSerializableDelegate), memberAccessFlag);
     }
     catch (SecurityException securityException)
     {
         if (memberAccessFlag && securityException.PermissionType.Equals(typeof(ReflectionPermission)))
         {
             RequiresMemberAccessForCreate(securityException);
         }
         else
         {
             throw;
         }
     }
     if (type.IsValueType)
     {
         System.Reflection.Emit.LocalBuilder local = ilg.DeclareLocal(type, type.Name + "Value");
         ilg.Ldloca(local);
         ilg.InitObj(type);
         ilg.Ldloc(local);
     }
     else
     {
         ilg.New(GetConstructor());
     }
     ilg.ConvertValue(this.UnderlyingType, Globals.TypeOfIXmlSerializable);
     ilg.Ret();
     return (CreateXmlSerializableDelegate)ilg.EndMethod();
 }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:35,代码来源:XmlDataContract.cs

示例4: WriteNullableMethod

        void WriteNullableMethod(NullableMapping nullableMapping) {
            string methodName = (string)MethodNames[nullableMapping];
            ilg = new CodeGenerator(this.typeBuilder);
            ilg.BeginMethod(
                nullableMapping.TypeDesc.Type,
                GetMethodBuilder(methodName),
                new Type[] { typeof(Boolean) },
                new string[] { "checkType" },
                CodeGenerator.PrivateMethodAttributes);

            LocalBuilder oLoc = ilg.DeclareLocal(nullableMapping.TypeDesc.Type, "o");

            ilg.LoadAddress(oLoc);
            ilg.InitObj(nullableMapping.TypeDesc.Type);
            MethodInfo XmlSerializationReader_ReadNull = typeof(XmlSerializationReader).GetMethod(
                "ReadNull",
                CodeGenerator.InstanceBindingFlags,
                null,
                CodeGenerator.EmptyTypeArray,
                null);
            ilg.Ldarg(0);
            ilg.Call(XmlSerializationReader_ReadNull);
            ilg.If();
            {
                ilg.Ldloc(oLoc);
                ilg.Stloc(ilg.ReturnLocal);
                ilg.Br(ilg.ReturnLabel);
            }
            ilg.EndIf();

            ElementAccessor element = new ElementAccessor();
            element.Mapping = nullableMapping.BaseMapping;
            element.Any = false;
            element.IsNullable = nullableMapping.BaseMapping.TypeDesc.IsNullable;

            WriteElement("o", null, null, element, null, null, false, false, -1, -1);
            ilg.Ldloc(oLoc);
            ilg.Stloc(ilg.ReturnLocal);
            ilg.Br(ilg.ReturnLabel);

            ilg.MarkLabel(ilg.ReturnLabel);
            ilg.Ldloc(ilg.ReturnLocal);
            ilg.EndMethod();
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:44,代码来源:XmlSerializationReaderILGen.cs

示例5: ILGenForCreateInstance

 internal void ILGenForCreateInstance(CodeGenerator ilg, Type type, bool ctorInaccessible, bool cast)
 {
     if (!ctorInaccessible)
     {
         ConstructorInfo ctor = type.GetConstructor(
                CodeGenerator.InstanceBindingFlags,
                Array.Empty<Type>()
                );
         if (ctor != null)
             ilg.New(ctor);
         else
         {
             Debug.Assert(type.GetTypeInfo().IsValueType);
             LocalBuilder tmpLoc = ilg.GetTempLocal(type);
             ilg.Ldloca(tmpLoc);
             ilg.InitObj(type);
             ilg.Ldloc(tmpLoc);
         }
         return;
     }
     ILGenForCreateInstance(ilg, type, cast ? type : null, ctorInaccessible);
 }
开发者ID:shiftkey-tester,项目名称:corefx,代码行数:22,代码来源:XmlSerializationWriterILGen.cs


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