本文整理汇总了C#中IronRuby.Builtins.RubyStruct类的典型用法代码示例。如果您正苦于以下问题:C# RubyStruct类的具体用法?C# RubyStruct怎么用?C# RubyStruct使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RubyStruct类属于IronRuby.Builtins命名空间,在下文中一共展示了RubyStruct类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Each
public static object Each(BlockParam block, RubyStruct/*!*/ self)
{
if (block == null && self.ItemCount > 0) {
throw RubyExceptions.NoBlockGiven();
}
foreach (var value in self.Values) {
object result;
if (block.Yield(value, out result)) {
return result;
}
}
return self;
}
示例2: EachPair
public static object EachPair(BlockParam block, RubyStruct/*!*/ self)
{
if (block == null && self.ItemCount > 0) {
throw RubyExceptions.NoBlockGiven();
}
var context = self.ImmediateClass.Context;
foreach (KeyValuePair<string, object> entry in self.GetItems()) {
object result;
if (block.Yield(context.EncodeIdentifier(entry.Key), entry.Value, out result)) {
return result;
}
}
return self;
}
示例3: GetMembers
public static RubyArray/*!*/ GetMembers(RubyStruct/*!*/ self) {
Debug.Assert(self.Class.StructInfo != null);
return self.Class.StructInfo.GetMembers();
}
示例4: TmsSetChildUserTime
public static void TmsSetChildUserTime(RubyStruct/*!*/ tms, double value) {
tms[2] = value;
}
示例5: RubyClass
// friend: RubyContext
// tracker: non-null => show members declared on the tracker
internal RubyClass(RubyContext/*!*/ context, string name, Type type, object singletonClassOf,
Action<RubyModule> methodsInitializer, Action<RubyModule> constantsInitializer, Delegate/*!*/[] factories, RubyClass superClass,
RubyModule/*!*/[] expandedMixins, TypeTracker tracker, RubyStruct.Info structInfo,
bool isRubyClass, bool isSingletonClass, ModuleRestrictions restrictions)
: base(context, name, methodsInitializer, constantsInitializer, expandedMixins,
type != typeof(object) ? null : context.Namespaces, tracker, restrictions) {
Debug.Assert(context.Namespaces != null, "Namespaces should be initialized");
Debug.Assert(superClass != null || structInfo == null, "BasicObject is not a struct");
Debug.Assert(!isRubyClass || tracker == null, "Ruby class cannot have a tracker");
Debug.Assert(singletonClassOf != null || !isSingletonClass, "Singleton classes don't have a type");
Debug.Assert(superClass != this);
_underlyingSystemType = type;
_superClass = superClass;
_isSingletonClass = isSingletonClass;
_isRubyClass = isRubyClass;
_singletonClassOf = singletonClassOf;
_factories = factories ?? Utils.EmptyDelegates;
if (superClass != null) {
_level = superClass.Level + 1;
_structInfo = structInfo ?? superClass._structInfo;
} else {
_level = 0;
}
}
示例6: ToYamlNode
public static Node ToYamlNode(RubyStruct/*!*/ self, [NotNull]RubyRepresenter/*!*/ rep) {
RubyContext context = self.Class.Context;
RubyArray members = _Members.Target(_Members, context, self);
RubyArray values = _Values.Target(_Values, context, self);
if (members.Count != values.Count) {
throw new ArgumentException("Struct values and members returned arrays of different lengths");
}
Hash map = new Hash(self.Class.Context);
for (int i = 0; i < members.Count; i++) {
IDictionaryOps.SetElement(context, map, members[i], values[i]);
}
RubyRepresenter.AddYamlProperties(context, self, map);
return rep.Map(self, map);
}
示例7: ToYamlNode
public static Node ToYamlNode(RubyStruct/*!*/ self, [NotNull]RubyRepresenter/*!*/ rep) {
var fieldNames = self.GetNames();
var map = new Dictionary<MutableString, object>(fieldNames.Count);
for (int i = 0; i < fieldNames.Count; i++) {
map[MutableString.Create(fieldNames[i])] = self.GetValue(i);
}
rep.AddYamlProperties(self, map);
return rep.Map(self, map);
}
示例8: InitializeCopy
public static RubyStruct/*!*/ InitializeCopy(RubyStruct/*!*/ self, [NotNull]RubyStruct/*!*/ source) {
// TODO: compare non-singleton classes?
if (self.ImmediateClass.GetNonSingletonClass() != source.ImmediateClass.GetNonSingletonClass()) {
throw RubyExceptions.CreateTypeError("wrong argument class");
}
self.SetValues(source.Values);
return self;
}
示例9: SetValue
public static object SetValue(RubyStruct/*!*/ self, [NotNull]MutableString/*!*/ name, object value) {
return self[name.ConvertToString()] = value;
}
示例10: GetSize
public static int GetSize(RubyStruct/*!*/ self) {
return self.ItemCount;
}
示例11: GetMembers
public static RubyArray/*!*/ GetMembers(RubyStruct/*!*/ self) {
return RubyStruct.GetMembers(self);
}
示例12: WriteStruct
private void WriteStruct(RubyStruct/*!*/ obj) {
SubclassData instanceWriter = new SubclassData(this, obj, typeof(RubyStruct));
_writer.Write((byte)'S');
RubyClass theClass = _context.GetClassOf(obj);
TestForAnonymous(theClass);
WriteSymbol(theClass.Name);
var names = obj.GetNames();
WriteInt32(names.Count);
foreach (string name in names) {
int index = obj.GetIndex(name);
WriteSymbol(name);
WriteAnObject(obj[index]);
}
}
示例13: Equals
public static bool Equals(BinaryOpStorage/*!*/ equals, RubyStruct/*!*/ self, object obj) {
var other = obj as RubyStruct;
if (!self.StructReferenceEquals(other)) {
return false;
}
Debug.Assert(self.ItemCount == other.ItemCount);
if (self.Values.Length > 0) {
var site = equals.GetCallSite("==");
for (int i = 0; i < self.Values.Length; i++) {
if (RubyOps.IsFalse(site.Target(site, self.Values[i], other.Values[i]))) {
return false;
}
}
}
return true;
}
示例14: ValuesAt
public static RubyArray/*!*/ ValuesAt(ConversionStorage<int>/*!*/ fixnumCast, RubyStruct/*!*/ self, params object[]/*!*/ values) {
RubyArray result = new RubyArray();
object[] data = self.Values;
for (int i = 0; i < values.Length; ++i) {
Range range = values[i] as Range;
if (range != null) {
int begin = Protocols.CastToFixnum(fixnumCast, range.Begin);
int end = Protocols.CastToFixnum(fixnumCast, range.End);
if (range.ExcludeEnd) {
end -= 1;
}
begin = NormalizeIndex(data.Length, begin);
end = NormalizeIndex(data.Length, end);
Debug.Assert(end - begin <= data.Length); // because we normalized the indicies
if (end - begin > 0) {
result.AddCapacity(end - begin);
for (int j = begin; j <= end; j++) {
result.Add(data[j]);
}
}
} else {
int index = NormalizeIndex(data.Length, Protocols.CastToFixnum(fixnumCast, values[i]));
result.Add(data[index]);
}
}
return result;
}
示例15: Reinitialize
public static void Reinitialize(RubyStruct/*!*/ self, params object[]/*!*/ items) {
self.SetValues(items);
}