public ToffeeType(ToffeeNetwork network, uint structId) { if (network.GetObject <ToffeeStruct>(structId) == null) { throw new Exception("Cannot make a ToffeeType instance with invalid structId"); } BaseType = ToffeeValueType.Struct; SubType = new ToffeeType(ToffeeValueType.None); StructId = structId; }
public ToffeeType(ToffeeNetwork network, Type t) { BaseType = GetToffeeValueTypeFromType(network, t); if (t.IsArray) { SubType = new ToffeeType(network, t.GetElementType()); } else if ((t.IsValueType) && (network.HasObject <ToffeeStruct>(t.FullName))) { StructId = network.GetObject <ToffeeStruct>(t.FullName).ObjectId; } }
public ToffeeType(ToffeeValueType baseType) { BaseType = baseType; if (BaseType == ToffeeValueType.Array) { SubType = new ToffeeType(ToffeeValueType.UInt8); } else { SubType = new ToffeeType(ToffeeValueType.None); } }
/// <summary> /// Write's a set of ToffeeValueType values to signify a Type. /// </summary> /// <param name="t">The type to write</param> public void Write(Type t) { ToffeeValueType toffeeType = ToffeeType.GetToffeeValueTypeFromType(Network, t); Write((byte)toffeeType); if (toffeeType == ToffeeValueType.Array) { Write(t.GetElementType()); } if (toffeeType == ToffeeValueType.Struct) { Write(Network.GetObject <ToffeeStruct>(t.FullName).ObjectId); } }
public Array ReadArray() { // Get the properties of the array uint length = ReadUInt32(); ToffeeValueType elementVType = ReadValueType(); uint structId = 0; if (elementVType == ToffeeValueType.Struct) { structId = ReadUInt32(); } Type elementType = ToffeeType.GetTypeFromToffeeValueType(Network, elementVType, structId: structId); // Create the array and fill it Array array = Array.CreateInstance(elementType, length); for (int i = 0; i < length; i++) { array.SetValue(Read(elementType), i); } return(array); }
public ToffeeType(ToffeeType subType) { BaseType = ToffeeValueType.Array; SubType = subType; }
public ToffeeType(ToffeeValueType subType, bool array) { BaseType = ToffeeValueType.Array; SubType = new ToffeeType(subType); }