本文整理汇总了C#中Mono.CodeGeneration.CodeExpression.Generate方法的典型用法代码示例。如果您正苦于以下问题:C# CodeExpression.Generate方法的具体用法?C# CodeExpression.Generate怎么用?C# CodeExpression.Generate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.CodeGeneration.CodeExpression
的用法示例。
在下文中一共展示了CodeExpression.Generate方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateSet
public override void GenerateSet(ILGenerator gen, CodeExpression value)
{
if (type.IsByRef) {
gen.Emit (OpCodes.Ldarg, argNum);
value.Generate (gen);
CodeGenerationHelper.GenerateSafeConversion (gen, type.GetElementType (), value.GetResultType ());
CodeGenerationHelper.SaveToPtr (gen, type.GetElementType ());
}
else {
value.Generate (gen);
CodeGenerationHelper.GenerateSafeConversion (gen, type, value.GetResultType ());
gen.Emit (OpCodes.Starg, argNum);
}
}
示例2: GenerateSet
public override void GenerateSet (ILGenerator gen, CodeExpression value)
{
if (field.IsStatic) {
value.Generate (gen);
CodeGenerationHelper.GenerateSafeConversion (gen, field.FieldType, value.GetResultType ());
gen.Emit (OpCodes.Stsfld, field);
}
else {
target.Generate (gen);
value.Generate (gen);
CodeGenerationHelper.GenerateSafeConversion (gen, field.FieldType, value.GetResultType ());
gen.Emit (OpCodes.Stfld, field);
}
}
示例3: GenerateMethodCall
static void GenerateMethodCall (ILGenerator gen, CodeExpression target, MethodBase method, Type[] parameterTypes, params CodeExpression[] parameters)
{
OpCode callOp;
if (parameterTypes.Length != parameters.Length)
throw GetMethodException (method, "Invalid number of parameters, expected " + parameterTypes.Length + ", found " + parameters.Length + ".");
if (!object.ReferenceEquals (target, null))
{
target.Generate (gen);
Type targetType = target.GetResultType();
if (targetType.IsValueType) {
LocalBuilder lb = gen.DeclareLocal (targetType);
gen.Emit (OpCodes.Stloc, lb);
gen.Emit (OpCodes.Ldloca, lb);
callOp = OpCodes.Call;
}
else
callOp = OpCodes.Callvirt;
}
else
callOp = OpCodes.Call;
for (int n=0; n<parameterTypes.Length; n++) {
try {
CodeExpression par = parameters[n];
par.Generate (gen);
GenerateSafeConversion (gen, parameterTypes[n], par.GetResultType());
}
catch (InvalidOperationException ex) {
throw GetMethodException (method, "Parameter " + n + ". " + ex.Message);
}
}
if (method is MethodInfo)
gen.Emit (callOp, (MethodInfo)method);
else if (method is ConstructorInfo)
gen.Emit (callOp, (ConstructorInfo)method);
}
示例4: GenerateSet
public override void GenerateSet (ILGenerator gen, CodeExpression value)
{
if (value == null)
throw new ArgumentNullException ("value");
Type t = array.GetResultType().GetElementType();
if (t.IsEnum && t != typeof(Enum)) t = t.UnderlyingSystemType;
array.Generate (gen);
index.Generate (gen);
switch (Type.GetTypeCode (t))
{
case TypeCode.Byte:
case TypeCode.SByte:
value.Generate (gen);
gen.Emit (OpCodes.Stelem_I1);
break;
case TypeCode.Double:
value.Generate (gen);
gen.Emit (OpCodes.Stelem_R8);
break;
case TypeCode.UInt16:
case TypeCode.Int16:
value.Generate (gen);
gen.Emit (OpCodes.Stelem_I2);
break;
case TypeCode.UInt32:
case TypeCode.Int32:
value.Generate (gen);
gen.Emit (OpCodes.Stelem_I4);
break;
case TypeCode.UInt64:
case TypeCode.Int64:
value.Generate (gen);
gen.Emit (OpCodes.Stelem_I8);
break;
case TypeCode.Single:
value.Generate (gen);
gen.Emit (OpCodes.Stelem_R4);
break;
default:
if (t.IsValueType) {
gen.Emit (OpCodes.Ldelema, t);
value.Generate (gen);
gen.Emit (OpCodes.Stobj, t);
}
else {
value.Generate (gen);
gen.Emit (OpCodes.Stelem_Ref);
}
break;
}
}
示例5: GenerateSet
public override void GenerateSet(ILGenerator gen, CodeExpression value)
{
value.Generate (gen);
CodeGenerationHelper.GenerateSafeConversion (gen, type, value.GetResultType ());
gen.Emit (OpCodes.Stloc, localBuilder);
}