예제 #1
0
        private static void DeserializeInternal(ILPanelEditor editor, IDeserializer deserializer, object instance, IEnumerable<PropertyInfo> properties, string path)
        {
            foreach (PropertyInfo property in properties)
            {
                if (property.CanRead && property.CanWrite)
                {
                    object value = property.GetValue(instance, null);

                    string configPrefixChild = String.Format("{0}:{1}", path, ToIdentifier(property.Name));
                    if (deserializer.Contains(SplitPath(configPrefixChild)))
                    {
                        PropertyInfo[] childProperties = GetProperties(value);
                        if (childProperties.Length > 0 && editor.WrapperMap.Values.Contains(value.GetType()))
                        {
                            DeserializeInternal(editor, deserializer, value, childProperties, String.Format("{0}:{1}", path, ToIdentifier(property.Name)));
                            continue;
                        }
                    }

                    try
                    {
                        string[] pathParts = SplitPath(path);
                        if (deserializer.Contains(pathParts, property.Name))
                            property.SetValue(instance, deserializer.Get(pathParts, property.Name, property.PropertyType), null);
                    }
                    catch
                    {
                        // Exception in deserialization (e.g. ElementNotFound or not deserializable)
                    }
                }
            }
        }