private Object _GetConstantRuntimeValue(SchemaType type, Object value)
        {
            if (value == null)
            {
                throw new ArgumentNullException();
            }

            if (type is StringType stype)
            {
                if (value is String)
                {
                    return(value);
                }

                return(value == null ? null : System.Convert.ChangeType(value, typeof(string), System.Globalization.CultureInfo.InvariantCulture));
            }

            if (type is BlittableType btype)
            {
                if (btype.DataType == typeof(Boolean).GetTypeInfo())
                {
                    if (value is Boolean)
                    {
                        return(value);
                    }

                    var str = value as String;

                    if (str.ToLower() == "false")
                    {
                        return(false);
                    }
                    if (str.ToLower() == "true")
                    {
                        return(true);
                    }
                    throw new NotImplementedException();
                }

                if (value is String)
                {
                    return(value);
                }

                return(value == null ? null : System.Convert.ChangeType(value, btype.DataType.AsType(), System.Globalization.CultureInfo.InvariantCulture));
            }

            if (type is EnumType etype)
            {
                var etypeName = _GetRuntimeName(type);

                if (value is String)
                {
                    return($"{etypeName}.{value}");
                }
                else
                {
                    return($"({etypeName}){value}");
                }
            }

            if (type is ArrayType aType)
            {
                var atypeName = _GetRuntimeName(type);

                return(value.ToString());
            }

            throw new NotImplementedException();
        }
 internal _RuntimeType(SchemaType t)
 {
     _PersistentType = t;
 }
 public void SetRuntimeName(SchemaType stype, string newName)
 {
     _UseType(stype).RuntimeName = newName;
 }
Пример #4
0
 public void Remove(SchemaType type)
 {
     _Types.Remove(type.PersistentName);
 }
Пример #5
0
            public DictionaryType UseDictionary(SchemaType key, SchemaType val)
            {
                var item = new DictionaryType(this, key, val);

                return((DictionaryType)_UseOrCreate(item));
            }
Пример #6
0
            public ArrayType UseArray(SchemaType elementType)
            {
                var item = new ArrayType(this, elementType);

                return((ArrayType)_UseOrCreate(item));
            }