本文整理汇总了C#中IronRuby.Runtime.Calls.MetaObjectBuilder.CreateMetaObject方法的典型用法代码示例。如果您正苦于以下问题:C# MetaObjectBuilder.CreateMetaObject方法的具体用法?C# MetaObjectBuilder.CreateMetaObject怎么用?C# MetaObjectBuilder.CreateMetaObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IronRuby.Runtime.Calls.MetaObjectBuilder
的用法示例。
在下文中一共展示了MetaObjectBuilder.CreateMetaObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Bind
public override DynamicMetaObject/*!*/ Bind(DynamicMetaObject/*!*/ scopeOrContextOrTarget, DynamicMetaObject/*!*/[]/*!*/ args) {
var callArgs = new CallArguments(_context, scopeOrContextOrTarget, args, Signature);
var metaBuilder = new MetaObjectBuilder(this, args);
if (IsForeignMetaObject(callArgs.MetaTarget)) {
return InteropBind(metaBuilder, callArgs);
}
Build(metaBuilder, callArgs, true);
return metaBuilder.CreateMetaObject(this);
}
示例2: Bind
public override DynamicMetaObject/*!*/ Bind(DynamicMetaObject/*!*/ context, DynamicMetaObject/*!*/[]/*!*/ args) {
var callArgs = new CallArguments(context, args, Signature);
// TODO: COM interop
if (IsForeignMetaObject(callArgs.MetaTarget)) {
return InteropBind(callArgs);
}
var metaBuilder = new MetaObjectBuilder();
Build(metaBuilder, callArgs);
return metaBuilder.CreateMetaObject(this);
}
示例3: 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);
}
示例4: BindInvoke
public override MetaObject/*!*/ BindInvoke(InvokeBinder/*!*/ action, MetaObject/*!*/[]/*!*/ args) {
RubyCallSignature callSignature;
if (RubyCallSignature.TryCreate(action.Arguments, out callSignature)) {
return action.FallbackInvoke(this, args);
}
var context = new MetaObject(
Methods.GetContextFromProc.OpCall(AstUtils.Convert(Expression, typeof(Proc))),
Restrictions.Empty,
RubyOps.GetContextFromProc((Proc)Value)
);
var metaBuilder = new MetaObjectBuilder();
Proc.SetCallActionRule(metaBuilder, new CallArguments(context, this, args, callSignature), true);
return metaBuilder.CreateMetaObject(action, args);
}
示例5: TryBind
public static DynamicMetaObject TryBind(RubyContext/*!*/ context, InvokeMemberBinder/*!*/ binder, DynamicMetaObject/*!*/ target, DynamicMetaObject/*!*/[]/*!*/ args) {
Assert.NotNull(context, target);
var metaBuilder = new MetaObjectBuilder();
RubyCallAction.Bind(metaBuilder, binder.Name,
new CallArguments(
new DynamicMetaObject(AstUtils.Constant(context), BindingRestrictions.Empty, context),
target,
args,
RubyCallSignature.Simple(binder.CallInfo.ArgumentCount)
)
);
// TODO: we should return null if we fail, we need to throw exception for now:
return metaBuilder.CreateMetaObject(binder, DynamicMetaObject.EmptyMetaObjects);
}
示例6: TryBind
public static DynamicMetaObject TryBind(RubyContext/*!*/ context, CreateInstanceBinder/*!*/ binder, DynamicMetaObject/*!*/ target, DynamicMetaObject/*!*/[]/*!*/ args) {
Assert.NotNull(context, binder, target, args);
var metaBuilder = new MetaObjectBuilder();
RubyCallAction.Bind(metaBuilder, "new",
new CallArguments(
new DynamicMetaObject(AstUtils.Constant(context), BindingRestrictions.Empty, context),
target,
args,
RubyCallSignature.Simple(args.Length)
)
);
// TODO: we should return null if we fail, we need to throw exception due to version update optimization:
return metaBuilder.CreateMetaObject(binder, DynamicMetaObject.EmptyMetaObjects);
}
示例7: BindInvoke
public override DynamicMetaObject/*!*/ BindInvoke(InvokeBinder/*!*/ action, DynamicMetaObject/*!*/[]/*!*/ args) {
RubyCallSignature callSignature;
if (RubyCallSignature.TryCreate(action.Arguments, out callSignature)) {
return action.FallbackInvoke(this, args);
}
var self = (RubyMethod)Value;
var context = new DynamicMetaObject(
Methods.GetContextFromMethod.OpCall(AstUtils.Convert(Expression, typeof(RubyMethod))),
BindingRestrictions.Empty,
RubyOps.GetContextFromMethod(self)
);
var metaBuilder = new MetaObjectBuilder();
Method.SetRuleForCall(metaBuilder, new CallArguments(context, this, args, callSignature));
return metaBuilder.CreateMetaObject(action, args);
}
示例8: Bind
public static DynamicMetaObject/*!*/ Bind(DynamicMetaObject/*!*/ context, string/*!*/ methodName, CallInfo/*!*/ callInfo,
DynamicMetaObjectBinder/*!*/ binder, DynamicMetaObject/*!*/ target, DynamicMetaObject/*!*/[]/*!*/ args,
Func<DynamicMetaObject, DynamicMetaObject[], DynamicMetaObject>/*!*/ fallback) {
Debug.Assert(fallback != null);
var callArgs = new CallArguments(context, target, args, RubyCallSignature.Interop(callInfo.ArgumentCount));
var metaBuilder = new MetaObjectBuilder(target, args);
if (!RubyCallAction.BuildCall(metaBuilder, methodName, callArgs, false, false)) {
metaBuilder.SetMetaResult(fallback(target, args), false);
}
return metaBuilder.CreateMetaObject(binder);
}
示例9: InteropBind
protected override DynamicMetaObject/*!*/ InteropBind(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args) {
metaBuilder.SetError(Ast.New(
typeof(NotSupportedException).GetConstructor(new[] { typeof(string) }),
Ast.Constant("Super call not supported on foreign meta-objects")
));
return metaBuilder.CreateMetaObject(this);
}
示例10: FallbackInvokeMember
internal static DynamicMetaObject FallbackInvokeMember(IInteropBinder/*!*/ binder, string/*!*/ methodName, CallInfo/*!*/ callInfo,
DynamicMetaObject/*!*/ target, DynamicMetaObject/*!*/[]/*!*/ args, DynamicMetaObject errorSuggestion) {
var metaBuilder = new MetaObjectBuilder(binder, target, args);
var callArgs = new CallArguments(binder.Context, target, args, callInfo);
if (!RubyCallAction.BuildCall(metaBuilder, methodName, callArgs, errorSuggestion == null, true)) {
Debug.Assert(errorSuggestion != null);
// method wasn't found so we didn't do any operation with arguments that would require restrictions converted to conditions:
metaBuilder.SetMetaResult(errorSuggestion, false);
}
return metaBuilder.CreateMetaObject((DynamicMetaObjectBinder)binder);
}
示例11: InteropBind
private DynamicMetaObject/*!*/ InteropBind(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args) {
// TODO: argument count limit depends on the binder!
// TODO: pass block as the last (before RHS arg?) parameter/ignore block if args not accepting block:
var normalizedArgs = RubyOverloadResolver.NormalizeArguments(metaBuilder, args, 0, Int32.MaxValue);
if (!metaBuilder.Error) {
MethodInfo postConverter;
var interopBinder = GetInteropBinder(args.RubyContext, normalizedArgs, out postConverter);
if (interopBinder != null) {
Type resultType;
var result = interopBinder.Bind(args.MetaTarget, ArrayUtils.MakeArray(normalizedArgs));
metaBuilder.SetMetaResult(result, args);
if (postConverter != null) {
// TODO: do better?
var paramType = postConverter.GetParameters()[0].ParameterType;
metaBuilder.Result = Ast.Call(null, postConverter, AstUtils.Convert(metaBuilder.Result, paramType));
resultType = postConverter.ReturnType;
} else {
resultType = ((IInteropBinder)interopBinder).ResultType;
}
return metaBuilder.CreateMetaObject(interopBinder, resultType);
} else {
metaBuilder.SetError(Ast.New(
typeof(NotSupportedException).GetConstructor(new[] { typeof(string) }),
Ast.Constant(String.Format("{0} not supported on foreign meta-objects", this))
));
}
}
return metaBuilder.CreateMetaObject(this);
}
示例12: TryBind
public static MetaObject TryBind(RubyContext/*!*/ context, GetMemberBinder/*!*/ binder, MetaObject/*!*/ target) {
Assert.NotNull(context, target);
var metaBuilder = new MetaObjectBuilder();
var contextExpression = Ast.Constant(context);
metaBuilder.AddTargetTypeTest(target.Value, target.Expression, context, contextExpression);
RubyMemberInfo method = context.ResolveMethod(target.Value, binder.Name, true).InvalidateSitesOnOverride();
if (method != null && RubyModule.IsMethodVisible(method, false)) {
// we need to create a bound member:
metaBuilder.Result = Ast.Constant(new RubyMethod(target.Value, method, binder.Name));
} else {
// TODO:
// We need to throw an exception if we don't find method_missing so that our version update optimization works:
// This limits interop with other languages.
//
// class B CLR type with method 'foo'
// class C < B Ruby class
// x = C.new
//
// 1. x.GET("foo") from Ruby
// No method found or CLR method found -> fallback to Python
// Python might see its method foo or might just fallback to .NET,
// in any case it will add rule [1] with restriction on type of C w/o Ruby version check.
// 2. B.define_method("foo")
// This doesn't update C due to the optimization (there is no overridden method foo in C).
// 3. x.GET("foo") from Ruby
// This will not invoke the binder since the rule [1] is still valid.
//
object symbol = SymbolTable.StringToId(binder.Name);
RubyCallAction.BindToMethodMissing(metaBuilder, binder.Name,
new CallArguments(
new MetaObject(contextExpression, Restrictions.Empty, context),
new[] {
target,
new MetaObject(Ast.Constant(symbol), Restrictions.Empty, symbol)
},
RubyCallSignature.Simple(1)
),
method != null
);
}
// TODO: we should return null if we fail, we need to throw exception for now:
return metaBuilder.CreateMetaObject(binder, MetaObject.EmptyMetaObjects);
}
示例13: TryBind
public static DynamicMetaObject TryBind(RubyContext/*!*/ context, GetMemberBinder/*!*/ binder, DynamicMetaObject/*!*/ target) {
Assert.NotNull(context, target);
var metaBuilder = new MetaObjectBuilder();
var contextExpression = AstUtils.Constant(context);
RubyClass targetClass = context.GetImmediateClassOf(target.Value);
MethodResolutionResult method;
RubyMemberInfo methodMissing = null;
using (targetClass.Context.ClassHierarchyLocker()) {
metaBuilder.AddTargetTypeTest(target.Value, targetClass, target.Expression, context, contextExpression);
method = targetClass.ResolveMethodForSiteNoLock(binder.Name, RubyClass.IgnoreVisibility);
if (method.Found) {
methodMissing = targetClass.ResolveMethodForSiteNoLock(Symbols.MethodMissing, RubyClass.IgnoreVisibility).Info;
}
}
if (method.Found) {
// we need to create a bound member:
metaBuilder.Result = AstUtils.Constant(new RubyMethod(target.Value, method.Info, binder.Name));
} else {
// TODO:
// We need to throw an exception if we don't find method_missing so that our version update optimization works:
// This limits interop with other languages.
//
// class B CLR type with method 'foo'
// class C < B Ruby class
// x = C.new
//
// 1. x.GET("foo") from Ruby
// No method found or CLR method found -> fallback to Python
// Python might see its method foo or might just fallback to .NET,
// in any case it will add rule [1] with restriction on type of C w/o Ruby version check.
// 2. B.define_method("foo")
// This doesn't update C due to the optimization (there is no overridden method foo in C).
// 3. x.GET("foo") from Ruby
// This will not invoke the binder since the rule [1] is still valid.
//
object symbol = SymbolTable.StringToId(binder.Name);
RubyCallAction.BindToMethodMissing(metaBuilder,
new CallArguments(
new DynamicMetaObject(contextExpression, BindingRestrictions.Empty, context),
new[] {
target,
new DynamicMetaObject(AstUtils.Constant(symbol), BindingRestrictions.Empty, symbol)
},
RubyCallSignature.Simple(1)
),
binder.Name,
methodMissing,
method.IncompatibleVisibility,
false
);
}
// TODO: we should return null if we fail, we need to throw exception for now:
return metaBuilder.CreateMetaObject(binder, DynamicMetaObject.EmptyMetaObjects);
}
示例14: FallbackGetMember
public override DynamicMetaObject/*!*/ FallbackGetMember(DynamicMetaObject/*!*/ target, DynamicMetaObject errorSuggestion) {
if (_unmangled != null) {
// TODO: errorSuggestion?
return _unmangled.Bind(target, DynamicMetaObject.EmptyMetaObjects);
}
#if !SILVERLIGHT
DynamicMetaObject result;
if (Microsoft.Scripting.ComInterop.ComBinder.TryBindGetMember(this, target, out result)) {
return result;
}
#endif
var metaBuilder = new MetaObjectBuilder(target);
var callArgs = new CallArguments(_context, target, DynamicMetaObject.EmptyMetaObjects, _CallInfo);
if (!RubyCallAction.BuildAccess(metaBuilder, _originalName ?? Name, callArgs, errorSuggestion == null, true)) {
Debug.Assert(errorSuggestion != null);
metaBuilder.SetMetaResult(errorSuggestion, false);
}
return metaBuilder.CreateMetaObject(this);
}
示例15: InteropBind
protected override DynamicMetaObject/*!*/ InteropBind(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args) {
// TODO: pass block as the last parameter (before RHS arg?):
var normalizedArgs = RubyMethodGroupBase.NormalizeArguments(metaBuilder, args, SelfCallConvention.NoSelf, false, false);
var callInfo = new CallInfo(normalizedArgs.Length);
var interopBinder = GetInteropBinder(args.RubyContext, callInfo);
var result = interopBinder.Bind(args.MetaTarget, normalizedArgs);
metaBuilder.SetMetaResult(result, args);
return metaBuilder.CreateMetaObject(interopBinder);
}