• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# SimpleAST.Expression类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Castle.DynamicProxy.Generators.Emitters.SimpleAST.Expression的典型用法代码示例。如果您正苦于以下问题:C# Expression类的具体用法?C# Expression怎么用?C# Expression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Expression类属于Castle.DynamicProxy.Generators.Emitters.SimpleAST命名空间,在下文中一共展示了Expression类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: GetCallbackMethodInvocation

		public MethodInvocationExpression GetCallbackMethodInvocation(AbstractTypeEmitter invocation, Expression[] args, Reference targetField, MethodEmitter invokeMethodOnTarget)
		{
			var allArgs = GetAllArgs(args, targetField);
			var @delegate = (Reference)invocation.GetField("delegate");

			return new MethodInvocationExpression(@delegate, GetCallbackMethod(), allArgs);
		}
开发者ID:vbedegi,项目名称:Castle.Core,代码行数:7,代码来源:InvocationWithDelegateContributor.cs


示例2: GetConstructorInvocationArguments

		public Expression[] GetConstructorInvocationArguments(Expression[] arguments, ClassEmitter proxy)
		{
			var allArguments = new Expression[arguments.Length + 1];
			allArguments[0] = new ReferenceExpression(BuildDelegateToken(proxy));
			Array.Copy(arguments, 0, allArguments, 1, arguments.Length);
			return allArguments;
		}
开发者ID:vbedegi,项目名称:Castle.Core,代码行数:7,代码来源:InvocationWithDelegateContributor.cs


示例3: GetCallbackMethodInvocation

		public MethodInvocationExpression GetCallbackMethodInvocation(AbstractTypeEmitter invocation, Expression[] args,
		                                                              Reference targetField,
		                                                              MethodEmitter invokeMethodOnTarget)
		{
			var @delegate = GetDelegate(invocation, invokeMethodOnTarget);
			return new MethodInvocationExpression(@delegate, GetCallbackMethod(), args);
		}
开发者ID:jeremymeng,项目名称:Core,代码行数:7,代码来源:InvocationWithGenericDelegateContributor.cs


示例4: ConvertArgumentReferenceToExpression

		public static Expression[] ConvertArgumentReferenceToExpression(ArgumentReference[] args)
		{
			var expressions = new Expression[args.Length];

			for (var i = 0; i < args.Length; ++i)
			{
				expressions[i] = args[i].ToExpression();
			}

			return expressions;
		}
开发者ID:gitter-badger,项目名称:MobileMoq,代码行数:11,代码来源:ArgumentsUtil.cs


示例5: BindDelegateExpression

		public BindDelegateExpression(Type @delegate, Expression owner, MethodInfo methodToBindTo, GenericTypeParameterBuilder[] genericTypeParams)
		{
			delegateCtor = @delegate.GetConstructors()[0];
			this.methodToBindTo = methodToBindTo;
			if(@delegate.IsGenericTypeDefinition)
			{
				var closedDelegate = @delegate.MakeGenericType(genericTypeParams);
				delegateCtor = TypeBuilder.GetConstructor(closedDelegate, delegateCtor);
				this.methodToBindTo = methodToBindTo.MakeGenericMethod(genericTypeParams);
			}
			this.owner = owner;
		}
开发者ID:vbedegi,项目名称:Castle.Core,代码行数:12,代码来源:BindDelegateExpression.cs


示例6: NullCoalescingOperatorExpression

        public NullCoalescingOperatorExpression(Expression expression, Expression @default)
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }

            if (@default == null)
            {
                throw new ArgumentNullException("default");
            }

            this.expression = expression;
            [email protected] = @default;
        }
开发者ID:brianmatic,项目名称:n2cms,代码行数:15,代码来源:NullCoalescingOperatorExpression.cs


示例7: GetCtorArguments

		private Expression[] GetCtorArguments(ClassEmitter @class, Expression proxiedMethodTokenExpression, TypeReference[] dereferencedArguments, Expression methodInterceptors)
		{
			return new[]
			{
				getTargetExpression(@class, MethodToOverride),
				SelfReference.Self.ToExpression(),
				methodInterceptors ?? interceptors.ToExpression(),
				proxiedMethodTokenExpression,
				new ReferencesToObjectArrayExpression(dereferencedArguments)
			};
		}
