Beispiel #1
0
 /// <summary>
 /// Retrieves the type metadata for the given value.
 /// </summary>
 static public RSTypeInfo RSTypeFor(RSValue inValue, RSTypeAssembly inAssembly)
 {
     return(RSTypeFor(inValue.GetInteropType(), inAssembly));
 }
Beispiel #2
0
        /// <summary>
        /// Retrieves the type metadata for the given C# type.
        /// </summary>
        static public RSTypeInfo RSTypeFor(Type inType, RSTypeAssembly inAssembly)
        {
            if (inType == null || inType == typeof(void))
            {
                return(RSBuiltInTypes.Void);
            }

            if (inType == typeof(object) || inType == typeof(RSValue))
            {
                return(RSBuiltInTypes.Any);
            }

            if (inType.IsEnum)
            {
                return(inAssembly.GetTypeMeta(inType));
            }

            switch (Type.GetTypeCode(inType))
            {
            case TypeCode.Boolean:
                return(RSBuiltInTypes.Bool);

            case TypeCode.Byte:
            case TypeCode.Char:
            case TypeCode.Int16:
            case TypeCode.Int32:
            case TypeCode.Int64:
            case TypeCode.SByte:
            case TypeCode.UInt16:
            case TypeCode.UInt32:
            case TypeCode.UInt64:
                return(RSBuiltInTypes.Int);

            case TypeCode.Double:
            case TypeCode.Single:
                return(RSBuiltInTypes.Float);

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

            case TypeCode.Object:
            {
                if (inType == typeof(Color))
                {
                    return(RSBuiltInTypes.Color);
                }
                if (inType == typeof(Vector2))
                {
                    return(RSBuiltInTypes.Vector2);
                }
                if (inType == typeof(Vector3))
                {
                    return(RSBuiltInTypes.Vector3);
                }
                if (inType == typeof(Vector4))
                {
                    return(RSBuiltInTypes.Vector4);
                }
                if (inType == typeof(RSGroupId))
                {
                    return(RSBuiltInTypes.GroupId);
                }
                if (inType == typeof(RSTriggerId))
                {
                    return(RSBuiltInTypes.TriggerId);
                }
                if (typeof(IRSEntity).IsAssignableFrom(inType))
                {
                    return(RSBuiltInTypes.Entity);
                }

                break;
            }
            }

            throw new ArgumentException(string.Format("Unable to find RSType for type {0}", inType.Name), "inType");
        }