本文整理汇总了C#中System.Dynamic.InvokeBinder类的典型用法代码示例。如果您正苦于以下问题:C# InvokeBinder类的具体用法?C# InvokeBinder怎么用?C# InvokeBinder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InvokeBinder类属于System.Dynamic命名空间,在下文中一共展示了InvokeBinder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryInvoke
public override bool TryInvoke(InvokeBinder binder, object[] args, out object result)
{
if (binder == null) throw new ArgumentNullException("binder");
if (Resource(args, out result))
return true;
if (Query(args, out result))
return true;
if (Extensions.IsHttpVerb(GetLastCall()))
{
result = HttpVerb(args);
return true;
}
var builder = new StringBuilder(_callLog);
foreach (var t in args)
{
builder.Append("/");
var s = t as string;
if (s != null)
builder.Append("@\"").Append(s.Replace("\"", "\"\"")).Append("\"");
else
builder.Append(t);
}
result = new MemberAccessWrapper(_httpClientWrapper, _baseUri, builder.ToString());
return true;
}
示例2: BindInvoke
public override Meta BindInvoke(InvokeBinder binder, Meta[] args)
{
return new Meta(
Et.Call(
EtUtils.Cast<IFunction>(
this.Expression
),
IFunctionMethods.MiCall,
EtUtils.Cast<IObj>(
args[0].Expression
),
AstUtils.NewArrayHelper(
typeof(object),
DynamicUtils.GetExpressions(
ArrayUtils.RemoveFirst(args)
)
)
),
RestrictUtils.BuildCallRestrictions(
this,
args,
RestrictFlag.Type
)
);
}
示例3: DelegateInfo
internal DelegateInfo(LanguageContext context, Type returnType, ParameterInfo[] parameters) {
Assert.NotNull(returnType);
Assert.NotNullItems(parameters);
_returnType = returnType;
_parameters = parameters;
PerfTrack.NoteEvent(PerfTrack.Categories.DelegateCreate, ToString());
if (_returnType != typeof(void)) {
_convertBinder = context.CreateConvertBinder(_returnType, true);
}
_invokeBinder = context.CreateInvokeBinder(new CallInfo(_parameters.Length));
Type[] delegateParams = new Type[_parameters.Length];
for (int i = 0; i < _parameters.Length; i++) {
delegateParams[i] = _parameters[i].ParameterType;
}
// Create the method with a special name so the langauge compiler knows that method's stack frame is not visible
DynamicILGen cg = Snippets.Shared.CreateDynamicMethod("_Scripting_", _returnType, ArrayUtils.Insert(typeof(object[]), delegateParams), false);
// Emit the stub
_constants = EmitClrCallStub(cg);
_method = cg.Finish();
}
示例4: TryInvoke
public override bool TryInvoke(InvokeBinder binder, object[] args, out object result)
{
output.Write(string.Format("Try invoke with {0} arguments {1} and return type is {2}",
binder.CallInfo.ArgumentCount, string.Join(", ", binder.CallInfo.ArgumentNames), binder.ReturnType.FullName));
var res = baseElement.TryInvoke(binder, args, out result);
return true;
}
示例5: TryInvoke
public override bool TryInvoke(InvokeBinder binder, object[] args, out object result)
{
var innerResult = _inner.TryInvoke(binder, args, out result);
//special case, we need to check if the result is of a non-legacy dynamic type because if it is, we need
//to return the legacy type
result = LegacyConverter.ConvertToLegacy(result);
return innerResult;
}
示例6: TryInvoke
public override bool TryInvoke(InvokeBinder binder, object[] args, out object result)
{
Console.WriteLine("TryInvoke is called");
bool tryResult = base.TryInvoke(binder, args, out result);
return true;
}
示例7: ParseArgs
public static ImmutableDictionary<string, object> ParseArgs(object[] args, InvokeBinder binder)
{
if (binder.CallInfo.ArgumentCount == 0) return Empty;
if (binder.CallInfo.ArgumentCount == 1 && (binder.CallInfo.ArgumentNames.Count == 0 || string.IsNullOrWhiteSpace(binder.CallInfo.ArgumentNames[0])))
{
return ObjectToDictionary(args[0]);
}
return ArgsToDictionary(args, binder);
}
示例8: BindInvoke
public override DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObject[] args)
{
return new DynamicMetaObject(
Expression.Call(
Expression.Constant(Function),
typeof(BonsaiFunction).GetMethod("Call"),
Expression.NewArrayInit(typeof(object), args.Select(a => Expression.Convert(a.Expression, typeof(object))))),
BindingRestrictions.GetInstanceRestriction(this.Expression, Function));
}
示例9: TryBindInvoke
/// <summary>
/// Tries to perform binding of the dynamic invoke operation.
/// </summary>
/// <param name="binder">An instance of the <see cref="GetMemberBinder"/> that represents the details of the dynamic operation.</param>
/// <param name="instance">The target of the dynamic operation. </param>
/// <param name="args">An array of <see cref="DynamicMetaObject"/> instances - arguments to the invoke member operation.</param>
/// <param name="result">The new <see cref="DynamicMetaObject"/> representing the result of the binding.</param>
/// <returns>true if operation was bound successfully; otherwise, false.</returns>
public static bool TryBindInvoke(InvokeBinder binder, DynamicMetaObject instance, DynamicMetaObject[] args, out DynamicMetaObject result) {
if (TryGetMetaObject(ref instance)) {
result = instance.BindInvoke(binder, args);
return true;
} else {
result = null;
return false;
}
}
示例10: TryInvoke
/// <summary>
/// Tries the invoke.
/// </summary>
/// <param name="binder">The binder.</param>
/// <param name="args">The args.</param>
/// <param name="result">The result.</param>
/// <returns></returns>
public override bool TryInvoke(InvokeBinder binder, object[] args, out object result)
{
result = null;
if (args.Length == 1 && args.First() is String)
{
result = _lookup(args[0] as String);
return true;
}
return false;
}
示例11: TryInvoke
public override bool TryInvoke(InvokeBinder binder, object[] args, out object result)
{
IodineObject[] arguments = new IodineObject[args.Length];
for (int i = 0; i < args.Length; i++) {
arguments [i] = typeRegistry.ConvertToIodineObject (args [i]);
}
IodineObject returnVal = internalObject.Invoke (internalVm, arguments);
result = typeRegistry.ConvertToNativeObject (returnVal);
return true;
}
示例12: TryInvoke
/// <summary>
/// Evaluates JavaScript directly within the context of the target object.
/// Particularly useful for expressing lambdas, but can be used to execute any JavaScript that cannot be expressed in C#.
/// </summary>
/// <example>
/// var visibleText = elements("filter(e => e.visible).map(e => e.textContent)");
/// </example>
public override bool TryInvoke(InvokeBinder binder, object[] args, out object result)
{
try
{
var script = "this." + args.Single().ToString();
result = target.eval(script).Result;
if (result is ExpandoObject) result = new Bridge(result);
return true;
}
catch (AggregateException e) { throw e.InnerException; }
}
示例13: TryInvoke
public override bool TryInvoke(InvokeBinder binder, object[] args, out object result)
{
if (!commands.Any())
{
result = null;
return true;
}
var runOptions = new RunOptions(this);
result = Runner.Run(runOptions);
return true;
}
示例14: BindInvoke
public override DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObject[] args) {
ContractUtils.RequiresNotNull(binder, "binder");
ComMethodDesc method;
if (_self.TryGetGetItem(out method)) {
bool[] isByRef = ComBinderHelpers.ProcessArgumentsForCom(ref args);
return BindComInvoke(args, method, binder.CallInfo, isByRef);
}
return base.BindInvoke(binder, args);
}
示例15: Bind
public static DynamicMetaObject/*!*/ Bind(RubyContext/*!*/ context, InvokeBinder/*!*/ binder,
RubyMetaObject/*!*/ target, DynamicMetaObject/*!*/[]/*!*/ args, Action<MetaObjectBuilder, CallArguments>/*!*/ buildInvoke) {
RubyCallSignature callSignature;
if (RubyCallSignature.TryCreate(binder.CallInfo, out callSignature)) {
return binder.FallbackInvoke(target, args);
}
var metaBuilder = new MetaObjectBuilder();
buildInvoke(metaBuilder, new CallArguments(target.CreateMetaContext(), target, args, callSignature));
return metaBuilder.CreateMetaObject(binder);
}