本文整理汇总了C#中System.Runtime.CompilerServices.CallSiteBinder类的典型用法代码示例。如果您正苦于以下问题:C# CallSiteBinder类的具体用法?C# CallSiteBinder怎么用?C# CallSiteBinder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CallSiteBinder类属于System.Runtime.CompilerServices命名空间,在下文中一共展示了CallSiteBinder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
}
开发者ID:jschementi,项目名称:iron,代码行数:7,代码来源:DynamicExpression.cs
示例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 });
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:33,代码来源:CallSite.cs
示例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;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:7,代码来源:DynamicExpression4.cs
示例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;
}
开发者ID:taolin123,项目名称:ExpressionFutures,代码行数:33,代码来源:BinaryDynamicCSharpExpression.cs
示例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 });
}
开发者ID:noahfalk,项目名称:corefx,代码行数:39,代码来源:CallSite.cs
示例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);
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:8,代码来源:DynamicExpression.cs
示例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
);
}
开发者ID:joshholmes,项目名称:ironruby,代码行数:57,代码来源:ComBinderHelpers.cs
示例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);
}
开发者ID:dotnet,项目名称:corefx,代码行数:25,代码来源:Expression.netstandard1.7.cs
示例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;
}
开发者ID:nickchal,项目名称:pash,代码行数:54,代码来源:DynamicInstructionN.cs
示例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);
}
}
开发者ID:taolin123,项目名称:ExpressionFutures,代码行数:14,代码来源:DynamicHelpers.cs
示例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);
}
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:14,代码来源:DynamicInstructions.cs
示例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
);
}
开发者ID:mscottford,项目名称:ironruby,代码行数:49,代码来源:ComBinderHelpers.cs
示例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;
}
开发者ID:taolin123,项目名称:ExpressionFutures,代码行数:21,代码来源:UnaryDynamicCSharpExpression.cs
示例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;
}
开发者ID:taolin123,项目名称:ExpressionFutures,代码行数:22,代码来源:InvokeDynamicCSharpExpression.cs
示例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;
}
开发者ID:taolin123,项目名称:ExpressionFutures,代码行数:22,代码来源:InvokeConstructorDynamicCSharpExpression.cs
示例16: BindGetOrInvoke
private DynamicMetaObject BindGetOrInvoke(CallSiteBinder binder, DynamicMetaObject[] args, IList<ArgumentInfo> argInfos) {
if (args.Any(arg => ComBinderHelpers.IsStrongBoxArg(arg))) {
return ComBinderHelpers.RewriteStrongBoxAsRef(binder, this, args, false);
}
ComMethodDesc method;
var target = _callable.DispatchComObject;
var name = _callable.MemberName;
if (target.TryGetMemberMethod(name, out method) ||
target.TryGetMemberMethodExplicit(name, out method)) {
return BindComInvoke(method, args, argInfos);
}
return null;
}
开发者ID:joshholmes,项目名称:ironruby,代码行数:16,代码来源:DispCallableMetaObject.cs
示例17: 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];
// NB: By-ref passing for the receiver seems to be omitted in Roslyn here; see https://github.com/dotnet/roslyn/issues/6818.
// We're choosing to be consistent with that behavior until further notice.
expressions[0] = Object;
argumentInfos[0] = CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null);
argumentTypes = null;
CopyArguments(Arguments, argumentInfos, expressions, ref argumentTypes);
binder = Binder.GetIndex(Flags, Context, argumentInfos);
arguments = expressions;
}
开发者ID:taolin123,项目名称:ExpressionFutures,代码行数:24,代码来源:GetIndexDynamicCSharpExpression.cs
示例18: 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");
ContractUtils.Requires(delegateType.IsSubclassOf(typeof(Delegate)), "delegateType", Strings.TypeMustBeDerivedFromSystemDelegate);
if (_SiteCtors == null) {
// It's okay to just set this, worst case we're just throwing away some data
_SiteCtors = new CacheDict<Type, Func<CallSiteBinder, CallSite>>(100);
}
Func<CallSiteBinder, CallSite> ctor;
lock (_SiteCtors) {
if (!_SiteCtors.TryGetValue(delegateType, out ctor)) {
MethodInfo method = typeof(CallSite<>).MakeGenericType(delegateType).GetMethod("Create");
ctor = (Func<CallSiteBinder, CallSite>)Delegate.CreateDelegate(typeof(Func<CallSiteBinder, CallSite>), method);
_SiteCtors.Add(delegateType, ctor);
}
}
return ctor(binder);
}
开发者ID:mscottford,项目名称:ironruby,代码行数:25,代码来源:CallSite.cs
示例19: MakeInstruction
public static Instruction MakeInstruction(Type delegateType, CallSiteBinder binder) {
Func<CallSiteBinder, Instruction> factory;
lock (_factories) {
if (!_factories.TryGetValue(delegateType, out factory)) {
if (delegateType.GetMethod("Invoke").ReturnType == typeof(void)) {
// TODO: We should generally support void returning binders but the only
// ones that exist are delete index/member who's perf isn't that critical.
return new DynamicInstructionN(delegateType, CallSite.Create(delegateType, binder), true);
}
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);
}
开发者ID:andreakn,项目名称:ironruby,代码行数:22,代码来源:DynamicInstructions.cs
示例20: GetMemberAccessCallSite
// Dev10 Bug 914027 - Changed the callsite's target parameter from dynamic to object, see comment at top for details
public static CallSite<Func<CallSite, object, object>> GetMemberAccessCallSite(CallSiteBinder binder)
{
return CallSite<Func<CallSite, object, object>>.Create(binder);
}
开发者ID:haoduotnt,项目名称:aspnetwebstack,代码行数:5,代码来源:DynamicHelper.cs
注:本文中的System.Runtime.CompilerServices.CallSiteBinder类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论