本文整理汇总了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();
}
示例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();
}
示例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");
}
示例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();
}