本文整理汇总了C#中CodeGenerator.Ldloca方法的典型用法代码示例。如果您正苦于以下问题:C# CodeGenerator.Ldloca方法的具体用法?C# CodeGenerator.Ldloca怎么用?C# CodeGenerator.Ldloca使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CodeGenerator
的用法示例。
在下文中一共展示了CodeGenerator.Ldloca方法的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: 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();
}
示例4: 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);
}