Beispiel #1
0
    public static Color AsColor(this UssValue v)
    {
        v = v.Unwrap();

        if (v.GetType() == typeof(UssColorValue))
        {
            return(((UssColorValue)v).value);
        }
        if (v.GetType() == typeof(UssStringValue))
        {
            var str = v.AsString();
            if (str == "black")
            {
                return(Color.black);
            }
            else if (str == "green")
            {
                return(Color.green);
            }
            else if (str == "red")
            {
                return(Color.red);
            }
            else if (str == "blue")
            {
                return(Color.blue);
            }
        }

        throw new InvalidOperationException("Value cannot be color: " + v.GetType());
    }
Beispiel #2
0
    public static Color AsColor(this UssValue v)
    {
        v = v.Unwrap();

        if (v.GetType() == typeof(UssColorValue))
        {
            return(((UssColorValue)v).value);
        }

        throw new InvalidOperationException("Value cannot be color: " + v.GetType());
    }
Beispiel #3
0
    public static int AsInt(this UssValue v)
    {
        v = v.Unwrap();

        if (v.GetType() == typeof(UssFloatValue))
        {
            return((int)((UssFloatValue)(object)v).value);
        }
        if (v.GetType() == typeof(UssIntValue))
        {
            return(((UssIntValue)(object)v).value);
        }

        throw new InvalidOperationException("Value cannot be integer: " + v.GetType());
    }
Beispiel #4
0
    public static string AsString(this UssValue v)
    {
        v = v.Unwrap();

        if (v.GetType() == typeof(UssStringValue))
        {
            return(((UssStringValue)(object)v).value);
        }
        if (v.GetType() == typeof(UssNullValue))
        {
            return(null);
        }

        throw new InvalidOperationException("Value cannot be string: " + v.GetType());
    }
Beispiel #5
0
 public static UssValue Unwrap(this UssValue v)
 {
     if (v.GetType() == typeof(UssRefValue))
     {
         return(UssValues.GetValue((UssRefValue)v));
     }
     return(v);
 }
Beispiel #6
0
 public UssModifierException(string className, UssValue value, Type expected) :
     base(className + " : " + value.GetType().Name + ". (expected " + expected.Name + ")")
 {
 }