本文整理汇总了C#中IronPython.Runtime.Binding.PythonBinder类的典型用法代码示例。如果您正苦于以下问题:C# PythonBinder类的具体用法?C# PythonBinder怎么用?C# PythonBinder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PythonBinder类属于IronPython.Runtime.Binding命名空间,在下文中一共展示了PythonBinder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MakeGetExpression
/// <summary>
/// Gets an expression which is used for accessing this slot. If the slot lookup fails the error expression
/// is used again.
///
/// The default implementation just calls the TryGetValue method. Subtypes of PythonTypeSlot can override
/// this and provide a more optimal implementation.
/// </summary>
internal virtual Expression/*!*/ MakeGetExpression(PythonBinder/*!*/ binder, Expression/*!*/ codeContext, Expression instance, Expression/*!*/ owner, Expression/*!*/ error) {
ParameterExpression tmp = Ast.Variable(typeof(object), "slotTmp");
Expression call = Ast.Call(
typeof(PythonOps).GetMethod("SlotTryGetValue"),
codeContext,
AstUtils.Convert(AstUtils.WeakConstant(this), typeof(PythonTypeSlot)),
instance ?? AstUtils.Constant(null),
owner,
tmp
);
if (!GetAlwaysSucceeds) {
call = Ast.Condition(
call,
tmp,
AstUtils.Convert(error, typeof(object))
);
} else {
call = Ast.Block(call, tmp);
}
return Ast.Block(
new ParameterExpression[] { tmp },
call
);
}
示例2: PythonOverloadResolver
// instance method call:
public PythonOverloadResolver(PythonBinder binder, DynamicMetaObject instance, IList<DynamicMetaObject> args, CallSignature signature,
Expression codeContext)
: base(binder, instance, args, signature)
{
Assert.NotNull(codeContext);
_context = codeContext;
}
示例3: ShouldWarn
public static bool ShouldWarn(PythonBinder/*!*/ binder, MethodBase/*!*/ method, out WarningInfo info) {
Assert.NotNull(method);
ObsoleteAttribute[] os = (ObsoleteAttribute[])method.GetCustomAttributes(typeof(ObsoleteAttribute), true);
if (os.Length > 0) {
info = new WarningInfo(
PythonExceptions.DeprecationWarning,
String.Format("{0}.{1} has been obsoleted. {2}",
NameConverter.GetTypeName(method.DeclaringType),
method.Name,
os[0].Message
)
);
return true;
}
if (binder.WarnOnPython3000) {
Python3WarningAttribute[] py3kwarnings = (Python3WarningAttribute[])method.GetCustomAttributes(typeof(Python3WarningAttribute), true);
if (py3kwarnings.Length > 0) {
info = new WarningInfo(
PythonExceptions.DeprecationWarning,
py3kwarnings[0].Message
);
return true;
}
}
#if !SILVERLIGHT
// no apartment states on Silverlight
if (method.DeclaringType == typeof(Thread)) {
if (method.Name == "Sleep") {
info = new WarningInfo(
PythonExceptions.RuntimeWarning,
"Calling Thread.Sleep on an STA thread doesn't pump messages. Use Thread.CurrentThread.Join instead.",
Expression.Equal(
Expression.Call(
Expression.Property(
null,
typeof(Thread).GetProperty("CurrentThread")
),
typeof(Thread).GetMethod("GetApartmentState")
),
AstUtils.Constant(ApartmentState.STA)
),
() => Thread.CurrentThread.GetApartmentState() == ApartmentState.STA
);
return true;
}
}
#endif
info = null;
return false;
}
示例4: MakeGetExpression
internal override Expression/*!*/ MakeGetExpression(PythonBinder/*!*/ binder, Expression/*!*/ codeContext, Expression instance, Expression/*!*/ owner, Expression/*!*/ error) {
if (instance != null) {
return Ast.Call(
typeof(PythonOps).GetMethod("MakeBoundBuiltinFunction"),
Ast.Constant(_template),
instance
);
}
return Ast.Constant(this);
}
示例5: MakeGetExpression
internal override void MakeGetExpression(PythonBinder/*!*/ binder, Expression/*!*/ codeContext, Expression instance, Expression/*!*/ owner, ConditionalBuilder/*!*/ builder) {
if (instance != null) {
builder.FinishCondition(
Ast.Call(
typeof(PythonOps).GetMethod("MakeBoundBuiltinFunction"),
AstUtils.Constant(_template),
instance
)
);
} else {
builder.FinishCondition(AstUtils.Constant(this));
}
}
示例6: MakeGetExpression
/// <summary>
/// Gets an expression which is used for accessing this slot. If the slot lookup fails the error expression
/// is used again.
///
/// The default implementation just calls the TryGetValue method. Subtypes of PythonTypeSlot can override
/// this and provide a more optimal implementation.
/// </summary>
internal virtual void MakeGetExpression(PythonBinder/*!*/ binder, Expression/*!*/ codeContext, DynamicMetaObject instance, DynamicMetaObject/*!*/ owner, ConditionalBuilder/*!*/ builder) {
ParameterExpression tmp = Ast.Variable(typeof(object), "slotTmp");
Expression call = Ast.Call(
typeof(PythonOps).GetMethod("SlotTryGetValue"),
codeContext,
AstUtils.Convert(AstUtils.WeakConstant(this), typeof(PythonTypeSlot)),
instance != null ? instance.Expression : AstUtils.Constant(null),
owner.Expression,
tmp
);
builder.AddVariable(tmp);
if (!GetAlwaysSucceeds) {
builder.AddCondition(
call,
tmp
);
} else {
builder.FinishCondition(Ast.Block(call, tmp));
}
}
示例7: GetMember
/// <summary>
/// Gets the statically known member from the type with the specific name. Searches only the specified type to find the member.
/// </summary>
public static MemberGroup/*!*/ GetMember(PythonBinder/*!*/ binder, OldDynamicAction/*!*/ action, Type/*!*/ type, string/*!*/ name) {
Assert.NotNull(binder, action, type, name);
PerfTrack.NoteEvent(PerfTrack.Categories.ReflectedTypes, String.Format("LookupMember: {0} {1}", type.Name, name));
return GetMemberGroup(new LookupBinder(binder), action, type, name);
}
示例8: ResolveBinder
public ResolveBinder(PythonBinder/*!*/ binder)
: base(binder) {
}
示例9: MakeGetExpression
internal override void MakeGetExpression(PythonBinder/*!*/ binder, Expression/*!*/ codeContext, DynamicMetaObject instance, DynamicMetaObject/*!*/ owner, ConditionalBuilder/*!*/ builder) {
if (Getter.Length != 0 && !Getter[0].IsPublic) {
// fallback to runtime call
base.MakeGetExpression(binder, codeContext, instance, owner, builder);
} else if (NeedToReturnProperty(instance, Getter)) {
builder.FinishCondition(AstUtils.Constant(this));
} else if (Getter[0].ContainsGenericParameters) {
builder.FinishCondition(
DefaultBinder.MakeError(
binder.MakeContainsGenericParametersError(
MemberTracker.FromMemberInfo(_info)
),
typeof(object)
).Expression
);
} else if (instance != null) {
builder.FinishCondition(
AstUtils.Convert(
binder.MakeCallExpression(
new PythonOverloadResolverFactory(binder, codeContext),
Getter[0],
instance
).Expression,
typeof(object)
)
);
} else {
builder.FinishCondition(
AstUtils.Convert(
binder.MakeCallExpression(
new PythonOverloadResolverFactory(binder, codeContext),
Getter[0]
).Expression,
typeof(object)
)
);
}
}
示例10: GetMembersAll
/// <summary>
/// Gets all the statically known members from the specified type. Searches the entire type hierarchy to get all possible members.
///
/// The result may include multiple resolution. It is the callers responsibility to only treat the 1st one by name as existing.
/// </summary>
public static IList<ResolvedMember/*!*/>/*!*/ GetMembersAll(PythonBinder/*!*/ binder, MemberRequestKind/*!*/ action, Type/*!*/ type) {
Assert.NotNull(binder, action, type);
return GetResolvedMembers(new ResolveBinder(binder), action, type);
}
示例11: MakeInitCall
public override DynamicMetaObject/*!*/ MakeInitCall(PythonBinder/*!*/ binder, DynamicMetaObject/*!*/ createExpr) {
Expression init = Ast.Call(
typeof(PythonOps).GetMethod("GetMixedMember"),
CodeContext,
Ast.Convert(Arguments.Self.Expression, typeof(PythonType)),
AstUtils.Convert(createExpr.Expression, typeof(object)),
AstUtils.Constant("__init__")
);
return MakeDefaultInit(binder, createExpr, init);
}
示例12: PythonOverloadResolverFactory
public PythonOverloadResolverFactory(PythonBinder/*!*/ binder, Expression/*!*/ codeContext)
{
Assert.NotNull(binder, codeContext);
_binder = binder;
_codeContext = codeContext;
}
示例13: MakeGetExpression
internal override void MakeGetExpression(PythonBinder/*!*/ binder, Expression/*!*/ codeContext, DynamicMetaObject instance, DynamicMetaObject/*!*/ owner, ConditionalBuilder/*!*/ builder) {
if (!_info.IsPublic || _info.DeclaringType.ContainsGenericParameters) {
// fallback to reflection
base.MakeGetExpression(binder, codeContext, instance, owner, builder);
} else if (instance == null) {
if (_info.IsStatic) {
builder.FinishCondition(AstUtils.Convert(Ast.Field(null, _info), typeof(object)));
} else {
builder.FinishCondition(Ast.Constant(this));
}
} else {
builder.FinishCondition(
AstUtils.Convert(
Ast.Field(
binder.ConvertExpression(
instance.Expression,
_info.DeclaringType,
ConversionResultKind.ExplicitCast,
new PythonOverloadResolverFactory(binder, codeContext)
),
_info
),
typeof(object)
)
);
}
}
示例14: PythonExtensionBinder
public PythonExtensionBinder(PythonBinder binder, ExtensionMethodSet extensionMethods)
: base(binder) {
_extMethodSet = extensionMethods;
}
示例15: MakeDefaultInit
protected DynamicMetaObject/*!*/ MakeDefaultInit(PythonBinder/*!*/ binder, DynamicMetaObject/*!*/ createExpr, Expression/*!*/ init) {
List<Expression> args = new List<Expression>();
args.Add(CodeContext);
args.Add(Expression.Convert(createExpr.Expression, typeof(object)));
foreach (DynamicMetaObject mo in Arguments.Arguments) {
args.Add(mo.Expression);
}
return new DynamicMetaObject(
DynamicExpression.Dynamic(
((PythonType)Arguments.Self.Value).GetLateBoundInitBinder(Arguments.Signature),
typeof(object),
args.ToArray()
),
Arguments.Self.Restrictions.Merge(createExpr.Restrictions)
);
}