Exemplo n.º 1
0
        /// <summary>
        /// Populate an pre-constructed instance with the data stored inside of the facade.
        /// </summary>
        /// <param name="instance">The object instance to populate.</param>
        public void PopulateInstance(ref T instance)
        {
            if (instance.GetType() != InstanceType)
            {
                Debug.LogWarning("PopulateInstance: Actual Facade type is different " +
                                 "(instance.GetType() = " + instance.GetType().CSharpName() +
                                 ", InstanceType = " + InstanceType.CSharpName() + ")");
            }

            Type defaultSerializer     = fiInstalledSerializerManager.DefaultMetadata.SerializerType;
            var  serializer            = (BaseSerializer)fiSingletons.Get(defaultSerializer);
            var  serializationOperator = new ListSerializationOperator()
            {
                SerializedObjects = ObjectReferences
            };

            InspectedType inspectedType = InspectedType.Get(instance.GetType());

            foreach (var tuple in FacadeMembers)
            {
                string name = tuple.Key;

                InspectedProperty property = inspectedType.GetPropertyByName(name);
                if (property != null)
                {
                    try {
                        object deserializedMember = serializer.Deserialize(
                            property.StorageType.Resolve(), tuple.Value, serializationOperator);
                        property.Write(instance, deserializedMember);
                    }
                    catch (Exception e) {
                        Debug.LogError("Skipping property " + name + " in facade due to " +
                                       "deserialization exception.\n" + e);
                    }
                }
            }
        }