开发者ID:jeremymeng,项目名称:Core,代码行数:11,代码来源:MethodWithInvocationGenerator.cs


示例8: ConvertExpression

		public ConvertExpression(Type targetType, Type fromType, Expression right)
		{
			target = targetType;
			this.fromType = fromType;
			this.right = right;
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:6,代码来源:ConvertExpression.cs


示例9: AssignArgumentStatement

 public AssignArgumentStatement(ArgumentReference argument, Expression expression)
 {
     this.argument = argument;
     this.expression = expression;
 }
开发者ID:brianmatic,项目名称:n2cms,代码行数:5,代码来源:AssignArgumentStatement.cs


示例10: AssignArrayStatement

		public AssignArrayStatement(Reference targetArray, int targetPosition, Expression value)
		{
			this.targetArray = targetArray;
			this.targetPosition = targetPosition;
			this.value = value;
		}
开发者ID:ralescano,项目名称:castle,代码行数:6,代码来源:AssignArrayStatement.cs


示例11: CreateIInvocationInvokeOnTarget

		protected void CreateIInvocationInvokeOnTarget(
			ClassEmitter targetTypeEmitter,
			NestedClassEmitter nested,
			ParameterInfo[] parameters,
			FieldReference targetField,
			MethodInfo callbackMethod)
		{
			const MethodAttributes methodAtts = MethodAttributes.Public | MethodAttributes.Final | MethodAttributes.Virtual;

			MethodEmitter method =
				nested.CreateMethod ("InvokeMethodOnTarget", methodAtts, typeof (void));

			Expression[] args = new Expression[parameters.Length];

			// Idea: instead of grab parameters one by one
			// we should grab an array
			Hashtable byRefArguments = new Hashtable();

			for(int i = 0; i < parameters.Length; i++)
			{
				ParameterInfo param = parameters[i];

				Type paramType = param.ParameterType;

				if (HasGenericParameters(paramType))
				{
					paramType = paramType.GetGenericTypeDefinition().MakeGenericType(nested.GetGenericArgumentsFor(paramType));
				}
				else if (paramType.IsGenericParameter)
				{
					paramType = nested.GetGenericArgument(paramType.Name);
				}

				if (paramType.IsByRef)
				{
					LocalReference localReference = method.CodeBuilder.DeclareLocal(paramType.GetElementType());
					method.CodeBuilder.AddStatement(
						new AssignStatement(localReference,
						                    new ConvertExpression(paramType.GetElementType(),
						                                          new MethodInvocationExpression(SelfReference.Self,
						                                                                         typeof(AbstractInvocation).GetMethod(
						                                                                         	"GetArgumentValue"),
						                                                                         new LiteralIntExpression(i)))));
					ByRefReference byRefReference = new ByRefReference(localReference);
					args[i] = new ReferenceExpression(byRefReference);
					byRefArguments[i] = localReference;
				}
				else
				{
					args[i] =
						new ConvertExpression(paramType,
						                      new MethodInvocationExpression(SelfReference.Self,
						                                                     typeof(AbstractInvocation).GetMethod("GetArgumentValue"),
						                                                     new LiteralIntExpression(i)));
				}
			}

			MethodInvocationExpression baseMethodInvExp;

			if (callbackMethod.IsGenericMethod)
			{
				callbackMethod = callbackMethod.MakeGenericMethod(nested.GetGenericArgumentsFor(callbackMethod));
			}

			baseMethodInvExp = new MethodInvocationExpression(targetField, callbackMethod, args);
			baseMethodInvExp.VirtualCall = true;

			LocalReference ret_local = null;

			if (callbackMethod.ReturnType != typeof(void))
			{
				if (callbackMethod.ReturnType.IsGenericParameter)
				{
					ret_local = method.CodeBuilder.DeclareLocal(nested.GetGenericArgument(callbackMethod.ReturnType.Name));
				}
				else if (HasGenericParameters(callbackMethod.ReturnType))
				{
					ret_local =
						method.CodeBuilder.DeclareLocal(
							callbackMethod.ReturnType.GetGenericTypeDefinition().MakeGenericType(
								nested.GetGenericArgumentsFor(callbackMethod.ReturnType)));
				}
				else
				{
					ret_local = method.CodeBuilder.DeclareLocal(callbackMethod.ReturnType);
				}

				method.CodeBuilder.AddStatement(new AssignStatement(ret_local, baseMethodInvExp));
			}
			else
			{
				method.CodeBuilder.AddStatement(new ExpressionStatement(baseMethodInvExp));
			}

			foreach(DictionaryEntry byRefArgument in byRefArguments)
			{
				int index = (int) byRefArgument.Key;
				LocalReference localReference = (LocalReference) byRefArgument.Value;
				method.CodeBuilder.AddStatement(
					new ExpressionStatement(
//.........这里部分代码省略.........
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:101,代码来源:BaseProxyGenerator.cs


示例12: CreateCallbackMethod

		private MethodBuilder CreateCallbackMethod(ClassEmitter emitter, MethodInfo methodInfo, MethodInfo methodOnTarget)
		{
			var targetMethod = methodOnTarget ?? methodInfo;
			var callBackMethod = emitter.CreateMethod(namingScope.GetUniqueName(methodInfo.Name + "_callback"), targetMethod);

			if (targetMethod.IsGenericMethod)
				targetMethod = targetMethod.MakeGenericMethod(callBackMethod.GenericTypeParams);

			var exps = new Expression[callBackMethod.Arguments.Length];
			for (var i = 0; i < callBackMethod.Arguments.Length; i++)
			{
				exps[i] = callBackMethod.Arguments[i].ToExpression();
			}

			// invocation on base class

			callBackMethod.CodeBuilder.AddStatement(
				new ReturnStatement(
					new MethodInvocationExpression(SelfReference.Self,
					                               targetMethod,
					                               exps)));

			return callBackMethod.MethodBuilder;
		}
开发者ID:n2cms,项目名称:Castle.Core,代码行数:24,代码来源:ClassProxyTargetContributor.cs


示例13: AssignStatement

 public AssignStatement(Reference target, Expression expression)
 {
     this.target = target;
     this.expression = expression;
 }
开发者ID:brianmatic,项目名称:n2cms,代码行数:5,代码来源:AssignStatement.cs


示例14: AddExpression

		public AbstractCodeBuilder AddExpression(Expression expression)
		{
			return AddStatement(new ExpressionStatement(expression));
		}
开发者ID:leloulight,项目名称:Core,代码行数:4,代码来源:AbstractCodeBuilder.cs


示例15: AddExpression

		public void AddExpression(Expression expression)
		{
			AddStatement(new ExpressionStatement(expression));
		}
开发者ID:gitter-badger,项目名称:MobileMoq,代码行数:4,代码来源:MultiStatementExpression.cs


示例16: ModifyArguments

		private Expression[] ModifyArguments(ClassEmitter @class, Expression[] arguments)
		{
			if (contributor == null)
			{
				return arguments;
			}

			return contributor.GetConstructorInvocationArguments(arguments, @class);
		}
开发者ID:AndreKraemer,项目名称:Castle.Core,代码行数:9,代码来源:MethodWithInvocationGenerator.cs


示例17: GetAllArgs

		private Expression[] GetAllArgs(Expression[] args, Reference targetField)
		{
			var allArgs = new Expression[args.Length + 1];
			args.CopyTo(allArgs, 1);
			allArgs[0] = new ConvertExpression(targetType, targetField.ToExpression());
			return allArgs;
		}
开发者ID:vbedegi,项目名称:Castle.Core,代码行数:7,代码来源:InvocationWithDelegateContributor.cs


示例18: SetMethodInterceptors

		private Expression SetMethodInterceptors(ClassEmitter @class, INamingScope namingScope, MethodEmitter emitter, Expression proxiedMethodTokenExpression)
		{
			var selector = @class.GetField("__selector");
			if(selector == null)
			{
				return null;
			}

			var methodInterceptorsField = BuildMethodInterceptorsField(@class, MethodToOverride, namingScope);

			var emptyInterceptors = new NewArrayExpression(0, typeof(IInterceptor));
			var selectInterceptors = new MethodInvocationExpression(selector, InterceptorSelectorMethods.SelectInterceptors,
			                                                        new MethodInvocationExpression(null,
				                                                        TypeUtilMethods.GetTypeOrNull,
				                                                        getTargetExpression(@class, MethodToOverride)),
			                                                        proxiedMethodTokenExpression, interceptors.ToExpression())
			{ VirtualCall = true };

			emitter.CodeBuilder.AddExpression(
				new IfNullExpression(methodInterceptorsField,
				                     new AssignStatement(methodInterceptorsField,
				                                         new NullCoalescingOperatorExpression(selectInterceptors, emptyInterceptors))));

			return methodInterceptorsField.ToExpression();
		}
开发者ID:jeremymeng,项目名称:Core,代码行数:25,代码来源:MethodWithInvocationGenerator.cs


示例19: GetCtorArguments

		private Expression[] GetCtorArguments(ClassEmitter @class, INamingScope namingScope, Expression proxiedMethodTokenExpression, TypeReference[] dereferencedArguments)
		{
			var selector = @class.GetField("__selector");
			if (selector != null)
			{
				return new[]
				{
					getTargetExpression(@class, MethodToOverride),
					SelfReference.Self.ToExpression(),
					interceptors.ToExpression(),
					proxiedMethodTokenExpression,
					new ReferencesToObjectArrayExpression(dereferencedArguments),
					selector.ToExpression(),
					new AddressOfReferenceExpression(BuildMethodInterceptorsField(@class, MethodToOverride, namingScope))
				};
			}
			return new[]
			{
				getTargetExpression(@class, MethodToOverride),
				SelfReference.Self.ToExpression(),
				interceptors.ToExpression(),
				proxiedMethodTokenExpression,
				new ReferencesToObjectArrayExpression(dereferencedArguments)
			};
		}
开发者ID:JulianBirch,项目名称:Castle.Core,代码行数:25,代码来源:MethodWithInvocationGenerator.cs


示例20: CreateCallbackMethod

		protected MethodBuilder CreateCallbackMethod(ClassEmitter emitter, MethodInfo methodInfo, MethodInfo methodOnTarget)
		{
			MethodInfo targetMethod = methodOnTarget != null ? methodOnTarget : methodInfo;

			if (targetMethod.IsAbstract)
				return null;

			// MethodBuild creation

			MethodAttributes atts = MethodAttributes.Family;

			String name = methodInfo.Name + "_callback_" + ++callbackCounter;

			MethodEmitter callBackMethod = emitter.CreateMethod(name, atts);

			callBackMethod.CopyParametersAndReturnTypeFrom(targetMethod, emitter);

			// Generic definition

			if (targetMethod.IsGenericMethod)
			{
				targetMethod = targetMethod.MakeGenericMethod(callBackMethod.GenericTypeParams);
			}

			// Parameters exp

			Expression[] exps = new Expression[callBackMethod.Arguments.Length];

			for(int i = 0; i < callBackMethod.Arguments.Length; i++)
			{
				exps[i] = callBackMethod.Arguments[i].ToExpression();
			}

			// invocation on base class

			callBackMethod.CodeBuilder.AddStatement(
				new ReturnStatement(new MethodInvocationExpression(GetProxyTargetReference(), targetMethod, exps)));

			return callBackMethod.MethodBuilder;
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:40,代码来源:BaseProxyGenerator.cs



注:本文中的Castle.DynamicProxy.Generators.Emitters.SimpleAST.Expression类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Interceptors.KeepDataInterceptor类代码示例发布时间:2022-05-24
下一篇:
C# SimpleAST.ArgumentReference类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap