public void Setup(VariableSchema schema, IVariableStore owner)
        {
            _schema = schema;
            _owner  = owner;

            Update();
        }
 public void Clear()
 {
     _variables.Clear();
     _version = 0;
     _schema  = null;
     _owner   = null;
 }
        private MappingData GetMapping(Type ownerType, VariableSchema schema)
        {
            var key     = Tuple.Create(ownerType, schema);
            var version = schema != null ? schema.Version : 0;

            if (!_mappingDatas.TryGetValue(key, out var data) || data.Map.Version != version)
            {
                if (data == null)
                {
                    data = new MappingData
                    {
                        Properties = GetPropertyMaps(ownerType)
                    };

                    _mappingDatas.Add(key, data);
                }

                data.Map = new VariableMap(version);

                foreach (var propertyMap in data.Properties)
                {
                    data.Map.Add(propertyMap);
                }

                if (schema != null)
                {
                    data.Map.Add(schema);
                }
            }

            return(data);
        }
Exemple #4
0
        public VariableMap Add(VariableSchema schema)
        {
            for (var i = 0; i < schema.Count; i++)
            {
                Add(schema[i].Name);
            }

            return(this);
        }
        public void Setup(object owner, VariableSchema schema, VariableSet variables)
        {
            var mapping   = GetMapping(owner.GetType(), schema);
            var listCount = mapping.Properties.Count;

            if (schema != null && variables != null)
            {
                listCount++;
            }

            var lists = new IMappedVariableList[listCount];

            for (var i = 0; i < mapping.Properties.Count; i++)
            {
                lists[i] = new PropertyList(owner, mapping.Properties[i]);
            }

            // variable initializers may need the map set to access other variables
            _map   = mapping.Map;
            _lists = lists;

            if (variables != null)
            {
                if (schema != null)
                {
                    if (owner is IVariableListener listener)
                    {
                        lists[listCount - 1] = new VariableListener(listener, variables);
                    }
                    else
                    {
                        lists[listCount - 1] = variables;
                    }

                    variables.Setup(schema, owner as IVariableStore);
                }
                else
                {
                    variables.Clear();
                }
            }
        }
        protected internal override void Read(BinaryReader reader, IList <Object> objects, short version)
        {
            var index = reader.ReadInt32();

            Schema = objects[index] as VariableSchema;
        }