本文整理汇总了C#中PythonContext类的典型用法代码示例。如果您正苦于以下问题:C# PythonContext类的具体用法?C# PythonContext怎么用?C# PythonContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PythonContext类属于命名空间,在下文中一共展示了PythonContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Convert
/// <summary>
/// Backwards compatible Convert for the old sites that need to flow CodeContext
/// </summary>
public static Expression/*!*/ Convert(Expression/*!*/ codeContext, PythonContext/*!*/ binder, Type/*!*/ type, ConversionResultKind resultKind, Expression/*!*/ target) {
return Ast.Dynamic(
binder.Convert(type, resultKind),
type,
target
);
}
示例2: Get
public static Expression/*!*/ Get(Expression/*!*/ codeContext, PythonContext/*!*/ binder, Type/*!*/ resultType, string/*!*/ name, Expression/*!*/ target) {
return Ast.Dynamic(
binder.GetMember(name),
resultType,
target,
codeContext
);
}
示例3: ShouldWarn
public static bool ShouldWarn(PythonContext/*!*/ context, 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 (context.PythonOptions.WarnPython30) {
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: BinaryOperationBinder
public static DynamicMetaObjectBinder BinaryOperationBinder(PythonContext state, PythonOperationKind operatorName) {
ExpressionType? et = GetExpressionTypeFromBinaryOperator(operatorName);
if (et == null) {
return state.Operation(
operatorName
);
}
return state.BinaryOperation(et.Value);
}
示例5: MakeTryGetTypeMember
internal static MethodCallExpression MakeTryGetTypeMember(PythonContext/*!*/ PythonContext, PythonTypeSlot dts, ParameterExpression tmp, Expression instance, Expression pythonType) {
return Ast.Call(
PythonTypeInfo._PythonOps.SlotTryGetBoundValue,
AstUtils.Constant(PythonContext.SharedContext),
AstUtils.Convert(Utils.WeakConstant(dts), typeof(PythonTypeSlot)),
AstUtils.Convert(instance, typeof(object)),
AstUtils.Convert(
pythonType,
typeof(PythonType)
),
tmp
);
}
示例6: TryGetStaticFunction
/// <summary>
/// Tries to get the BuiltinFunction for the given name on the type of the provided MetaObject.
///
/// Succeeds if the MetaObject is a BuiltinFunction or BuiltinMethodDescriptor.
/// </summary>
internal static bool TryGetStaticFunction(PythonContext/*!*/ state, string op, DynamicMetaObject/*!*/ mo, out BuiltinFunction function) {
PythonType type = MetaPythonObject.GetPythonType(mo);
function = null;
if (!String.IsNullOrEmpty(op)) {
PythonTypeSlot xSlot;
object val;
if (type.TryResolveSlot(state.SharedContext, op, out xSlot) &&
xSlot.TryGetValue(state.SharedContext, null, type, out val)) {
function = TryConvertToBuiltinFunction(val);
if (function == null) return false;
}
}
return true;
}
示例7: PythonBinder
public PythonBinder(ScriptDomainManager manager, PythonContext/*!*/ pythonContext, CodeContext context)
: base(manager) {
ContractUtils.RequiresNotNull(pythonContext, "pythonContext");
_context = pythonContext;
if (context != null) {
context.LanguageContext.DomainManager.AssemblyLoaded += new EventHandler<AssemblyLoadedEventArgs>(DomainManager_AssemblyLoaded);
foreach (Assembly asm in pythonContext.DomainManager.GetLoadedAssemblyList()) {
DomainManager_AssemblyLoaded(this, new AssemblyLoadedEventArgs(asm));
}
}
EmptyGetMemberAction = OldGetMemberAction.Make(this, String.Empty);
}
示例8: SlotCallable
public SlotCallable(PythonContext/*!*/ binder, PythonIndexType op, PythonTypeSlot slot)
: base(binder, op) {
_slot = slot;
}
示例9: BuiltinCallable
public BuiltinCallable(PythonContext/*!*/ binder, PythonIndexType op, BuiltinFunction/*!*/ func)
: base(binder, op) {
Assert.NotNull(func);
_bf = func;
}
示例10: MakeCallable
/// <summary>
/// Creates a new CallableObject. If BuiltinFunction is available we'll create a BuiltinCallable otherwise
/// we create a SlotCallable.
/// </summary>
public static Callable MakeCallable(PythonContext/*!*/ binder, PythonIndexType op, BuiltinFunction itemFunc, PythonTypeSlot itemSlot) {
if (itemFunc != null) {
// we'll call a builtin function to produce the rule
return new BuiltinCallable(binder, op, itemFunc);
} else if (itemSlot != null) {
// we'll call a PythonTypeSlot to produce the rule
return new SlotCallable(binder, op, itemSlot);
}
return null;
}
示例11: Callable
protected Callable(PythonContext/*!*/ binder, PythonIndexType op) {
Assert.NotNull(binder);
_binder = binder;
_op = op;
}
示例12: MakeOneTarget
private static bool MakeOneTarget(PythonContext/*!*/ state, SlotOrFunction/*!*/ target, PythonTypeSlot slotTarget, ConditionalBuilder/*!*/ bodyBuilder, bool reverse, DynamicMetaObject/*!*/[]/*!*/ types) {
if (target == SlotOrFunction.Empty && slotTarget == null) return true;
if (slotTarget != null) {
MakeSlotCall(state, types, bodyBuilder, slotTarget, reverse);
return true;
} else if (target.MaybeNotImplemented) {
Debug.Assert(target.ReturnType == typeof(object));
ParameterExpression tmp = Ast.Variable(typeof(object), "slot");
bodyBuilder.AddVariable(tmp);
bodyBuilder.AddCondition(
Ast.NotEqual(
Ast.Assign(
tmp,
target.Target.Expression
),
Ast.Property(null, typeof(PythonOps).GetProperty("NotImplemented"))
),
tmp
);
return true;
} else {
bodyBuilder.FinishCondition(target.Target.Expression, typeof(object));
return false;
}
}
示例13: HashConvertToInt
private static DynamicExpression/*!*/ HashConvertToInt(PythonContext/*!*/ state, Expression/*!*/ expression) {
return DynamicExpression.Dynamic(
state.Convert(
typeof(int),
ConversionResultKind.ExplicitCast
),
typeof(int),
expression
);
}
示例14: GetGetOrDeleteSlice
private static DynamicMetaObject/*!*/ GetGetOrDeleteSlice(PythonContext state, DynamicMetaObject/*!*/[]/*!*/ args) {
DynamicMetaObject[] newArgs = (DynamicMetaObject[])args.Clone();
for (int i = 1; i < newArgs.Length; i++) {
if (!IsIndexType(state, newArgs[i])) {
newArgs[i] = newArgs[i].Restrict(newArgs[i].GetLimitType());
}
}
return new DynamicMetaObject(
Ast.Call(
typeof(PythonOps).GetMethod("MakeSlice"),
AstUtils.Convert(GetGetOrDeleteParameter(newArgs, 1), typeof(object)),
AstUtils.Convert(GetGetOrDeleteParameter(newArgs, 2), typeof(object)),
AstUtils.Convert(GetGetOrDeleteParameter(newArgs, 3), typeof(object))
),
BindingRestrictions.Combine(newArgs)
);
}
示例15: MakeRule
public override DynamicMetaObject/*!*/ MakeRule(DynamicMetaObjectBinder/*!*/ metaBinder, PythonContext/*!*/ binder, DynamicMetaObject/*!*/[]/*!*/ args) {
DynamicMetaObject[] tupleArgs = Callable.GetTupleArguments(args);
return Callable.CompleteRuleTarget(metaBinder, tupleArgs, delegate() {
PythonTypeSlot indexSlot;
if (args[1].GetLimitType() != typeof(Slice) && GetTypeAt(1).TryResolveSlot(binder.SharedContext, "__index__", out indexSlot)) {
args[1] = new DynamicMetaObject(
DynamicExpression.Dynamic(
binder.Convert(
typeof(int),
ConversionResultKind.ExplicitCast
),
typeof(int),
DynamicExpression.Dynamic(
binder.InvokeNone,
typeof(object),
AstUtils.Constant(binder.SharedContext),
Binders.Get(
AstUtils.Constant(binder.SharedContext),
binder,
typeof(object),
"__index__",
args[1].Expression
)
)
),
BindingRestrictions.Empty
);
return Callable.CompleteRuleTarget(metaBinder, tupleArgs, null);
}
return null;
});
}