本文整理汇总了C#中Castle.DynamicProxy.Generators.Emitters.SimpleAST.Expression类的典型用法代码示例。如果您正苦于以下问题:C# Expression类的具体用法?C# Expression怎么用?C# Expression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Expression类属于Castle.DynamicProxy.Generators.Emitters.SimpleAST命名空间,在下文中一共展示了Expression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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;
}
示例3: GetCallbackMethodInvocation
public MethodInvocationExpression GetCallbackMethodInvocation(AbstractTypeEmitter invocation, Expression[] args,
Reference targetField,
MethodEmitter invokeMethodOnTarget)
{
var @delegate = GetDelegate(invocation, invokeMethodOnTarget);
return new MethodInvocationExpression(@delegate, GetCallbackMethod(), args);
}
示例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;
}
示例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;
}
示例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;
}
示例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)
};
}
示例8: ConvertExpression
public ConvertExpression(Type targetType, Type fromType, Expression right)
{
target = targetType;
this.fromType = fromType;
this.right = right;
}
示例9: AssignArgumentStatement
public AssignArgumentStatement(ArgumentReference argument, Expression expression)
{
this.argument = argument;
this.expression = expression;
}
示例10: AssignArrayStatement
public AssignArrayStatement(Reference targetArray, int targetPosition, Expression value)
{
this.targetArray = targetArray;
this.targetPosition = targetPosition;
this.value = value;
}
示例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(
//.........这里部分代码省略.........
示例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;
}
示例13: AssignStatement
public AssignStatement(Reference target, Expression expression)
{
this.target = target;
this.expression = expression;
}
示例14: AddExpression
public AbstractCodeBuilder AddExpression(Expression expression)
{
return AddStatement(new ExpressionStatement(expression));
}
示例15: AddExpression
public void AddExpression(Expression expression)
{
AddStatement(new ExpressionStatement(expression));
}