|
@@ -94,6 +94,24 @@ namespace InABox.Core
|
|
_properties = new ConcurrentDictionary<Type, ImmutableSortedDictionary<string, IProperty>>();
|
|
_properties = new ConcurrentDictionary<Type, ImmutableSortedDictionary<string, IProperty>>();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Gets the editor for the specified property. If the property has a <see cref="BaseEditor"/> defined, then returns that.<br/>
|
|
|
|
+ /// Otherwise, gets a default for the property type. (<see cref="GetEditor(Type)"/>), which can be <see langword="null"/>.
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <param name="prop"></param>
|
|
|
|
+ /// <returns></returns>
|
|
|
|
+ private static BaseEditor? GetEditor(PropertyInfo prop)
|
|
|
|
+ {
|
|
|
|
+ var attribute = prop.GetCustomAttributes<BaseEditor>(true).FirstOrDefault();
|
|
|
|
+ var editor = attribute ?? EditorUtils.GetEditor(prop.PropertyType);
|
|
|
|
+ if (editor != null && !prop.CanWrite && !prop.PropertyType.HasInterface<ISubObject>())
|
|
|
|
+ {
|
|
|
|
+ editor = editor.CloneEditor();
|
|
|
|
+ editor.Editable = editor.Editable.Combine(Editable.Disabled);
|
|
|
|
+ }
|
|
|
|
+ return editor;
|
|
|
|
+ }
|
|
|
|
+
|
|
private static void RegisterProperties(Type master, Type type, string prefix, StandardProperty? parent, Dictionary<string, IProperty> newProperties)
|
|
private static void RegisterProperties(Type master, Type type, string prefix, StandardProperty? parent, Dictionary<string, IProperty> newProperties)
|
|
{
|
|
{
|
|
try
|
|
try
|
|
@@ -120,7 +138,7 @@ namespace InABox.Core
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- editor = prop.GetEditor();
|
|
|
|
|
|
+ editor = GetEditor(prop);
|
|
}
|
|
}
|
|
|
|
|
|
var captionAttr = prop.GetCustomAttribute<Caption>();
|
|
var captionAttr = prop.GetCustomAttribute<Caption>();
|
|
@@ -405,10 +423,15 @@ namespace InABox.Core
|
|
|
|
|
|
return prop;
|
|
return prop;
|
|
}
|
|
}
|
|
- public static IProperty? Property<T>(Expression<Func<T, object?>> expression) => Property(typeof(T), CoreUtils.GetFullPropertyName(expression, "."));
|
|
|
|
- public static IProperty? Property<T, TType>(Expression<Func<T, TType>> expression) => Property(typeof(T), CoreUtils.GetFullPropertyName(expression, "."));
|
|
|
|
-
|
|
|
|
- public static IProperty PropertyStrict(Type type, string name) => Property(type, name) ?? throw new PropertyNotFoundException(type, name);
|
|
|
|
|
|
+ public static IProperty? Property<T>(Expression<Func<T, object?>> expression) =>
|
|
|
|
+ Property(typeof(T), CoreUtils.GetFullPropertyName(expression, "."));
|
|
|
|
+ public static IProperty? Property<T, TType>(Expression<Func<T, TType>> expression) =>
|
|
|
|
+ Property(typeof(T), CoreUtils.GetFullPropertyName(expression, "."));
|
|
|
|
+
|
|
|
|
+ public static IProperty PropertyStrict(Type type, string name) =>
|
|
|
|
+ Property(type, name) ?? throw new PropertyNotFoundException(type, name);
|
|
|
|
+ public static IProperty PropertyStrict<T>(Expression<Func<T, object?>> expression) =>
|
|
|
|
+ Property(expression) ?? throw new PropertyNotFoundException(typeof(T), CoreUtils.GetFullPropertyName(expression, "."));
|
|
|
|
|
|
public class PropertyNotFoundException : Exception
|
|
public class PropertyNotFoundException : Exception
|
|
{
|
|
{
|