Esempio n. 1
0
 public bool TryParse(GameCache cache, List <string> args, out IBlamType result, out string error)
 {
     result = null;
     if (args.Count != 1)
     {
         error = $"{args.Count} arguments supplied; should be 1";
         return(false);
     }
     else if (!cache.TryParseGroupTag(args[0], out Tag groupTag))
     {
         error = $"Invalid tag group specifier: {args[0]}";
         return(false);
     }
     else
     {
         result = groupTag;
         error  = null;
         return(true);
     }
 }
Esempio n. 2
0
        public static bool TryParseValue(GameCache cache, Type type, string value, out object result)
        {
            if (type == typeof(Tag))
            {
                if (!cache.TryParseGroupTag(value, out var tag))
                {
                    goto end;
                }
            }
            else if (type == typeof(StringId))
            {
                try
                {
                    result = cache.StringTable.GetStringId(value);
                    return(true);
                }
                catch (Exception)
                {
                    goto end;
                }
            }
            else if (type == typeof(sbyte))
            {
                if (!sbyte.TryParse(value, out var s))
                {
                    goto end;
                }
                result = s;
                return(true);
            }
            else if (type == typeof(byte))
            {
                if (!byte.TryParse(value, out var s))
                {
                    goto end;
                }
                result = s;
                return(true);
            }
            else if (type == typeof(short))
            {
                if (!short.TryParse(value, out var s))
                {
                    goto end;
                }
                result = s;
                return(true);
            }
            else if (type == typeof(ushort))
            {
                if (!ushort.TryParse(value, out var s))
                {
                    goto end;
                }
                result = s;
                return(true);
            }
            else if (type == typeof(int))
            {
                if (!int.TryParse(value, out var s))
                {
                    goto end;
                }
                result = s;
                return(true);
            }
            else if (type == typeof(uint))
            {
                if (!uint.TryParse(value, out var s))
                {
                    goto end;
                }
                result = s;
                return(true);
            }
            else if (type == typeof(long))
            {
                if (!long.TryParse(value, out var s))
                {
                    goto end;
                }
                result = s;
                return(true);
            }
            else if (type == typeof(ulong))
            {
                if (!ulong.TryParse(value, out var s))
                {
                    goto end;
                }
                result = s;
                return(true);
            }
            else if (type == typeof(float))
            {
                if (!float.TryParse(value, out var s))
                {
                    goto end;
                }
                result = s;
                return(true);
            }
            else if (type == typeof(Angle))
            {
                if (!float.TryParse(value, out var s))
                {
                    goto end;
                }
                result = Angle.FromDegrees(s);
                return(true);
            }
            else
            {
                goto end;
            }

end:
            result = null;
            return(false);
        }