4 using System.Collections;
5 using System.Collections.Generic;
8 using SiliconStudio.ActionStack;
9 using SiliconStudio.Core.IO;
11 namespace SiliconStudio.Presentation.Settings
16 internal abstract class SettingsEntry
18 protected readonly SettingsProfile Profile;
19 protected bool ShouldNotify;
27 protected SettingsEntry(SettingsProfile profile,
UFile name)
29 if (profile == null)
throw new ArgumentNullException(
"profile");
30 if (name == null)
throw new ArgumentNullException(
"name");
38 internal UFile Name {
get;
private set; }
43 internal object Value {
get {
return value; } set { UpdateValue(value); } }
52 internal static SettingsEntry CreateFromValue(SettingsProfile profile,
UFile name,
object value)
54 if (profile == null)
throw new ArgumentNullException(
"profile");
55 if (name == null)
throw new ArgumentNullException(
"name");
58 Type type = value.GetType();
60 if (value is IList || type.GetInterfaces().Any(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IList<>)))
63 var genericListInterface = type.GetInterfaces().FirstOrDefault(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IList<>));
64 if (genericListInterface != null)
66 var itemType = genericListInterface.GetGenericArguments()[0];
67 var result = (SettingsEntry)Activator.CreateInstance(typeof(SettingsEntryList<>).MakeGenericType(itemType), profile, name, listItems);
70 return new SettingsEntryList<object>(profile, name, listItems);
74 return new SettingsEntryValue(profile, name, value);
81 internal abstract object GetSerializableValue();
83 private void UpdateValue(
object newValue)
86 bool changed = !Equals(oldValue, newValue);
87 if (changed && ShouldNotify && !Profile.IsDiscarding)
90 Profile.ActionStack.Add(actionItem);
91 Profile.NotifyEntryChanged(Name);
The type of the serialized type will be passed as a generic arguments of the serializer. Example: serializer of A becomes instantiated as Serializer{A}.
Defines a normalized file path. See UPath for details. This class cannot be inherited.