Exemplo n.º 1
0
        /// <summary>
        /// Fill this data model with a collection reference.
        /// Gets the collection data from the collection and stores it in this serializable model.
        /// </summary>
        public void FromContainer(IInventoryItemContainer container)
        {
            // Serialize based on inventory item serialization model.
            items = new InventoryItemSerializationModel[container.items.Length];
            for (int i = 0; i < container.items.Length; i++)
            {
                var item = container.items[i];
                InventoryItemSerializationModel inst = null;
                if (item != null)
                {
                    var  classes            = ReflectionUtility.GetAllClassesWithAttribute(typeof(SerializationModelAttribute), true);
                    Type serializationModel = typeof(InventoryItemSerializationModel);

                    foreach (var c in classes)
                    {
                        var attrib = (SerializationModelAttribute)c.GetCustomAttributes(typeof(SerializationModelAttribute), true).First();
                        if (c == item.GetType())
                        {
                            DevdogLogger.LogVerbose("Using custom serialization model for " + item.GetType().Name + " - " + attrib.type.Name);
                            serializationModel = attrib.type;
                        }
                    }

                    inst = (InventoryItemSerializationModel)Activator.CreateInstance(serializationModel);
                    inst.FromItem(item);
                }
                else
                {
                    inst = new InventoryItemSerializationModel(null);
                }

                items[i] = inst;
            }
        }
        public object SerializeContainer(IInventoryItemContainer container)
        {
            var serializationModel = new ItemContainerSerializationModel(container);

            return(JsonSerializer.Serialize(serializationModel, null));
        }
 public object SerializeContainer(IInventoryItemContainer container)
 {
     // Easy save 2 handles all this for us..
     return(new ItemContainerSerializationModel(container));
 }
Exemplo n.º 4
0
 /// <summary>
 /// Fill a collection using this data object.
 /// </summary>
 public void ToContainer(IInventoryItemContainer container)
 {
     container.items = items.Select(o => o.ToItem()).ToArray();
 }
Exemplo n.º 5
0
 public ItemContainerSerializationModel(IInventoryItemContainer container)
 {
     FromContainer(container);
 }