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


C# CodeExpression.Generate方法代码示例

本文整理汇总了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);
     }
 }
开发者ID:yudhitech,项目名称:xamarin-android,代码行数:14,代码来源:CodeArgumentReference.cs

示例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);
			}
		}
开发者ID:nlhepler,项目名称:mono,代码行数:14,代码来源:CodeFieldReference.cs

示例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);
		}
开发者ID:nickchal,项目名称:pash,代码行数:40,代码来源:CodeGenerationHelper.cs

示例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;
			}				
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:59,代码来源:CodeArrayItem.cs

示例5: GenerateSet

 public override void GenerateSet(ILGenerator gen, CodeExpression value)
 {
     value.Generate (gen);
     CodeGenerationHelper.GenerateSafeConversion (gen, type, value.GetResultType ());
     gen.Emit (OpCodes.Stloc, localBuilder);
 }
开发者ID:yudhitech,项目名称:xamarin-android,代码行数:6,代码来源:CodeVariableReference.cs


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