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


C# CodeGenerator.Ret方法代码示例

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


在下文中一共展示了CodeGenerator.Ret方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: TestEmitInterface

            public static void TestEmitInterface()
            {
                AssemblyName assName = new AssemblyName("TestEmitInterface");
                AssemblyBuilder assBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(assName, AssemblyBuilderAccess.Run);
                ModuleBuilder modBuilder = assBuilder.DefineDynamicModule(assBuilder.GetName().Name);
                TypeBuilder typeBuilder = modBuilder.DefineType("TestEmitInterface.TestImpl", TypeAttributes.Public);
                typeBuilder.AddInterfaceImplementation(typeof(ITest));

                CodeGenerator ctor = new CodeGenerator(typeBuilder, "ctor", MethodAttributes.Public, CallingConventions.Standard, null, Type.EmptyTypes);
                ctor.Ldarg(0);
                ctor.Call(typeof(object).GetConstructor(Type.EmptyTypes));
                ctor.Ret();

                MethodInfo mi = typeof(ITest).GetMethod("Wow");

                CodeGenerator wow = new CodeGenerator(typeBuilder, mi.Name, mi.Attributes & (~MethodAttributes.Abstract) | MethodAttributes.Public, mi.CallingConvention, mi.ReturnType, new Type[] { typeof(string) });
                wow.Ldarg(1);
                wow.Ret();

                typeBuilder.DefineMethodOverride(wow.CurrentMethod, mi);

                Type testImplType = typeBuilder.CreateType();
                ITest test = (ITest)Activator.CreateInstance(testImplType);
                Check.Assert(test.Wow("hello") == "hello");
            }
开发者ID:Oman,项目名称:Maleos,代码行数:25,代码来源:CodeGenerator.cs

示例4: 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


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