Load() 공개 정적인 메소드

public static Load ( BinaryReader reader, Value>.IDictionary values ) : bool
reader System.IO.BinaryReader
values Value>.IDictionary
리턴 bool
예제 #1
0
        private static bool Load(BinaryReader reader, out Value value)
        {
            List <KeyValuePair <Value, Value> > array;
            Value        arrayKey;
            Value        arrayValue;
            int          count;
            ValueContent type;

            type = (ValueContent)reader.ReadInt32();

            switch (type)
            {
            case ValueContent.Boolean:
                value = reader.ReadBoolean() ? BooleanValue.True : BooleanValue.False;

                break;

            case ValueContent.Map:
                count = reader.ReadInt32();
                array = new List <KeyValuePair <Value, Value> > (count);

                while (count-- > 0)
                {
                    if (!ValueAccessor.Load(reader, out arrayKey) || !ValueAccessor.Load(reader, out arrayValue))
                    {
                        value = null;

                        return(false);
                    }

                    array.Add(new KeyValuePair <Value, Value> (arrayKey, arrayValue));
                }

                value = array;

                break;

            case ValueContent.Number:
                value = reader.ReadDecimal();

                break;

            case ValueContent.String:
                value = reader.ReadString();

                break;

            case ValueContent.Void:
                value = VoidValue.Instance;

                break;

            default:
                value = null;

                return(false);
            }

            return(true);
        }
예제 #2
0
파일: DemoForm.cs 프로젝트: mollstam/cottle
        private void StateLoad(string path, bool dialog)
        {
            TreeNode root;
            Dictionary <string, Value> values;
            int version;

            if (this.treeViewValue.Nodes.Count < 1)
            {
                return;
            }

            root = this.treeViewValue.Nodes[0];
            root.Nodes.Clear();

            try
            {
                using (BinaryReader reader = new BinaryReader(new FileStream(path, FileMode.Open), Encoding.UTF8))
                {
                    values  = new Dictionary <string, Value> ();
                    version = reader.ReadInt32();

                    if (version < 1 || version > 2)
                    {
                        MessageBox.Show(this, string.Format(CultureInfo.InvariantCulture, "Incompatible file format"));

                        return;
                    }

                    if (ValueAccessor.Load(reader, values))
                    {
                        foreach (KeyValuePair <string, Value> pair in values)
                        {
                            root.Nodes.Add(this.NodeCreate(pair.Key, pair.Value));
                        }
                    }

                    this.parameters = new SettingForm.Parameters
                    {
                        BlockBegin    = reader.ReadString(),
                        BlockContinue = reader.ReadString(),
                        BlockEnd      = reader.ReadString(),
                        TrimmerIndex  = version > 1 ? reader.ReadInt32() : TrimmerCollection.DEFAULT_INDEX
                    };

                    this.textBoxInput.Text = reader.ReadString();
                }

                root.ExpandAll();

                if (dialog)
                {
                    MessageBox.Show(this, string.Format(CultureInfo.InvariantCulture, "State successfully loaded from \"{0}\".", path), "File save successfull", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch
            {
                MessageBox.Show(this, string.Format(CultureInfo.InvariantCulture, "Cannot open input file \"{0}\"", path), "File load error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #3
0
        public static bool Load(BinaryReader reader, IDictionary <string, Value> values)
        {
            int    count;
            string key;
            Value  value;

            for (count = reader.ReadInt32(); count-- > 0;)
            {
                key = reader.ReadString();

                if (!ValueAccessor.Load(reader, out value))
                {
                    return(false);
                }

                values[key] = value;
            }

            return(true);
        }