本文整理汇总了C#中RubyContext.GetClass方法的典型用法代码示例。如果您正苦于以下问题:C# RubyContext.GetClass方法的具体用法?C# RubyContext.GetClass怎么用?C# RubyContext.GetClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RubyContext
的用法示例。
在下文中一共展示了RubyContext.GetClass方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PrecInteger
public static object PrecInteger(
CallSiteStorage<Func<CallSite, RubyContext, object, RubyClass, object>>/*!*/ precStorage,
RubyContext/*!*/ context, object self) {
var prec = precStorage.GetCallSite("prec", 1);
return prec.Target(prec, context, self, context.GetClass(typeof(Integer)));
}
示例2: RubyRepresenter
public RubyRepresenter(RubyContext/*!*/ context, Serializer/*!*/ serializer, YamlOptions/*!*/ opts)
: base(serializer, opts) {
_context = context;
_objectToYamlMethod = context.GetClass(typeof(object)).ResolveMethod("to_yaml", VisibilityContext.AllVisible).Info;
_TagUri =
CallSite<Func<CallSite, object, object>>.Create(
RubyCallAction.Make(context, "taguri", RubyCallSignature.WithImplicitSelf(0))
);
_ToYamlStyle =
CallSite<Func<CallSite, object, object>>.Create(
RubyCallAction.Make(context, "to_yaml_style", RubyCallSignature.WithImplicitSelf(0))
);
_ToYamlNode =
CallSite<Func<CallSite, object, RubyRepresenter, object>>.Create(
RubyCallAction.Make(context, "to_yaml_node", RubyCallSignature.WithImplicitSelf(1))
);
_ToYaml =
CallSite<Func<CallSite, object, RubyRepresenter, object>>.Create(
RubyCallAction.Make(context, "to_yaml", RubyCallSignature.WithImplicitSelf(0))
);
_ToYamlProperties =
CallSite<Func<CallSite, object, object>>.Create(
RubyCallAction.Make(context, "to_yaml_properties", RubyCallSignature.WithImplicitSelf(0))
);
}
示例3: ToClass
public static RubyClass ToClass(RubyContext/*!*/ context, Type/*!*/ self)
{
if (self.IsInterface()) {
RubyExceptions.CreateTypeError("Cannot convert a CLR interface to a Ruby class");
}
return context.GetClass(self);
}
示例4: CreateDefaultTagMapping
private static Hash CreateDefaultTagMapping(RubyContext/*!*/ context) {
Hash taggedClasses = new Hash(context.EqualityComparer);
taggedClasses.Add(MutableString.CreateAscii("tag:ruby.yaml.org,2002:array"), context.GetClass(typeof(RubyArray)));
taggedClasses.Add(MutableString.CreateAscii("tag:ruby.yaml.org,2002:exception"), context.GetClass(typeof(Exception)));
taggedClasses.Add(MutableString.CreateAscii("tag:ruby.yaml.org,2002:hash"), context.GetClass(typeof(Hash)));
taggedClasses.Add(MutableString.CreateAscii("tag:ruby.yaml.org,2002:object"), context.GetClass(typeof(object)));
taggedClasses.Add(MutableString.CreateAscii(Tags.RubyRange), context.GetClass(typeof(Range)));
taggedClasses.Add(MutableString.CreateAscii(Tags.RubyRegexp), context.GetClass(typeof(RubyRegex)));
taggedClasses.Add(MutableString.CreateAscii("tag:ruby.yaml.org,2002:string"), context.GetClass(typeof(MutableString)));
taggedClasses.Add(MutableString.CreateAscii("tag:ruby.yaml.org,2002:struct"), context.GetClass(typeof(RubyStruct)));
taggedClasses.Add(MutableString.CreateAscii(Tags.RubySymbol), context.GetClass(typeof(RubySymbol)));
taggedClasses.Add(MutableString.CreateAscii("tag:ruby.yaml.org,2002:symbol"), context.GetClass(typeof(RubySymbol)));
taggedClasses.Add(MutableString.CreateAscii("tag:ruby.yaml.org,2002:time"), context.GetClass(typeof(RubyTime)));
taggedClasses.Add(MutableString.CreateAscii(Tags.Binary), context.GetClass(typeof(MutableString)));
taggedClasses.Add(MutableString.CreateAscii(Tags.Float), context.GetClass(typeof(Double)));
taggedClasses.Add(MutableString.CreateAscii(Tags.Int), context.GetClass(typeof(Integer)));
taggedClasses.Add(MutableString.CreateAscii(Tags.Map), context.GetClass(typeof(Hash)));
taggedClasses.Add(MutableString.CreateAscii(Tags.Seq), context.GetClass(typeof(RubyArray)));
taggedClasses.Add(MutableString.CreateAscii(Tags.Str), context.GetClass(typeof(MutableString)));
taggedClasses.Add(MutableString.CreateAscii(Tags.Timestamp), context.GetClass(typeof(RubyTime)));
taggedClasses.Add(MutableString.CreateAscii(Tags.False), context.FalseClass);
taggedClasses.Add(MutableString.CreateAscii(Tags.True), context.TrueClass);
taggedClasses.Add(MutableString.CreateAscii(Tags.Null), context.NilClass);
//if (ctor.GlobalScope.Context.TryGetModule(ctor.GlobalScope, "Date", out module)) {
// taggedClasses.Add(MutableString.CreateAscii(Tags.TimestampYmd), context.NilClass);
//}
//taggedClasses.Add(MutableString.CreateAscii("tag:yaml.org,2002:timestamp#ymd'"), );
//Currently not supported
//taggedClasses.Add(MutableString.CreateAscii("tag:yaml.org,2002:omap"), ec.GetClass(typeof()));
//taggedClasses.Add(MutableString.CreateAscii("tag:yaml.org,2002:pairs"),// ec.GetClass(typeof()));
//taggedClasses.Add(MutableString.CreateAscii("tag:yaml.org,2002:set"),// ec.GetClass(typeof()));
return taggedClasses;
}
示例5: GetTmsClass
public static RubyClass/*!*/ GetTmsClass(RubyContext/*!*/ context) {
ContractUtils.RequiresNotNull(context, "context");
object value;
if (context.TryGetLibraryData(TmsStructClassKey, out value)) {
return (RubyClass)value;
}
// trigger constant initialization of Struct class:
context.GetClass(typeof(RubyStruct)).TryGetConstant(null, String.Empty, out value);
// try again:
if (context.TryGetLibraryData(TmsStructClassKey, out value)) {
return (RubyClass)value;
}
throw Assert.Unreachable;
}
示例6: GetSuperclass
public static RubyClass GetSuperclass(RubyContext/*!*/ context, TypeGroup/*!*/ self) {
Type type = GetNonGenericType(self);
return type.IsInterface ? null : context.GetClass(type).SuperClass;
}
示例7: GetNonGenericClass
public static RubyClass/*!*/ GetNonGenericClass(RubyContext/*!*/ context, TypeGroup/*!*/ typeGroup) {
Type type = GetNonGenericType(typeGroup);
if (type.IsInterface) {
throw RubyExceptions.CreateTypeError("cannot instantiate an interface");
}
return context.GetClass(type);
}
示例8: Step
public static object Step(RubyContext/*!*/ context, BlockParam block, Range/*!*/ self, object step) {
// We attempt to cast step to Fixnum here even though if we were iterating over Floats, for instance, we use step as is.
// This prevents cases such as (1.0..2.0).step(0x800000000000000) {|x| x } from working but that is what MRI does.
int intStep = Protocols.CastToFixnum(context, step);
if (self.Begin is int && self.End is int) {
// self.begin is Fixnum; directly call item = item + 1 instead of succ
return StepFixnum(context, block, self, (int)self.Begin, (int)self.End, intStep);
} else if ( self.Begin is MutableString ) {
// self.begin is String; use item.succ and item <=> self.end but make sure you check the length of the strings
return StepString(context, block, self, (MutableString)self.Begin, (MutableString)self.End, intStep);
} else if (context.IsInstanceOf(self.Begin, context.GetClass(typeof(Numeric)))) {
// self.begin is Numeric; invoke item = item + 1 instead of succ and invoke < or <= for compare
return StepNumeric(context, block, self, self.Begin, self.End, step);
} else {
// self.begin is not Numeric or String; just invoke item.succ and item <=> self.end
CheckBegin(context, self.Begin);
return StepObject(context, block, self, self.Begin, self.End, intStep);
}
}
示例9: RubyRepresenter
public RubyRepresenter(RubyContext/*!*/ context, Serializer/*!*/ serializer, YamlOptions/*!*/ opts)
: base(serializer, opts) {
_context = context;
_objectToYamlMethod = context.GetClass(typeof(object)).ResolveMethod("to_yaml", RubyClass.IgnoreVisibility).Info;
}
示例10: CreateDefaultTagMapping
private static Hash CreateDefaultTagMapping(RubyContext/*!*/ context) {
Hash taggedClasses = new Hash(context.EqualityComparer);
taggedClasses.Add(MutableString.Create("tag:ruby.yaml.org,2002:array"), context.GetClass(typeof(RubyArray)));
taggedClasses.Add(MutableString.Create("tag:ruby.yaml.org,2002:exception"), context.GetClass(typeof(Exception)));
taggedClasses.Add(MutableString.Create("tag:ruby.yaml.org,2002:hash"), context.GetClass(typeof(Hash)));
taggedClasses.Add(MutableString.Create("tag:ruby.yaml.org,2002:object"), context.GetClass(typeof(object)));
taggedClasses.Add(MutableString.Create("tag:ruby.yaml.org,2002:range"), context.GetClass(typeof(Range)));
taggedClasses.Add(MutableString.Create("tag:ruby.yaml.org,2002:regexp"), context.GetClass(typeof(RubyRegex)));
taggedClasses.Add(MutableString.Create("tag:ruby.yaml.org,2002:string"), context.GetClass(typeof(MutableString)));
taggedClasses.Add(MutableString.Create("tag:ruby.yaml.org,2002:struct"), context.GetClass(typeof(RubyStruct)));
taggedClasses.Add(MutableString.Create("tag:ruby.yaml.org,2002:sym"), context.GetClass(typeof(SymbolId)));
taggedClasses.Add(MutableString.Create("tag:ruby.yaml.org,2002:symbol"), context.GetClass(typeof(SymbolId)));
taggedClasses.Add(MutableString.Create("tag:ruby.yaml.org,2002:time"), context.GetClass(typeof(DateTime)));
taggedClasses.Add(MutableString.Create("tag:yaml.org,2002:binary"), context.GetClass(typeof(MutableString)));
taggedClasses.Add(MutableString.Create("tag:yaml.org,2002:bool#no"), context.FalseClass);
taggedClasses.Add(MutableString.Create("tag:yaml.org,2002:bool#yes"), context.TrueClass);
taggedClasses.Add(MutableString.Create("tag:yaml.org,2002:float"), context.GetClass(typeof(Double)));
taggedClasses.Add(MutableString.Create("tag:yaml.org,2002:int"), context.GetClass(typeof(Integer)));
taggedClasses.Add(MutableString.Create("tag:yaml.org,2002:map"), context.GetClass(typeof(Hash)));
taggedClasses.Add(MutableString.Create("tag:yaml.org,2002:null"), context.NilClass);
taggedClasses.Add(MutableString.Create("tag:yaml.org,2002:seq"), context.GetClass(typeof(RubyArray)));
taggedClasses.Add(MutableString.Create("tag:yaml.org,2002:str"), context.GetClass(typeof(MutableString)));
taggedClasses.Add(MutableString.Create("tag:yaml.org,2002:timestamp"), context.GetClass(typeof(DateTime)));
//Currently not supported
//taggedClasses.Add(MutableString.Create("tag:yaml.org,2002:omap"), ec.GetClass(typeof()));
//taggedClasses.Add(MutableString.Create("tag:yaml.org,2002:pairs"),// ec.GetClass(typeof()));
//taggedClasses.Add(MutableString.Create("tag:yaml.org,2002:set"),// ec.GetClass(typeof()));
//taggedClasses.Add(MutableString.Create("tag:yaml.org,2002:timestamp#ymd'"), );
return taggedClasses;
}
示例11: Step
public static object Step(
ConversionStorage<MutableString>/*!*/ stringCast,
ConversionStorage<int>/*!*/ fixnumCast,
RespondToStorage/*!*/ respondToStorage,
BinaryOpStorage/*!*/ comparisonStorage,
BinaryOpStorage/*!*/ lessThanStorage,
BinaryOpStorage/*!*/ lessThanEqualsStorage,
BinaryOpStorage/*!*/ greaterThanStorage,
BinaryOpStorage/*!*/ equalsStorage,
BinaryOpStorage/*!*/ addStorage,
UnaryOpStorage/*!*/ succStorage,
RubyContext/*!*/ context, BlockParam block, Range/*!*/ self, [Optional]object step) {
if (step == Missing.Value) {
step = ScriptingRuntimeHelpers.Int32ToObject(1);
}
// We attempt to cast step to Fixnum here even though if we were iterating over Floats, for instance, we use step as is.
// This prevents cases such as (1.0..2.0).step(0x800000000000000) {|x| x } from working but that is what MRI does.
if (self.Begin is int && self.End is int) {
// self.begin is Fixnum; directly call item = item + 1 instead of succ
int intStep = Protocols.CastToFixnum(fixnumCast, context, step);
return StepFixnum(context, block, self, (int)self.Begin, (int)self.End, intStep);
} else if (self.Begin is MutableString ) {
// self.begin is String; use item.succ and item <=> self.end but make sure you check the length of the strings
int intStep = Protocols.CastToFixnum(fixnumCast, context, step);
return StepString(stringCast, comparisonStorage, lessThanStorage, greaterThanStorage, succStorage, context,
block, self, (MutableString)self.Begin, (MutableString)self.End, intStep
);
} else if (context.IsInstanceOf(self.Begin, context.GetClass(typeof(Numeric)))) {
// self.begin is Numeric; invoke item = item + 1 instead of succ and invoke < or <= for compare
return StepNumeric(lessThanStorage, lessThanEqualsStorage, equalsStorage, addStorage, context,
block, self, self.Begin, self.End, step
);
} else {
// self.begin is not Numeric or String; just invoke item.succ and item <=> self.end
CheckBegin(respondToStorage, context, self.Begin);
int intStep = Protocols.CastToFixnum(fixnumCast, context, step);
return StepObject(comparisonStorage, lessThanStorage, greaterThanStorage, equalsStorage, succStorage, context,
block, self, self.Begin, self.End, intStep
);
}
}
示例12: HandleException
internal static Exception/*!*/ HandleException(RubyContext/*!*/ context, Exception/*!*/ exception) {
// already handled:
var instanceData = GetInstance(exception);
if (instanceData.Handled) {
return exception;
}
RubyClass exceptionClass = context.GetClass(exception.GetType());
// new resolves to Class#new built-in method:
var newMethod = exceptionClass.SingletonClass.ResolveMethod("new", VisibilityContext.AllVisible);
if (newMethod.Found && newMethod.Info.DeclaringModule == context.ClassClass && newMethod.Info is RubyCustomMethodInfo) {
// initialize resolves to a built-in method:
var initializeMethod = exceptionClass.ResolveMethod("initialize", VisibilityContext.AllVisible);
if (initializeMethod.Found && initializeMethod.Info is RubyLibraryMethodInfo) {
instanceData.Handled = true;
return exception;
}
}
var site = exceptionClass.NewSite;
Exception newException;
try {
newException = site.Target(site, exceptionClass, instanceData.Message) as Exception;
} catch (Exception e) {
// MRI: this can lead to stack overflow:
return HandleException(context, e);
}
// MRI doesn't handle this correctly, see http://redmine.ruby-lang.org/issues/show/1886:
if (newException == null) {
newException = RubyExceptions.CreateTypeError("exception object expected");
}
var newInstanceData = GetInstance(newException);
newInstanceData.Handled = true;
newInstanceData._backtrace = instanceData._backtrace;
return newException;
}
示例13: RubyRepresenter
public RubyRepresenter(RubyContext/*!*/ context, ISerializer/*!*/ serializer, YamlOptions/*!*/ opts)
: base(serializer, opts) {
_context = context;
_objectToYamlMethod = context.GetClass(typeof(object)).ResolveMethod("to_yaml", false);
}
示例14: PrecFloat
public static object PrecFloat(RubyContext/*!*/ context, object self) {
return LibrarySites.InvokePrec(context, context.GetClass(typeof(double)), self);
}
示例15: PrecInteger
public static object PrecInteger(RubyContext/*!*/ context, object self) {
return LibrarySites.InvokePrec(context, context.GetClass(typeof(Integer)), self);
}