本文整理汇总了C#中IronRuby.Runtime.Calls.MetaObjectBuilder.AddTypeRestriction方法的典型用法代码示例。如果您正苦于以下问题:C# MetaObjectBuilder.AddTypeRestriction方法的具体用法?C# MetaObjectBuilder.AddTypeRestriction怎么用?C# MetaObjectBuilder.AddTypeRestriction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IronRuby.Runtime.Calls.MetaObjectBuilder
的用法示例。
在下文中一共展示了MetaObjectBuilder.AddTypeRestriction方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildConversion
internal static void BuildConversion(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args)
{
const string ToS = "to_s";
if (TryImplicitConversion(metaBuilder, args)) {
metaBuilder.AddTypeRestriction(args.Target.GetType(), args.TargetExpression);
return;
}
RubyMemberInfo conversionMethod, methodMissing = null;
RubyClass targetClass = args.RubyContext.GetImmediateClassOf(args.Target);
using (targetClass.Context.ClassHierarchyLocker()) {
metaBuilder.AddTargetTypeTest(args.Target, targetClass, args.TargetExpression, args.MetaContext,
new[] { ToS, Symbols.MethodMissing }
);
conversionMethod = targetClass.ResolveMethodForSiteNoLock(ToS, VisibilityContext.AllVisible).Info;
// find method_missing - we need to add "to_s" method to the missing methods table:
if (conversionMethod == null) {
methodMissing = targetClass.ResolveMethodMissingForSite(ToS, RubyMethodVisibility.None);
}
}
// invoke target.to_s and if successful convert the result to string unless it is already:
if (conversionMethod != null) {
conversionMethod.BuildCall(metaBuilder, args, ToS);
} else {
RubyCallAction.BuildMethodMissingCall(metaBuilder, args, ToS, methodMissing, RubyMethodVisibility.None, false, true);
}
if (metaBuilder.Error) {
return;
}
metaBuilder.Result = Methods.ToSDefaultConversion.OpCall(
AstUtils.Convert(args.MetaContext.Expression, typeof(RubyContext)),
AstUtils.Box(args.TargetExpression),
AstUtils.Box(metaBuilder.Result)
);
}
示例2: Build
protected override void Build(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args) {
const string ToS = "to_s";
// no conversion for a subclass of string:
var stringTarget = args.Target as MutableString;
if (stringTarget != null) {
metaBuilder.AddTypeRestriction(args.Target.GetType(), args.TargetExpression);
metaBuilder.Result = AstUtils.Convert(args.TargetExpression, typeof(MutableString));
return;
}
RubyMemberInfo conversionMethod, methodMissing = null;
RubyClass targetClass = args.RubyContext.GetImmediateClassOf(args.Target);
using (targetClass.Context.ClassHierarchyLocker()) {
metaBuilder.AddTargetTypeTest(args.Target, targetClass, args.TargetExpression, args.MetaContext);
conversionMethod = targetClass.ResolveMethodForSiteNoLock(ToS, RubyClass.IgnoreVisibility).Info;
// find method_missing - we need to add "to_xxx" methods to the missing methods table:
if (conversionMethod == null) {
methodMissing = targetClass.ResolveMethodMissingForSite(ToS, RubyMethodVisibility.None);
}
}
// invoke target.to_s and if successful convert the result to string unless it is already:
if (conversionMethod != null) {
conversionMethod.BuildCall(metaBuilder, args, ToS);
if (metaBuilder.Error) {
return;
}
} else {
RubyCallAction.BindToMethodMissing(metaBuilder, args, ToS, methodMissing, RubyMethodVisibility.None, false, true);
}
metaBuilder.Result = Methods.ToSDefaultConversion.OpCall(
AstUtils.Convert(args.MetaContext.Expression, typeof(RubyContext)),
AstFactory.Box(args.TargetExpression),
AstFactory.Box(metaBuilder.Result)
);
}
示例3: FallbackInvoke
public override DynamicMetaObject/*!*/ FallbackInvoke(DynamicMetaObject/*!*/ target, DynamicMetaObject/*!*/[]/*!*/ args,
DynamicMetaObject errorSuggestion) {
// Used in combination with GetMember to compose InvokeMember operation.
// Gets here only if the target is not a callable meta-object.
var metaBuilder = new MetaObjectBuilder(this, target, args);
var callArgs = new CallArguments(_context, target, args, CallInfo);
metaBuilder.AddTypeRestriction(target.GetLimitType(), target.Expression);
var normalizedArgs = RubyOverloadResolver.NormalizeArguments(metaBuilder, callArgs, 0, 0);
if (!metaBuilder.Error) {
// no arguments => just return the target:
metaBuilder.Result = target.Expression;
} else {
// any arguments found (expected none):
metaBuilder.SetMetaResult(errorSuggestion, false);
}
return metaBuilder.CreateMetaObject(this);
}
示例4: BuildInvoke
internal void BuildInvoke(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args) {
Assert.NotNull(metaBuilder, args);
var convertedTarget = AstUtils.Convert(args.TargetExpression, typeof(Proc));
// test for target type:
metaBuilder.AddTypeRestriction(args.Target.GetType(), args.TargetExpression);
BuildCall(
metaBuilder,
convertedTarget, // proc object
Methods.GetProcSelf.OpCall(convertedTarget), // self captured by the block closure
args
);
}
示例5: MarshalArgument
private Expression/*!*/ MarshalArgument(MetaObjectBuilder/*!*/ metaBuilder, DynamicMetaObject/*!*/ arg, ArgType parameterType) {
object value = arg.Value;
if (value == null) {
metaBuilder.AddRestriction(Ast.Equal(arg.Expression, AstUtils.Constant(null)));
} else {
metaBuilder.AddTypeRestriction(value.GetType(), arg.Expression);
}
switch (parameterType) {
case ArgType.Buffer:
if (value == null) {
return AstUtils.Constant(null, typeof(byte[]));
}
if (value is int && (int)value == 0) {
metaBuilder.AddRestriction(Ast.Equal(AstUtils.Convert(arg.Expression, typeof(int)), AstUtils.Constant(0)));
return AstUtils.Constant(null, typeof(byte[]));
}
if (value.GetType() == typeof(MutableString)) {
return Methods.GetMutableStringBytes.OpCall(
AstUtils.Convert(arg.Expression, typeof(MutableString))
);
}
return Methods.GetMutableStringBytes.OpCall(
AstUtils.LightDynamic(ConvertToStrAction.Make(_context), typeof(MutableString), arg.Expression)
);
case ArgType.Int32:
if (value is int) {
return AstUtils.Convert(arg.Expression, typeof(int));
}
return Ast.Convert(
Ast.Call(
AstUtils.LightDynamic(ConvertToIntAction.Make(_context), typeof(IntegerValue), arg.Expression),
Methods.IntegerValue_ToUInt32Unchecked
),
typeof(int)
);
}
throw Assert.Unreachable;
}
示例6: BuildInvoke
/// <summary>
/// "yields" to the proc.
/// </summary>
internal void BuildInvoke(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args) {
Assert.NotNull(metaBuilder, args);
Debug.Assert(!args.Signature.HasBlock);
var convertedTarget = AstUtils.Convert(args.TargetExpression, typeof(BlockParam));
// test for target type:
metaBuilder.AddTypeRestriction(args.Target.GetType(), args.TargetExpression);
metaBuilder.Result = AstFactory.YieldExpression(
args.GetSimpleArgumentExpressions(),
args.GetSplattedArgumentExpression(),
args.GetRhsArgumentExpression(),
convertedTarget, // block param
Ast.Property(convertedTarget, SelfProperty) // self
);
}
示例7: TryBuildConversionToDelegate
internal static bool TryBuildConversionToDelegate(MetaObjectBuilder/*!*/ metaBuilder, RubyMetaObject/*!*/ metaTarget, Type/*!*/ delegateType, MethodInfo/*!*/ delegateFactory) {
MethodInfo invoke;
if (!typeof(Delegate).IsAssignableFrom(delegateType) || (invoke = delegateType.GetMethod("Invoke")) == null) {
return false;
}
var type = metaTarget.Value.GetType();
metaBuilder.AddTypeRestriction(type, metaTarget.Expression);
metaBuilder.Result = delegateFactory.OpCall(AstUtils.Constant(delegateType), Ast.Convert(metaTarget.Expression, type));
return true;
}
示例8: SetCallActionRule
internal static void SetCallActionRule(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args, bool testTarget) {
Assert.NotNull(metaBuilder, args);
var convertedTarget = AstUtils.Convert(args.TargetExpression, typeof(Proc));
// test for target type:
if (testTarget) {
metaBuilder.AddTypeRestriction(args.Target.GetType(), args.TargetExpression);
}
SetProcCallRule(
metaBuilder,
convertedTarget, // proc object
Ast.Property(convertedTarget, SelfProperty), // self captured by the block closure
null,
args
);
}