本文整理汇总了C#中RubyContext.GetClassOf方法的典型用法代码示例。如果您正苦于以下问题:C# RubyContext.GetClassOf方法的具体用法?C# RubyContext.GetClassOf怎么用?C# RubyContext.GetClassOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RubyContext
的用法示例。
在下文中一共展示了RubyContext.GetClassOf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitializeCopy
public static object InitializeCopy(RubyContext/*!*/ context, object self, object source) {
RubyClass selfClass = context.GetClassOf(self);
RubyClass sourceClass = context.GetClassOf(source);
if (sourceClass != selfClass) {
throw RubyExceptions.CreateTypeError("initialize_copy should take same class object");
}
if (context.IsObjectFrozen(self)) {
throw RubyExceptions.CreateTypeError(String.Format("can't modify frozen {0}", selfClass.Name));
}
return self;
}
示例2: Include
public static RubyClass/*!*/ Include(RubyContext/*!*/ context, object/*!*/ self, params RubyModule[]/*!*/ modules) {
ContractUtils.RequiresNotNullItems(modules, "modules");
RubyUtils.RequireNonClasses(modules);
RubyClass result = context.GetClassOf(self);
result.IncludeModules(modules);
return result;
}
示例3: TagUri
public static MutableString/*!*/ TagUri(RubyContext/*!*/ context, object self) {
var result = MutableString.Create(Tags.RubyObject, context.GetIdentifierEncoding());
var selfClass = context.GetClassOf(self);
if (selfClass != context.ObjectClass) {
return result.Append(':').Append(context.GetClassName(self));
} else {
return result;
}
}
示例4: GetClassObsolete
public static RubyClass/*!*/ GetClassObsolete(RubyContext/*!*/ context, object self) {
context.ReportWarning("Object#type will be deprecated; use Object#class");
return context.GetClassOf(self);
}
示例5: Include
public static RubyClass Include(RubyContext/*!*/ context, object/*!*/ self, params RubyModule[]/*!*/ modules)
{
RubyClass result = context.GetClassOf(self);
result.IncludeModules(modules);
return result;
}
示例6: CreateResultArray
private static IList/*!*/ CreateResultArray(CallSiteStorage<Func<CallSite, RubyContext, RubyClass, object>>/*!*/ allocateStorage,
RubyContext/*!*/ context, IList/*!*/ list) {
// RubyArray:
var array = list as RubyArray;
if (array != null) {
return array.CreateInstance();
}
// interop - call a default ctor to get an instance:
var allocate = allocateStorage.GetCallSite("allocate", 0);
var cls = context.GetClassOf(list);
var result = allocate.Target(allocate, context, cls) as IList;
if (result != null) {
return result;
}
throw RubyExceptions.CreateTypeError(String.Format("{0}#allocate should return IList", cls.Name));
}
示例7: Inspect
public static MutableString/*!*/ Inspect(RubyContext/*!*/ context, BigDecimal/*!*/ self) {
MutableString str = MutableString.CreateMutable();
str.AppendFormat("#<{0}:", context.GetClassOf(self).Name);
RubyUtils.AppendFormatHexObjectId(str, RubyUtils.GetObjectId(context, self));
str.AppendFormat(",'{0}',", self.ToString(10));
str.AppendFormat("{0}({1})>", self.PrecisionDigits.ToString(), self.MaxPrecisionDigits.ToString());
return str;
}
示例8: MakeCoercionError
public static Exception/*!*/ MakeCoercionError(RubyContext/*!*/ context, object self, object other) {
string selfClass = context.GetClassOf(self).Name;
string otherClass = context.GetClassOf(other).Name;
return CreateTypeError("{0} can't be coerced into {1}", selfClass, otherClass);
}
示例9: ToSuperClass
private static RubyClass/*!*/ ToSuperClass(RubyContext/*!*/ ec, object superClassObject) {
if (superClassObject != null) {
RubyClass superClass = superClassObject as RubyClass;
if (superClass == null) {
throw RubyExceptions.CreateTypeError(String.Format("superclass must be a Class ({0} given)", ec.GetClassOf(superClassObject).Name));
}
if (superClass.IsSingletonClass) {
throw RubyExceptions.CreateTypeError("can't make subclass of virtual class");
}
return superClass;
} else {
return ec.ObjectClass;
}
}
示例10: GetMethod
public static RubyMethod/*!*/ GetMethod(RubyContext/*!*/ context, object self, [DefaultProtocol, NotNull]string/*!*/ name) {
RubyMemberInfo info = context.ResolveMethod(self, name, VisibilityContext.AllVisible).Info;
if (info == null) {
throw RubyExceptions.CreateUndefinedMethodError(context.GetClassOf(self), name);
}
return new RubyMethod(self, info, name);
}
示例11: CreateResultArray
private static IList/*!*/ CreateResultArray(RubyContext/*!*/ context, IList/*!*/ self) {
return _CreateArraySite.Target(_CreateArraySite, context, context.GetClassOf(self));
}
示例12: MakeTime
private static DateTime MakeTime(RubyContext/*!*/ context, object obj) {
if (obj == null) {
return DateTime.Now;
} else if (obj is DateTime) {
return (DateTime)obj;
} else if (obj is int) {
return TimeOps.Create(typeof(RubyFileOps), (int)obj);
} else {
string name = context.GetClassOf(obj).Name;
throw RubyExceptions.CreateTypeConversionError(name, "time");
}
}
示例13: MakeComparisonError
public static Exception/*!*/ MakeComparisonError(RubyContext/*!*/ context, object self, object other, Exception x) {
string selfClass = context.GetClassOf(self).Name;
string otherClass = context.GetClassOf(other).Name;
return RubyExceptions.CreateArgumentError("comparison of " + selfClass+ " with " + otherClass + " failed", x);
}
示例14: Coerce
public static RubyArray Coerce(ConversionStorage<double>/*!*/ tof1, ConversionStorage<double>/*!*/ tof2,
RubyContext/*!*/ context, object self, object other) {
if (context.GetClassOf(self) == context.GetClassOf(other)) {
return RubyOps.MakeArray2(other, self);
}
var site1 = tof1.GetSite(ConvertToFAction.Instance);
var site2 = tof2.GetSite(ConvertToFAction.Instance);
return RubyOps.MakeArray2(site1.Target(site1, context, other), site2.Target(site2, context, self));
}
示例15: ObjectToMutableString
public static MutableString/*!*/ ObjectToMutableString(RubyContext/*!*/ context, object obj) {
using (IDisposable handle = RubyUtils.InfiniteInspectTracker.TrackObject(obj)) {
if (handle == null) {
return MutableString.Create("...");
}
MutableString str = MutableString.CreateMutable();
str.Append("#<");
str.Append(context.GetClassOf(obj).Name);
// Ruby prints 2*object_id for objects
str.Append(':');
AppendFormatHexObjectId(str, GetObjectId(context, obj));
// display instance variables
RubyInstanceData data = context.TryGetInstanceData(obj);
if (data != null) {
var vars = data.GetInstanceVariablePairs();
bool first = true;
foreach (KeyValuePair<string, object> var in vars) {
if (first) {
str.Append(" ");
first = false;
} else {
str.Append(", ");
}
str.Append(var.Key);
str.Append("=");
str.Append(RubySites.Inspect(context, var.Value));
}
}
str.Append(">");
return str;
}
}