本文整理汇总了C#中System.Runtime.CompilerServices.CallSiteBinder类的典型用法代码示例。如果您正苦于以下问题:C# CallSiteBinder类的具体用法?C# CallSiteBinder怎么用?C# CallSiteBinder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CallSiteBinder类属于System.Runtime.CompilerServices命名空间,在下文中一共展示了CallSiteBinder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Make
internal static DynamicExpression Make(Type returnType, Type delegateType, CallSiteBinder binder, Expression arg0, Expression arg1, Expression arg2, Expression arg3) {
if (returnType == typeof(object)) {
return new DynamicExpression4(delegateType, binder, arg0, arg1, arg2, arg3);
} else {
return new TypedDynamicExpression4(returnType, delegateType, binder, arg0, arg1, arg2, arg3);
}
}
示例2: Create
public static CallSite Create(Type delegateType, CallSiteBinder binder)
{
Func<CallSiteBinder, CallSite> func;
ContractUtils.RequiresNotNull(delegateType, "delegateType");
ContractUtils.RequiresNotNull(binder, "binder");
if (!delegateType.IsSubclassOf(typeof(Delegate)))
{
throw Error.TypeMustBeDerivedFromSystemDelegate();
}
if (_SiteCtors == null)
{
_SiteCtors = new CacheDict<Type, Func<CallSiteBinder, CallSite>>(100);
}
MethodInfo method = null;
CacheDict<Type, Func<CallSiteBinder, CallSite>> dict = _SiteCtors;
lock (dict)
{
if (!dict.TryGetValue(delegateType, out func))
{
method = typeof(CallSite<>).MakeGenericType(new Type[] { delegateType }).GetMethod("Create");
if (delegateType.CanCache())
{
func = (Func<CallSiteBinder, CallSite>) Delegate.CreateDelegate(typeof(Func<CallSiteBinder, CallSite>), method);
dict.Add(delegateType, func);
}
}
}
if (func != null)
{
return func(binder);
}
return (CallSite) method.Invoke(null, new object[] { binder });
}
示例3: DynamicExpression4
internal DynamicExpression4(Type delegateType, CallSiteBinder binder, Expression arg0, Expression arg1, Expression arg2, Expression arg3) : base(delegateType, binder)
{
this._arg0 = arg0;
this._arg1 = arg1;
this._arg2 = arg2;
this._arg3 = arg3;
}
示例4: ReduceDynamic
/// <summary>
/// Reduces the dynamic expression to a binder and a set of arguments to apply the operation to.
/// </summary>
/// <param name="binder">The binder used to perform the dynamic operation.</param>
/// <param name="arguments">The arguments to apply the dynamic operation to.</param>
/// <param name="argumentTypes">The types of the arguments to use for the dynamic call site. Return null to infer types.</param>
protected override void ReduceDynamic(out CallSiteBinder binder, out IEnumerable<Expression> arguments, out Type[] argumentTypes)
{
var nodeType = OperationNodeType;
switch (nodeType)
{
case ExpressionType.AddChecked:
nodeType = ExpressionType.Add;
break;
case ExpressionType.MultiplyChecked:
nodeType = ExpressionType.Multiply;
break;
case ExpressionType.SubtractChecked:
nodeType = ExpressionType.Subtract;
break;
case ExpressionType.AndAlso:
nodeType = ExpressionType.And;
break;
case ExpressionType.OrElse:
nodeType = ExpressionType.Or;
break;
}
binder = Binder.BinaryOperation(Flags, nodeType, Context, new[] { Left.ArgumentInfo, Right.ArgumentInfo });
arguments = new[] { Left.Expression, Right.Expression };
argumentTypes = null;
}
示例5: Create
/// <summary>
/// Creates a CallSite with the given delegate type and binder.
/// </summary>
/// <param name="delegateType">The CallSite delegate type.</param>
/// <param name="binder">The CallSite binder.</param>
/// <returns>The new CallSite.</returns>
public static CallSite Create(Type delegateType, CallSiteBinder binder)
{
ContractUtils.RequiresNotNull(delegateType, "delegateType");
ContractUtils.RequiresNotNull(binder, "binder");
if (!delegateType.IsSubclassOf(typeof(MulticastDelegate))) throw Error.TypeMustBeDerivedFromSystemDelegate();
var ctors = s_siteCtors;
if (ctors == null) {
// It's okay to just set this, worst case we're just throwing away some data
s_siteCtors = ctors = new CacheDict<Type, Func<CallSiteBinder, CallSite>>(100);
}
Func<CallSiteBinder, CallSite> ctor;
MethodInfo method = null;
if (!ctors.TryGetValue(delegateType, out ctor))
{
method = typeof(CallSite<>).MakeGenericType(delegateType).GetMethod("Create");
if (TypeUtils.CanCache(delegateType))
{
ctor = (Func<CallSiteBinder, CallSite>)method.CreateDelegate(typeof(Func<CallSiteBinder, CallSite>));
ctors.Add(delegateType, ctor);
}
}
if (ctor != null)
{
return ctor(binder);
}
// slow path
return (CallSite)method.Invoke(null, new object[] { binder });
}
示例6: Make
internal static DynamicExpression Make(System.Type returnType, System.Type delegateType, CallSiteBinder binder, Expression arg0, Expression arg1, Expression arg2)
{
if (returnType == typeof(object))
{
return new DynamicExpression3(delegateType, binder, arg0, arg1, arg2);
}
return new TypedDynamicExpression3(returnType, delegateType, binder, arg0, arg1, arg2);
}
示例7: RewriteStrongBoxAsRef
internal static DynamicMetaObject RewriteStrongBoxAsRef(CallSiteBinder action, DynamicMetaObject target, DynamicMetaObject[] args, bool hasRhs) {
Debug.Assert(action != null && target != null && args != null);
var restrictions = target.Restrictions.Merge(BindingRestrictions.Combine(args));
Expression[] argExpressions = new Expression[args.Length + 1];
Type[] signatureTypes = new Type[args.Length + 3]; // args + CallSite, target, returnType
signatureTypes[0] = typeof(CallSite);
//we are not restricting on target type here.
argExpressions[0] = target.Expression;
signatureTypes[1] = target.Expression.Type;
int argsToProcess = args.Length;
if (hasRhs) {
DynamicMetaObject rhsArgument = args[args.Length - 1];
argExpressions[args.Length] = rhsArgument.Expression;
signatureTypes[args.Length + 1] = rhsArgument.Expression.Type;
argsToProcess--;
}
for (int i = 0; i < argsToProcess; i++) {
DynamicMetaObject currArgument = args[i];
if (IsStrongBoxArg(currArgument)) {
restrictions = restrictions.Merge(BindingRestrictions.GetTypeRestriction(currArgument.Expression, currArgument.LimitType));
// we have restricted this argument to LimitType so we can convert and conversion will be trivial cast.
Expression boxedValueAccessor = Expression.Field(
Helpers.Convert(
currArgument.Expression,
currArgument.LimitType
),
currArgument.LimitType.GetField("Value")
);
argExpressions[i + 1] = boxedValueAccessor;
signatureTypes[i + 2] = boxedValueAccessor.Type.MakeByRefType();
} else {
argExpressions[i + 1] = currArgument.Expression;
signatureTypes[i + 2] = currArgument.Expression.Type;
}
}
// Last signatureType is the return value
signatureTypes[signatureTypes.Length - 1] = typeof(object);
return new DynamicMetaObject(
Expression.MakeDynamic(
Expression.GetDelegateType(signatureTypes),
action,
argExpressions
),
restrictions
);
}
示例8: Dynamic
/// <summary>
/// Creates a <see cref="DynamicExpression" /> that represents a dynamic operation bound by the provided <see cref="CallSiteBinder" />.
/// </summary>
/// <param name="binder">The runtime binder for the dynamic operation.</param>
/// <param name="returnType">The result type of the dynamic expression.</param>
/// <param name="arguments">The arguments to the dynamic operation.</param>
/// <returns>
/// A <see cref="DynamicExpression" /> that has <see cref="NodeType" /> equal to
/// <see cref="ExpressionType.Dynamic">Dynamic</see> and has the
/// <see cref="DynamicExpression.Binder">Binder</see> and
/// <see cref="DynamicExpression.Arguments">Arguments</see> set to the specified values.
/// </returns>
/// <remarks>
/// The <see cref="DynamicExpression.DelegateType">DelegateType</see> property of the
/// result will be inferred from the types of the arguments and the specified return type.
/// </remarks>
public static DynamicExpression Dynamic(CallSiteBinder binder, Type returnType, IEnumerable<Expression> arguments)
{
ContractUtils.RequiresNotNull(arguments, nameof(arguments));
ContractUtils.RequiresNotNull(returnType, nameof(returnType));
var args = arguments.ToReadOnly();
ContractUtils.RequiresNotEmpty(args, nameof(args));
return MakeDynamic(binder, returnType, args);
}
示例9: CreateUntypedInstruction
internal static Instruction CreateUntypedInstruction(CallSiteBinder binder, int argCount)
{
switch (argCount)
{
case 0:
return DynamicInstruction<object>.Factory(binder);
case 1:
return DynamicInstruction<object, object>.Factory(binder);
case 2:
return DynamicInstruction<object, object, object>.Factory(binder);
case 3:
return DynamicInstruction<object, object, object, object>.Factory(binder);
case 4:
return DynamicInstruction<object, object, object, object, object>.Factory(binder);
case 5:
return DynamicInstruction<object, object, object, object, object, object>.Factory(binder);
case 6:
return DynamicInstruction<object, object, object, object, object, object, object>.Factory(binder);
case 7:
return DynamicInstruction<object, object, object, object, object, object, object, object>.Factory(binder);
case 8:
return DynamicInstruction<object, object, object, object, object, object, object, object, object>.Factory(binder);
case 9:
return DynamicInstruction<object, object, object, object, object, object, object, object, object, object>.Factory(binder);
case 10:
return DynamicInstruction<object, object, object, object, object, object, object, object, object, object, object>.Factory(binder);
case 11:
return DynamicInstruction<object, object, object, object, object, object, object, object, object, object, object, object>.Factory(binder);
case 12:
return DynamicInstruction<object, object, object, object, object, object, object, object, object, object, object, object, object>.Factory(binder);
case 13:
return DynamicInstruction<object, object, object, object, object, object, object, object, object, object, object, object, object, object>.Factory(binder);
case 14:
return DynamicInstruction<object, object, object, object, object, object, object, object, object, object, object, object, object, object, object>.Factory(binder);
case 15:
return DynamicInstruction<object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object>.Factory(binder);
}
return null;
}
示例10: MakeDynamic
public static Expression MakeDynamic(Type type, CallSiteBinder binder, IEnumerable<Expression> arguments, Type[] argumentTypes)
{
if (argumentTypes == null)
{
return Expression.Dynamic(binder, type, arguments);
}
else
{
// NB: This is a trick to leverage MakeCallSiteDelegate; we should refactor it to take in an array of types.
var args = argumentTypes.Map(a => (Expression)Expression.Default(a)).ToReadOnly();
var delegateType = DelegateHelpers.MakeCallSiteDelegate(args, type);
return Expression.MakeDynamic(delegateType, binder, arguments);
}
}
示例11: MakeInstruction
public static Instruction MakeInstruction(Type delegateType, CallSiteBinder binder) {
Func<CallSiteBinder, Instruction> factory;
if (!_factories.TryGetValue(delegateType, out factory)) {
Type instructionType = GetDynamicInstructionType(delegateType);
if (instructionType == null) {
return new DynamicInstructionN(delegateType, CallSite.Create(delegateType, binder));
}
factory = (Func<CallSiteBinder, Instruction>)Delegate.CreateDelegate(typeof(Func<CallSiteBinder, Instruction>),
instructionType.GetMethod("Factory"));
_factories[delegateType] = factory;
}
return factory(binder);
}
示例12: RewriteStrongBoxAsRef
internal static MetaObject RewriteStrongBoxAsRef(CallSiteBinder action, MetaObject target, MetaObject[] args) {
Debug.Assert(action != null && target != null && args != null);
var restrictions = target.Restrictions.Merge(Restrictions.Combine(args));
Expression[] argExpressions = new Expression[args.Length + 1];
Type[] signatureTypes = new Type[args.Length + 3]; // args + CallSite, target, returnType
signatureTypes[0] = typeof(CallSite);
//TODO: we are not restricting on target type here, but in theory we could.
//It is a tradeoff between rule reuse and higher polymorphism of the site.
argExpressions[0] = target.Expression;
signatureTypes[1] = target.Expression.Type;
for (int i = 0; i < args.Length; i++) {
MetaObject currArgument = args[i];
if (IsStrongBoxArg(currArgument)) {
restrictions = restrictions.Merge(Restrictions.GetTypeRestriction(currArgument.Expression, currArgument.LimitType));
// we have restricted this argument to LimitType so we can convert and conversion will be trivial cast.
Expression boxedValueAccessor = Expression.Field(
Helpers.Convert(
currArgument.Expression,
currArgument.LimitType
),
currArgument.LimitType.GetField("Value")
);
argExpressions[i + 1] = boxedValueAccessor;
signatureTypes[i + 2] = boxedValueAccessor.Type.MakeByRefType();
} else {
argExpressions[i + 1] = currArgument.Expression;
signatureTypes[i + 2] = currArgument.Expression.Type;
}
}
// Last signatureType is the return value
signatureTypes[signatureTypes.Length - 1] = typeof(object);
return new MetaObject(
Expression.MakeDynamic(
Expression.GetDelegateType(signatureTypes),
action,
argExpressions
),
restrictions
);
}
示例13: ReduceDynamic
/// <summary>
/// Reduces the dynamic expression to a binder and a set of arguments to apply the operation to.
/// </summary>
/// <param name="binder">The binder used to perform the dynamic operation.</param>
/// <param name="arguments">The arguments to apply the dynamic operation to.</param>
/// <param name="argumentTypes">The types of the arguments to use for the dynamic call site. Return null to infer types.</param>
protected override void ReduceDynamic(out CallSiteBinder binder, out IEnumerable<Expression> arguments, out Type[] argumentTypes)
{
var nodeType = OperationNodeType;
switch (nodeType)
{
case ExpressionType.NegateChecked:
nodeType = ExpressionType.Negate;
break;
}
binder = Binder.UnaryOperation(Flags, nodeType, Context, new[] { Operand.ArgumentInfo });
arguments = new[] { Operand.Expression };
argumentTypes = null;
}
示例14: ReduceDynamic
/// <summary>
/// Reduces the dynamic expression to a binder and a set of arguments to apply the operation to.
/// </summary>
/// <param name="binder">The binder used to perform the dynamic operation.</param>
/// <param name="arguments">The arguments to apply the dynamic operation to.</param>
/// <param name="argumentTypes">The types of the arguments to use for the dynamic call site. Return null to infer types.</param>
protected override void ReduceDynamic(out CallSiteBinder binder, out IEnumerable<Expression> arguments, out Type[] argumentTypes)
{
var n = Arguments.Count;
var argumentInfos = new CSharpArgumentInfo[n + 1];
var expressions = new Expression[n + 1];
expressions[0] = Expression;
argumentInfos[0] = CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null);
argumentTypes = null;
CopyArguments(Arguments, argumentInfos, expressions, ref argumentTypes);
binder = Binder.Invoke(Flags, Context, argumentInfos);
arguments = expressions;
}
示例15: ReduceDynamic
/// <summary>
/// Reduces the dynamic expression to a binder and a set of arguments to apply the operation to.
/// </summary>
/// <param name="binder">The binder used to perform the dynamic operation.</param>
/// <param name="arguments">The arguments to apply the dynamic operation to.</param>
/// <param name="argumentTypes">The types of the arguments to use for the dynamic call site. Return null to infer types.</param>
protected override void ReduceDynamic(out CallSiteBinder binder, out IEnumerable<Expression> arguments, out Type[] argumentTypes)
{
var n = Arguments.Count;
var argumentInfos = new CSharpArgumentInfo[n + 1];
var expressions = new Expression[n + 1];
expressions[0] = Expression.Constant(Type, typeof(Type));
argumentInfos[0] = CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType | CSharpArgumentInfoFlags.IsStaticType, null);
argumentTypes = null;
CopyArguments(Arguments, argumentInfos, expressions, ref argumentTypes);
binder = Binder.InvokeConstructor(Flags, Context, argumentInfos);
arguments = expressions;
}