本文整理汇总了C#中DynamicMetaObjectBinder类的典型用法代码示例。如果您正苦于以下问题:C# DynamicMetaObjectBinder类的具体用法?C# DynamicMetaObjectBinder怎么用?C# DynamicMetaObjectBinder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DynamicMetaObjectBinder类属于命名空间,在下文中一共展示了DynamicMetaObjectBinder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: MakeStandardDotNetTypeCall
/// <summary>
/// Creating a standard .NET type is easy - we just call it's constructor with the provided
/// arguments.
/// </summary>
private DynamicMetaObject/*!*/ MakeStandardDotNetTypeCall(DynamicMetaObjectBinder/*!*/ call, Expression/*!*/ codeContext, DynamicMetaObject/*!*/[]/*!*/ args) {
CallSignature signature = BindingHelpers.GetCallSignature(call);
BinderState state = BinderState.GetBinderState(call);
MethodBase[] ctors = CompilerHelpers.GetConstructors(Value.UnderlyingSystemType, state.Binder.PrivateBinding);
if (ctors.Length > 0) {
return state.Binder.CallMethod(
new ParameterBinderWithCodeContext(state.Binder, codeContext),
ctors,
args,
signature,
Restrictions.Merge(BindingRestrictions.GetInstanceRestriction(Expression, Value))
);
} else {
return new DynamicMetaObject(
Ast.Throw(
Ast.New(
typeof(ArgumentTypeException).GetConstructor(new Type[] { typeof(string) }),
Ast.Constant("Cannot create instances of " + Value.Name)
)
),
Restrictions.Merge(BindingRestrictions.GetInstanceRestriction(Expression, Value))
);
}
}
开发者ID:octavioh,项目名称:ironruby,代码行数:29,代码来源:MetaPythonType.Calls.cs
示例2: ConvertWorker
public DynamicMetaObject ConvertWorker(DynamicMetaObjectBinder binder, Type toType, ConversionResultKind kind) {
if (toType.IsSubclassOf(typeof(Delegate))) {
return MakeDelegateTarget(binder, toType, Restrict(typeof(Method)));
}
return FallbackConvert(binder);
}
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:7,代码来源:MetaMethod.cs
示例3: IsNoThrow
internal static bool IsNoThrow(DynamicMetaObjectBinder action) {
PythonGetMemberBinder gmb = action as PythonGetMemberBinder;
if (gmb != null) {
return gmb.IsNoThrow;
}
return false;
}
开发者ID:m4dc4p,项目名称:ironruby,代码行数:8,代码来源:BindingHelpers.cs
示例4: Dynamic
public Expression Dynamic(DynamicMetaObjectBinder binder, Type retType, Expression arg0, Expression arg1, Expression arg2, Expression arg3)
{
if(retType == typeof(object))
return new TotemDynamicExpression4(binder, this, arg0, arg1, arg2, arg3);
else if(retType == typeof(bool))
return new TotemDynamicExpression4<bool>(binder, this, arg0, arg1, arg2, arg3);
return ReduceDynamic(binder, retType, arg0, arg1, arg2, arg3);
}
开发者ID:Alxandr,项目名称:IronTotem-3.0,代码行数:9,代码来源:DynamicExpressions.cs
示例5: ConvertWorker
public DynamicMetaObject ConvertWorker(DynamicMetaObjectBinder binder, Type toType, ConversionResultKind kind) {
PerfTrack.NoteEvent(PerfTrack.Categories.Binding, "BuiltinFunc Convert " + toType);
PerfTrack.NoteEvent(PerfTrack.Categories.BindingTarget, "BuiltinFunc Convert");
if (toType.IsSubclassOf(typeof(Delegate))) {
return MakeDelegateTarget(binder, toType, Restrict(LimitType));
}
return FallbackConvert(binder);
}
开发者ID:rafacv,项目名称:iron_languages,代码行数:10,代码来源:MetaBuiltinFunction.cs
示例6: ConvertWorker
public DynamicMetaObject ConvertWorker(DynamicMetaObjectBinder binder, Type type, Type retType, ConversionResultKind kind) {
PerfTrack.NoteEvent(PerfTrack.Categories.Binding, "Conversion " + type.FullName);
PerfTrack.NoteEvent(PerfTrack.Categories.BindingTarget, "Conversion");
ValidationInfo typeTest = BindingHelpers.GetValidationInfo(this, Value.PythonType);
return BindingHelpers.AddDynamicTestAndDefer(
binder,
TryPythonConversion(binder, type) ?? FallbackConvert(binder),
new DynamicMetaObject[] { this },
typeTest,
retType
);
}
开发者ID:jschementi,项目名称:iron,代码行数:13,代码来源:MetaUserObject.cs
示例7: Dynamic
/*!*/
public MSAst.Expression Dynamic(DynamicMetaObjectBinder/*!*/ binder, Type/*!*/ retType, MSAst.Expression/*!*/ arg0)
{
if (retType == typeof(object))
{
throw new NotImplementedException();
//return new TotemDynamicExpression1(binder, this, arg0);
}
else if (retType == typeof(bool))
{
throw new NotImplementedException();
//return new TotemDynamicExpression1<bool>(binder, this, arg0);
}
return ReduceDynamic(binder, retType, arg0);
}
开发者ID:Alxandr,项目名称:IronTotem,代码行数:16,代码来源:CompilationMode.cs
示例8: InvokeWorker
private DynamicMetaObject/*!*/ InvokeWorker(DynamicMetaObjectBinder/*!*/ call, Expression/*!*/ codeContext, DynamicMetaObject/*!*/[] args) {
PerfTrack.NoteEvent(PerfTrack.Categories.Binding, "BuiltinMethodDesc Invoke " + Value.DeclaringType + "." + Value.__name__ + " w/ " + args.Length + " args");
PerfTrack.NoteEvent(PerfTrack.Categories.BindingTarget, "BuiltinMethodDesc Invoke");
CallSignature signature = BindingHelpers.GetCallSignature(call);
BindingRestrictions selfRestrict = BindingRestrictions.GetInstanceRestriction(Expression, Value).Merge(Restrictions);
selfRestrict = selfRestrict.Merge(
BindingRestrictions.GetExpressionRestriction(
MakeFunctionTest(
Ast.Call(
typeof(PythonOps).GetMethod("GetBuiltinMethodDescriptorTemplate"),
Ast.Convert(Expression, typeof(BuiltinMethodDescriptor))
)
)
)
);
return Value.Template.MakeBuiltinFunctionCall(
call,
codeContext,
this,
args,
false, // no self
selfRestrict,
(newArgs) => {
BindingTarget target;
PythonContext state = PythonContext.GetPythonContext(call);
DynamicMetaObject res = state.Binder.CallMethod(
new PythonOverloadResolver(
state.Binder,
newArgs,
signature,
codeContext
),
Value.Template.Targets,
selfRestrict,
Value.Template.Name,
NarrowingLevel.None,
Value.Template.IsBinaryOperator ? PythonNarrowing.BinaryOperator : NarrowingLevel.All,
out target
);
return BindingHelpers.CheckLightThrow(call, res, target);
});
}
开发者ID:CookieEaters,项目名称:FireHTTP,代码行数:47,代码来源:MetaBuiltinMethodDescriptor.cs
示例9: InvokeWorker
private DynamicMetaObject/*!*/ InvokeWorker(DynamicMetaObjectBinder/*!*/ call, DynamicMetaObject/*!*/[]/*!*/ args, Expression/*!*/ codeContext) {
if (this.NeedsDeferral()) {
return call.Defer(ArrayUtils.Insert(this, args));
}
for (int i = 0; i < args.Length; i++) {
if (args[i].NeedsDeferral()) {
return call.Defer(ArrayUtils.Insert(this, args));
}
}
if (IsStandardDotNetType(call)) {
return MakeStandardDotNetTypeCall(call, codeContext, args);
}
return MakePythonTypeCall(call, codeContext, args);
}
开发者ID:octavioh,项目名称:ironruby,代码行数:17,代码来源:MetaPythonType.Calls.cs
示例10: FunctionBinderHelper
public FunctionBinderHelper(DynamicMetaObjectBinder call, MetaTotemFunction function, Expression codeContext, DynamicMetaObject[] args)
{
PerfTrack.NoteEvent(PerfTrack.Categories.Binding, "TotemFunction Invoke " + function.Value.FunctionCompatibility + " w/ " + args.Length + " args");
PerfTrack.NoteEvent(PerfTrack.Categories.BindingTarget, "TotemFunction");
_call = call;
_func = function;
_args = args;
_originalArgs = args;
_temps = new List<ParameterExpression>();
_codeContext = codeContext;
// Remove the passed in instance argument if present
int instanceIndex = Signature.IndexOf(ArgumentType.Instance);
if (instanceIndex > -1)
_args = ArrayUtils.RemoveAt(_args, instanceIndex);
}
开发者ID:Alxandr,项目名称:IronTotem-3.0,代码行数:17,代码来源:MetaTotemFunction.cs
示例11: FilterShowCls
internal static DynamicMetaObject/*!*/ FilterShowCls(Expression/*!*/ codeContext, DynamicMetaObjectBinder/*!*/ action, DynamicMetaObject/*!*/ res, Expression/*!*/ failure) {
if (action is IPythonSite) {
return new DynamicMetaObject(
Ast.Condition(
Ast.Call(
typeof(PythonOps).GetMethod("IsClsVisible"),
codeContext
),
AstUtils.Convert(res.Expression, typeof(object)),
AstUtils.Convert(failure, typeof(object))
),
res.Restrictions
);
}
return res;
}
开发者ID:m4dc4p,项目名称:ironruby,代码行数:18,代码来源:BindingHelpers.cs
示例12: InvokeWorker
private DynamicMetaObject/*!*/ InvokeWorker(DynamicMetaObjectBinder/*!*/ call, DynamicMetaObject/*!*/[]/*!*/ args, Expression/*!*/ codeContext) {
PerfTrack.NoteEvent(PerfTrack.Categories.Binding, "Type Invoke " + Value.UnderlyingSystemType.FullName + args.Length);
PerfTrack.NoteEvent(PerfTrack.Categories.BindingTarget, "Type Invoke");
if (this.NeedsDeferral()) {
return call.Defer(ArrayUtils.Insert(this, args));
}
for (int i = 0; i < args.Length; i++) {
if (args[i].NeedsDeferral()) {
return call.Defer(ArrayUtils.Insert(this, args));
}
}
if (IsStandardDotNetType(call)) {
return MakeStandardDotNetTypeCall(call, codeContext, args);
}
return MakePythonTypeCall(call, codeContext, args);
}
开发者ID:tnachen,项目名称:ironruby,代码行数:19,代码来源:MetaPythonType.Calls.cs
示例13: FilterShowCls
internal static DynamicMetaObject/*!*/ FilterShowCls(Expression/*!*/ codeContext, DynamicMetaObjectBinder/*!*/ action, DynamicMetaObject/*!*/ res, Expression/*!*/ failure) {
if (action is IPythonSite) {
Type resType = BindingHelpers.GetCompatibleType(res.Expression.Type, failure.Type);
return new DynamicMetaObject(
Ast.Condition(
Ast.Call(
typeof(PythonOps).GetMethod("IsClsVisible"),
codeContext
),
AstUtils.Convert(res.Expression, resType),
AstUtils.Convert(failure, resType)
),
res.Restrictions
);
}
return res;
}
开发者ID:jcteague,项目名称:ironruby,代码行数:20,代码来源:BindingHelpers.cs
示例14: InvokeWorker
private DynamicMetaObject/*!*/ InvokeWorker(DynamicMetaObjectBinder/*!*/ call, Expression/*!*/ codeContext, DynamicMetaObject/*!*/[]/*!*/ args) {
PerfTrack.NoteEvent(PerfTrack.Categories.Binding, "BuiltinFunc Invoke " + Value.DeclaringType.FullName + "." + Value.Name + " with " + args.Length + " args " + Value.IsUnbound);
PerfTrack.NoteEvent(PerfTrack.Categories.BindingTarget, "BuiltinFunction " + Value.Targets.Count + ", " + Value.Targets[0].GetParameters().Length);
PerfTrack.NoteEvent(PerfTrack.Categories.BindingSlow, "BuiltinFunction " + BindingHelpers.GetCallSignature(call));
if (this.NeedsDeferral()) {
return call.Defer(ArrayUtils.Insert(this, args));
}
for (int i = 0; i < args.Length; i++) {
if (args[i].NeedsDeferral()) {
return call.Defer(ArrayUtils.Insert(this, args));
}
}
if (Value.IsUnbound) {
return MakeSelflessCall(call, codeContext, args);
} else {
return MakeSelfCall(call, codeContext, args);
}
}
开发者ID:tnachen,项目名称:ironruby,代码行数:21,代码来源:MetaBuiltinFunction.cs
示例15: MakeConvertToBool
private DynamicMetaObject/*!*/ MakeConvertToBool(DynamicMetaObjectBinder/*!*/ conversion) {
DynamicMetaObject self = Restrict(typeof(OldInstance));
ParameterExpression tmp = Ast.Variable(typeof(bool?), "tmp");
DynamicMetaObject fallback = FallbackConvert(conversion);
Type resType = BindingHelpers.GetCompatibleType(typeof(bool), fallback.Expression.Type);
return new DynamicMetaObject(
Ast.Block(
new ParameterExpression[] { tmp },
Ast.Condition(
Ast.NotEqual(
Ast.Assign(
tmp,
Ast.Call(
typeof(PythonOps).GetMethod("OldInstanceConvertToBoolNonThrowing"),
AstUtils.Constant(PythonContext.GetPythonContext(conversion).SharedContext),
self.Expression
)
),
AstUtils.Constant(null)
),
AstUtils.Convert(tmp, resType),
AstUtils.Convert(fallback.Expression, resType)
)
),
self.Restrictions
);
}
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:29,代码来源:MetaOldInstance.cs
示例16: MakeMemberAccess
private DynamicMetaObject/*!*/ MakeMemberAccess(DynamicMetaObjectBinder/*!*/ member, string name, MemberAccess access, params DynamicMetaObject/*!*/[]/*!*/ args) {
DynamicMetaObject self = Restrict(typeof(OldInstance));
CustomOldClassDictionaryStorage dict;
int key = GetCustomStorageSlot(name, out dict);
if (key == -1) {
PerfTrack.NoteEvent(PerfTrack.Categories.Binding, "OldInstance " + access + " NoOptimized");
return MakeDynamicMemberAccess(member, name, access, args);
}
ParameterExpression tmp = Ast.Variable(typeof(object), "dict");
Expression target;
ValidationInfo test = new ValidationInfo(
Ast.NotEqual(
Ast.Assign(
tmp,
Ast.Call(
typeof(PythonOps).GetMethod("OldInstanceGetOptimizedDictionary"),
self.Expression,
AstUtils.Constant(dict.KeyVersion)
)
),
AstUtils.Constant(null)
)
);
PerfTrack.NoteEvent(PerfTrack.Categories.Binding, "OldInstance " + access + " Optimized");
switch (access) {
case MemberAccess.Invoke:
ParameterExpression value = Ast.Variable(typeof(object), "value");
target = Ast.Block(
new[] { value },
Ast.Condition(
Ast.Call(
typeof(PythonOps).GetMethod("TryOldInstanceDictionaryGetValueHelper"),
tmp,
Ast.Constant(key),
AstUtils.Convert(Expression, typeof(object)),
value
),
AstUtils.Convert(
((InvokeMemberBinder)member).FallbackInvoke(new DynamicMetaObject(value, BindingRestrictions.Empty), args, null).Expression,
typeof(object)
),
AstUtils.Convert(
((InvokeMemberBinder)member).FallbackInvokeMember(self, args).Expression,
typeof(object)
)
)
);
break;
case MemberAccess.Get:
// BUG: There's a missing Fallback path here that's always been present even
// in the version that used rules.
target = Ast.Call(
typeof(PythonOps).GetMethod("OldInstanceDictionaryGetValueHelper"),
tmp,
AstUtils.Constant(key),
AstUtils.Convert(Expression, typeof(object))
);
break;
case MemberAccess.Set:
target = Ast.Call(
typeof(PythonOps).GetMethod("OldInstanceDictionarySetExtraValue"),
tmp,
AstUtils.Constant(key),
AstUtils.Convert(args[1].Expression, typeof(object))
);
break;
case MemberAccess.Delete:
target = Ast.Call(
typeof(PythonOps).GetMethod("OldInstanceDeleteCustomMember"),
AstUtils.Constant(PythonContext.GetPythonContext(member).SharedContext),
AstUtils.Convert(Expression, typeof(OldInstance)),
AstUtils.Constant(name)
);
break;
default:
throw new InvalidOperationException();
}
return BindingHelpers.AddDynamicTestAndDefer(
member,
new DynamicMetaObject(
target,
BindingRestrictions.Combine(args).Merge(self.Restrictions)
),
args,
test,
tmp
);
}
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:92,代码来源:MetaOldInstance.cs
示例17: MakeConvertToCommon
private DynamicMetaObject/*!*/ MakeConvertToCommon(DynamicMetaObjectBinder/*!*/ conversion, Type toType, Type retType, string name) {
// TODO: support trys
ParameterExpression tmp = Ast.Variable(typeof(object), "convertResult");
DynamicMetaObject self = Restrict(typeof(OldInstance));
return new DynamicMetaObject(
Ast.Block(
new ParameterExpression[] { tmp },
Ast.Condition(
MakeOneConvert(conversion, self, name, tmp),
Expression.Convert(
tmp,
retType
),
FallbackConvert(conversion).Expression
)
),
self.Restrictions
);
}
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:19,代码来源:MetaOldInstance.cs
示例18: MakeOneConvert
private static BinaryExpression/*!*/ MakeOneConvert(DynamicMetaObjectBinder/*!*/ conversion, DynamicMetaObject/*!*/ self, string name, ParameterExpression/*!*/ tmp) {
return Ast.NotEqual(
Ast.Assign(
tmp,
Ast.Call(
typeof(PythonOps).GetMethod("OldInstanceConvertNonThrowing"),
AstUtils.Constant(PythonContext.GetPythonContext(conversion).SharedContext),
self.Expression,
AstUtils.Constant(name)
)
),
AstUtils.Constant(null)
);
}
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:14,代码来源:MetaOldInstance.cs
示例19: MakeConvertToIEnumerable
private DynamicMetaObject/*!*/ MakeConvertToIEnumerable(DynamicMetaObjectBinder/*!*/ conversion) {
ParameterExpression tmp = Ast.Variable(typeof(IEnumerable), "res");
DynamicMetaObject self = Restrict(typeof(OldInstance));
return new DynamicMetaObject(
Ast.Block(
new ParameterExpression[] { tmp },
Ast.Condition(
Ast.NotEqual(
Ast.Assign(
tmp,
Ast.Call(
typeof(PythonOps).GetMethod("OldInstanceConvertToIEnumerableNonThrowing"),
AstUtils.Constant(PythonContext.GetPythonContext(conversion).SharedContext),
self.Expression
)
),
AstUtils.Constant(null)
),
tmp,
AstUtils.Convert(
AstUtils.Convert( // first to object (incase it's a throw), then to IEnumerable
FallbackConvert(conversion).Expression,
typeof(object)
),
typeof(IEnumerable)
)
)
),
self.Restrictions
);
}
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:32,代码来源:MetaOldInstance.cs
示例20: ConvertWorker
public DynamicMetaObject ConvertWorker(DynamicMetaObjectBinder binder, Type type, Type retType, ConversionResultKind kind) {
if (!type.IsEnum) {
switch (Type.GetTypeCode(type)) {
case TypeCode.Boolean:
return MakeConvertToBool(binder);
case TypeCode.Int32:
return MakeConvertToCommon(binder, type, retType, "__int__");
case TypeCode.Double:
return MakeConvertToCommon(binder, type, retType, "__float__");
case TypeCode.String:
return MakeConvertToCommon(binder, type, retType, "__str__");
case TypeCode.Object:
if (type == typeof(BigInteger)) {
return MakeConvertToCommon(binder, type, retType, "__long__");
} else if (type == typeof(Complex64)) {
return MakeConvertToCommon(binder, type, retType, "__complex__");
} else if (type == typeof(IEnumerable)) {
return MakeConvertToIEnumerable(binder);
} else if (type == typeof(IEnumerator)) {
return MakeConvertToIEnumerator(binder);
} else if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(IEnumerable<>)) {
return MakeConvertToIEnumerable(binder, type, type.GetGenericArguments()[0]);
} else if (type.IsSubclassOf(typeof(Delegate))) {
return MakeDelegateTarget(binder, type, Restrict(typeof(OldInstance)));
}
break;
}
}
return FallbackConvert(binder);
}
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:32,代码来源:MetaOldInstance.cs
注:本文中的DynamicMetaObjectBinder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论