Example #1
0
        public bool TypeMatches(ToffeeNetwork network, object o)
        {
            Type            t          = o.GetType();
            ToffeeValueType toffeeType = GetToffeeValueTypeFromType(network, t);

            if (toffeeType == BaseType)
            {
                if ((toffeeType != ToffeeValueType.Array) && (toffeeType != ToffeeValueType.Struct))
                {
                    return(true);
                }
                else
                {
                    if (t.IsArray)
                    {
                        return(SubType.TypeMatches(network, t.GetElementType()));
                    }
                    else if ((t.IsValueType) && (network.HasObject <ToffeeStruct>(t.FullName)))
                    {
                        return(StructId == network.GetObject <ToffeeStruct>(t.FullName).ObjectId);
                    }
                }
            }

            return(false);
        }
Example #2
0
 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;
     }
 }
Example #3
0
        public static ToffeeValueType GetToffeeValueTypeFromType(ToffeeNetwork network, Type t)
        {
            TypeCode tCode = Type.GetTypeCode(t);

            switch (tCode)
            {
            case TypeCode.Boolean:
                return(ToffeeValueType.Bool);

            case TypeCode.Char:
                return(ToffeeValueType.Char);

            case TypeCode.SByte:
                return(ToffeeValueType.Int8);

            case TypeCode.Int16:
                return(ToffeeValueType.Int16);

            case TypeCode.Int32:
                return(ToffeeValueType.Int32);

            case TypeCode.Int64:
                return(ToffeeValueType.Int64);

            case TypeCode.Byte:
                return(ToffeeValueType.UInt8);

            case TypeCode.UInt16:
                return(ToffeeValueType.UInt16);

            case TypeCode.UInt32:
                return(ToffeeValueType.UInt32);

            case TypeCode.UInt64:
                return(ToffeeValueType.UInt64);

            case TypeCode.String:
                return(ToffeeValueType.String);

            case TypeCode.Single:
                return(ToffeeValueType.Float32);

            case TypeCode.Double:
                return(ToffeeValueType.Float64);

            case TypeCode.Object:
                if (t.IsArray)
                {
                    return(ToffeeValueType.Array);
                }
                else if (network.HasObject <ToffeeStruct>(t.FullName))
                {
                    return(ToffeeValueType.Struct);
                }
                else
                {
                    throw new Exception(string.Format("{0} cannot be converted to a ToffeeValueType.", t));
                }

            default:
                throw new Exception(string.Format("{0} cannot be converted to a ToffeeValueType.", t));
            }
        }