コード例 #1
0
 /// <summary>
 /// Handles fetching of a value in the StringValues Dictionary
 /// </summary>
 /// <param name="defaultValue">Default Value to use if value is not found in the Settings Dictionary</param>
 /// <param name="name">Compiler Generated Name of Property</param>
 /// <returns>String Value for the dictionary</returns>
 public string GetString(string defaultValue = null, [CallerMemberName] string name = null)
 {
     if (name == null)
     {
         return(null);
     }
     return(StringValues.ContainsKey(name) ? StringValues[name] : defaultValue);
 }
コード例 #2
0
 /// <summary>
 /// Handles setting of a value in the StringValues Dictionary
 /// </summary>
 /// <param name="value">Value to Set</param>
 /// <param name="name">Compiler Generated Name of the Property</param>
 public void SetString(string value, [CallerMemberName] string name = null)
 {
     if (name == null)
     {
         return;
     }
     if (StringValues.ContainsKey(name))
     {
         StringValues[name] = value;
     }
     else
     {
         StringValues.Add(name, value);
     }
 }
コード例 #3
0
ファイル: DataLoader.cs プロジェクト: w1r2p1/PtProject
        private T ParseValue(string str)
        {
            if (string.IsNullOrWhiteSpace(str))
            {
                str = string.Empty;
            }

            double val;
            bool   isok = double.TryParse(str, NumberStyles.Any, CultureInfo.InvariantCulture, out val);

            if (!isok)
            {
                DateTime dval;
                bool     dateok = DateTime.TryParseExact(str, DateFormat, null, DateTimeStyles.None, out dval);

                if (dateok)
                {
                    DateTime def = new DateTime();
                    val = (dval - def).TotalDays;
                }
                else
                {
                    if (!StringValues.ContainsKey(str))
                    {
                        int ival = -1;
                        if (!string.IsNullOrWhiteSpace(str))
                        {
                            var hash = ComputeMd5Hash(GetBytes(str));
                            if (!UseLongConverter)
                            {
                                hash = Compute4BytesHash(hash);
                            }
                            ival = (ushort)BitConverter.ToInt32(hash, 0);
                        }
                        StringValues.Add(str, ival);
                    }
                    val = StringValues[str];
                }
            }
            var fval = (T)Convert.ChangeType(val, typeof(T));

            return(fval);
        }
コード例 #4
0
ファイル: ASTTable.cs プロジェクト: Szune/EGScript
        public bool InsertValue(ASTExpressionBase key, ASTExpressionBase value)
        {
            if (key == null)
            {
                AutoIntegerValues.Add(AutoIntegerValues.Count, new ASTTableElement(AutoIntegerValues.Count, value));
                return(true);
            }

            if (key.Type == ExpressionType.NUMBER)
            {
                var numberKey = key as ASTNumber;
                if (IntegerValues.ContainsKey((int)numberKey.Value)) // TODO: Do something to stop this from possibly crashing.. someday. (double to int cast)
                {
                    return(false);
                }
                IntegerValues.Add((int)numberKey.Value, new ASTTableElement((int)numberKey.Value, value));
            }
            else if (key.Type == ExpressionType.STRING)
            {
                var stringKey = key as ASTString;
                if (StringValues.ContainsKey(stringKey.Text))
                {
                    return(false);
                }
                StringValues.Add(stringKey.Text, new ASTTableElement(stringKey.Text, value));
            }
            else if (key.Type == ExpressionType.IDENTIFIER)
            {
                var identifierKey = key as ASTIdentifier;
                if (StringValues.ContainsKey(identifierKey.Name))
                {
                    return(false);
                }
                StringValues.Add(identifierKey.Name, new ASTTableElement(identifierKey.Name, value));
            }
            else
            {
                return(false);
            }
            return(true);
        }
