本文整理汇总了C#中PythonContext.Invoke方法的典型用法代码示例。如果您正苦于以下问题:C# PythonContext.Invoke方法的具体用法?C# PythonContext.Invoke怎么用?C# PythonContext.Invoke使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PythonContext
的用法示例。
在下文中一共展示了PythonContext.Invoke方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MakeSlotCallWorker
private static void MakeSlotCallWorker(PythonContext/*!*/ state, PythonTypeSlot/*!*/ slotTarget, Expression/*!*/ self, ConditionalBuilder/*!*/ bodyBuilder, params Expression/*!*/[]/*!*/ args) {
// Generate:
//
// SlotTryGetValue(context, slot, selfType, out callable) && (tmp=callable(args)) != NotImplemented) ?
// tmp :
// RestOfOperation
//
ParameterExpression callable = Ast.Variable(typeof(object), "slot");
ParameterExpression tmp = Ast.Variable(typeof(object), "slot");
bodyBuilder.AddCondition(
Ast.AndAlso(
Ast.Call(
typeof(PythonOps).GetMethod("SlotTryGetValue"),
AstUtils.Constant(state.SharedContext),
AstUtils.Convert(Utils.WeakConstant(slotTarget), typeof(PythonTypeSlot)),
AstUtils.Convert(self, typeof(object)),
Ast.Call(
typeof(DynamicHelpers).GetMethod("GetPythonType"),
AstUtils.Convert(self, typeof(object))
),
callable
),
Ast.NotEqual(
Ast.Assign(
tmp,
DynamicExpression.Dynamic(
state.Invoke(
new CallSignature(args.Length)
),
typeof(object),
ArrayUtils.Insert(AstUtils.Constant(state.SharedContext), (Expression)callable, args)
)
),
Ast.Property(null, typeof(PythonOps).GetProperty("NotImplemented"))
)
),
tmp
);
bodyBuilder.AddVariable(callable);
bodyBuilder.AddVariable(tmp);
}
示例2: InvokeKeywords
/// <summary>
/// Creates a new InvokeBinder which will call with positional and keyword splatting.
///
/// The signature of the target site should be object(function), object[], dictionary, retType
/// </summary>
public static PythonInvokeBinder/*!*/ InvokeKeywords(PythonContext/*!*/ state) {
return state.Invoke(
new CallSignature(new Argument(ArgumentType.List), new Argument(ArgumentType.Dictionary))
);
}
示例3: GetSlotOrFunction
public static SlotOrFunction/*!*/ GetSlotOrFunction(PythonContext/*!*/ state, string op, params DynamicMetaObject[] types) {
PythonTypeSlot slot;
SlotOrFunction res;
if (TryGetBinder(state, types, op, null, out res)) {
if (res != SlotOrFunction.Empty) {
return res;
}
} else if (MetaUserObject.GetPythonType(types[0]).TryResolveSlot(state.SharedContext, op, out slot)) {
ParameterExpression tmp = Ast.Variable(typeof(object), "slotVal");
Expression[] args = new Expression[types.Length - 1];
for (int i = 1; i < types.Length; i++) {
args[i - 1] = types[i].Expression;
}
return new SlotOrFunction(
new DynamicMetaObject(
Ast.Block(
new ParameterExpression[] { tmp },
MetaPythonObject.MakeTryGetTypeMember(
state,
slot,
tmp,
types[0].Expression,
Ast.Call(
typeof(DynamicHelpers).GetMethod("GetPythonType"),
types[0].Expression
)
),
Ast.Dynamic(
state.Invoke(
new CallSignature(args.Length)
),
typeof(object),
ArrayUtils.Insert<Expression>(
AstUtils.Constant(state.SharedContext),
tmp,
args
)
)
),
BindingRestrictions.Combine(types).Merge(BindingRestrictionsHelpers.GetRuntimeTypeRestriction(types[0].Expression, types[0].GetLimitType()))
),
slot
);
}
return SlotOrFunction.Empty;
}
示例4: InvokeSplat
/// <summary>
/// Creates a new InvokeBinder which will call with positional splatting.
///
/// The signature of the target site should be object(function), object[], retType
/// </summary>
/// <param name="state"></param>
/// <returns></returns>
public static PythonInvokeBinder/*!*/ InvokeSplat(PythonContext/*!*/ state) {
return state.Invoke(
new CallSignature(new Argument(ArgumentType.List))
);
}
示例5: Invoke
public static Expression/*!*/ Invoke(Expression codeContext, PythonContext/*!*/ binder, Type/*!*/ resultType, CallSignature signature, params Expression/*!*/[]/*!*/ args) {
return Ast.Dynamic(
binder.Invoke(
signature
),
resultType,
ArrayUtils.Insert(codeContext, args)
);
}