1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- using System;
- using System.Linq.Expressions;
- using System.Runtime.CompilerServices;
- namespace InABox.Core
- {
- public interface IProperty
- {
- string Class { get; set; }
- string Name { get; set; }
- string Type { get; set; }
- Type PropertyType { get; set; }
- string Page { get; set; }
- /// <summary>
- /// Whether the property or any parents actually declares an editor.
- /// </summary>
- /// <remarks>
- /// If <c>false</c>, <see cref="Editor"/> will be a <see cref="NullEditor"/>.
- /// </remarks>
- bool HasEditor { get; set; }
- BaseEditor Editor { get; set; }
- long Sequence { get; set; }
- string Caption { get; set; }
- /// <summary>
- /// An <see cref="IProperty"/> is required if it has the <see cref="RequiredColumnAttribute"/> defined on it.<br/>
- /// If it is part of an <see cref="IEntityLink"/>, then it is only required if the <see cref="IEntityLink"/> property on the parent class
- /// also has <see cref="RequiredColumnAttribute"/>.
- /// </summary>
- bool Required { get; set; }
- /// <summary>
- /// Null if the <see cref="IProperty"/> is not loggable.<br/>
- /// An <see cref="IProperty"/> is loggable if it has the <see cref="LoggablePropertyAttribute"/> defined on it.<br/>
- /// If it is part of an <see cref="IEntityLink"/>, then it is only loggable if the <see cref="IEntityLink"/> property on the parent class
- /// also has <see cref="LoggablePropertyAttribute"/>.
- /// </summary>
- LoggablePropertyAttribute? Loggable { get; set; }
- IProperty? Parent { get; set; }
- bool IsEntityLink { get; set; }
- Expression Expression();
- Func<object, object> Getter();
- Action<object, object> Setter();
- }
- public static class PropertyExtensions
- {
- public static bool HasParentEditor(this IProperty property)
- {
- return property.Parent != null && (property.Parent.HasEditor || property.Parent.HasParentEditor());
- }
- private static bool HasParentEntityLink(this IProperty property)
- {
- return property.Parent != null && (property.Parent.IsEntityLink || property.Parent.HasParentEntityLink());
- }
- public static bool ShouldShowEditor(this IProperty property)
- {
- if (property.Parent == null)
- return true;
- if (property.HasParentEditor())
- return false;
- if (property.Parent.IsEntityLink && !property.Name.EndsWith(".ID"))
- return false;
- if (property.Parent.HasParentEntityLink())
- return false;
- return true;
- }
- }
- }
|