コード例 #5
0
        public ExecutionState LoadData(ByteReader br)
        {
            while (br.Avaliable > 0)
            {
                var Name = br.ReadString();
                if (!Name)
                {
                    return(ExecutionState.Failed());
                }
                var Type = br.ReadByte();
                if (!Type)
                {
                    return(ExecutionState.Failed());
                }
                if (!DataTypeHelper.TryParse(Type.Result, out DataType TypeResult))
                {
                    return(ExecutionState.Failed());
                }
                switch (TypeResult)
                {
                case DataType.type_byte:
                    var ValueByte = br.ReadByte();
                    if (!ValueByte)
                    {
                        return(ExecutionState.Failed());
                    }
                    if (ByteValues.ContainsKey(Name.Result))
                    {
                        return(ExecutionState.Failed());
                    }
                    ByteValues.Add(Name.Result, ValueByte.Result);
                    break;

                case DataType.type_sbyte:
                    var ValueSByte = br.ReadSByte();
                    if (!ValueSByte)
                    {
                        return(ExecutionState.Failed());
                    }
                    if (SByteValues.ContainsKey(Name.Result))
                    {
                        return(ExecutionState.Failed());
                    }
                    SByteValues.Add(Name.Result, ValueSByte.Result);
                    break;

                case DataType.type_short:
                    var ValueShort = br.ReadShort();
                    if (!ValueShort)
                    {
                        return(ExecutionState.Failed());
                    }
                    if (ShortValues.ContainsKey(Name.Result))
                    {
                        return(ExecutionState.Failed());
                    }
                    ShortValues.Add(Name.Result, ValueShort.Result);
                    break;

                case DataType.type_ushort:
                    var ValueUShort = br.ReadUShort();
                    if (!ValueUShort)
                    {
                        return(ExecutionState.Failed());
                    }
                    if (UShortValues.ContainsKey(Name.Result))
                    {
                        return(ExecutionState.Failed());
                    }
                    UShortValues.Add(Name.Result, ValueUShort.Result);
                    break;

                case DataType.type_int:
                    var ValueInt = br.ReadInt();
                    if (!ValueInt)
                    {
                        return(ExecutionState.Failed());
                    }
                    if (IntValues.ContainsKey(Name.Result))
                    {
                        return(ExecutionState.Failed());
                    }
                    IntValues.Add(Name.Result, ValueInt.Result);
                    break;

                case DataType.type_uint:
                    var ValueUInt = br.ReadUInt();
                    if (!ValueUInt)
                    {
                        return(ExecutionState.Failed());
                    }
                    if (UIntValues.ContainsKey(Name.Result))
                    {
                        return(ExecutionState.Failed());
                    }
                    UIntValues.Add(Name.Result, ValueUInt.Result);
                    break;

                case DataType.type_long:
                    var ValueLong = br.ReadLong();
                    if (!ValueLong)
                    {
                        return(ExecutionState.Failed());
                    }
                    if (LongValues.ContainsKey(Name.Result))
                    {
                        return(ExecutionState.Failed());
                    }
                    LongValues.Add(Name.Result, ValueLong.Result);
                    break;

                case DataType.type_ulong:
                    var ValueULong = br.ReadULong();
                    if (!ValueULong)
                    {
                        return(ExecutionState.Failed());
                    }
                    if (ULongValues.ContainsKey(Name.Result))
                    {
                        return(ExecutionState.Failed());
                    }
                    ULongValues.Add(Name.Result, ValueULong.Result);
                    break;

                case DataType.type_single:
                    var ValueSingle = br.ReadSingle();
                    if (!ValueSingle)
                    {
                        return(ExecutionState.Failed());
                    }
                    if (SingleValues.ContainsKey(Name.Result))
                    {
                        return(ExecutionState.Failed());
                    }
                    SingleValues.Add(Name.Result, ValueSingle.Result);
                    break;

                case DataType.type_double:
                    var ValueDobule = br.ReadDouble();
                    if (!ValueDobule)
                    {
                        return(ExecutionState.Failed());
                    }
                    if (DoubleValues.ContainsKey(Name.Result))
                    {
                        return(ExecutionState.Failed());
                    }
                    DoubleValues.Add(Name.Result, ValueDobule.Result);
                    break;

                case DataType.type_string:
                    var ValueString = br.ReadString();
                    if (!ValueString)
                    {
                        return(ExecutionState.Failed());
                    }
                    if (StringValues.ContainsKey(Name.Result))
                    {
                        return(ExecutionState.Failed());
                    }
                    StringValues.Add(Name.Result, ValueString.Result);
                    break;
                }
            }

            return(ExecutionState.Succeeded());
        }