當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。