瀏覽代碼

Refactored stuff to not use PropertyInfo.GetEditor(), but IProperty.Editor

Kenric Nugteren 4 月之前
父節點
當前提交
7a0eec97c3

+ 5 - 7
prs.classes/Server/ServerProperties.cs

@@ -27,19 +27,17 @@ namespace PRSServer
         public List<string> CommandLineOptions(params string[] extras)
         {
             var options = new List<string>();
-            var props = CoreUtils.PropertyList(
-                GetType(),
-                x => x.GetEditor() != null
-                     && (x.DeclaringType == typeof(ServerProperties) || x.DeclaringType.IsSubclassOf(typeof(ServerProperties))
-                     )
-            ).OrderBy(x => x.GetSequence());
+
+            var props = DatabaseSchema.Properties(GetType())
+                .OrderBy(x => x.PropertySequence());
+
             foreach (var prop in props)
                 options.Add(
                     string.Format(
                         "/{0}={1}{2}{1}",
                         prop.Name,
                         prop.PropertyType == typeof(string) ? "\"" : "",
-                        prop.GetValue(this)
+                        prop.Getter()(this)
                     )
                 );
             foreach (var extra in extras)

+ 6 - 4
prs.desktop/Panels/Quotes/Details/QuoteDetails.xaml.cs

@@ -78,16 +78,18 @@ namespace PRSDesktop
             Title.OnEditorValueChanged += Title_OnEditorValueChanged;
             Title.Loaded = true;
 
-            Customer.EditorDefinition = new CodePopupEditor(typeof(Customer));
-            Customer.ColumnName = "Customer.ID";
+            var customerProp = DatabaseSchema.PropertyStrict<Quote>(x => x.Customer.ID);
+            Customer.EditorDefinition = customerProp.Editor.CloneEditor() as CodePopupEditor;
+            Customer.ColumnName = customerProp.Name;
             Customer.CodeColumn = "Code";
             Customer.Host = this;
             Customer.Configure();
             Customer.OnEditorValueChanged += Customer_OnEditorValueChanged;
             Customer.Loaded = true;
 
-            Account.EditorDefinition = new CodePopupEditor(typeof(Customer));
-            Account.ColumnName = "Account.ID";
+            var accountProp = DatabaseSchema.PropertyStrict<Quote>(x => x.Account.ID);
+            Account.EditorDefinition = accountProp.Editor.CloneEditor() as CodePopupEditor;
+            Account.ColumnName = accountProp.Name;
             Account.CodeColumn = "Code";
             Account.Host = this;
             Account.Configure();

+ 7 - 11
prs.desktop/Panels/Quotes/Proposals/QuoteProposalDetails.xaml.cs

@@ -30,21 +30,17 @@ namespace PRSDesktop
         public QuoteProposalDetails()
         {
             InitializeComponent();
-            
-            Preamble.EditorDefinition = (CoreUtils.GetProperty<QuoteProposal>(nameof(QuoteProposal.Preamble))?
-                .GetEditor() as RichTextEditor)?
-                .Clone() as RichTextEditor 
-                ?? new RichTextEditor();
-            Preamble.ColumnName = "Preamble";
+
+            var preambleProp = DatabaseSchema.Property<QuoteProposal>(x => x.Preamble);
+            Preamble.EditorDefinition = (preambleProp?.Editor.CloneEditor() as RichTextEditor) ?? new();
+            Preamble.ColumnName = preambleProp?.Name ?? "";
             Preamble.Configure();
             Preamble.OnEditorValueChanged += Preamble_OnEditorValueChanged;
             Preamble.Loaded = true;
 
-            Summary.EditorDefinition = (CoreUtils.GetProperty<QuoteProposal>(nameof(QuoteProposal.Summary))?
-                .GetEditor() as RichTextEditor)?
-                .Clone() as RichTextEditor 
-                ?? new RichTextEditor();
-            Summary.ColumnName = "Summary";
+            var summaryProp = DatabaseSchema.Property<QuoteProposal>(x => x.Summary);
+            Summary.EditorDefinition = (summaryProp?.Editor.CloneEditor() as RichTextEditor) ?? new();
+            Summary.ColumnName = summaryProp?.Name ?? "";
             Summary.Configure();
             Summary.OnEditorValueChanged += Summary_OnEditorValueChanged;
             Summary.Loaded = true;

+ 3 - 3
prs.server/Engines/WebEngine/WebListener.cs

@@ -884,8 +884,8 @@ Model.LoadModel(
             var data = new Dictionary<string, object?>();
             foreach (var property in DatabaseSchema.Properties(entityType))
             {
-                var editor = EditorUtils.GetPropertyEditor(entityType, property);
-                if (editor != null && !(editor is NullEditor) && editor.Editable.EditorVisible())
+                var editor = property.Editor;
+                if (editor.Editable.EditorVisible())
                 {
                     if (editor is LookupEditor)
                     {
@@ -913,7 +913,7 @@ Model.LoadModel(
 
             foreach (var property in DatabaseSchema.Properties(typeof(T)))
             {
-                var editor = EditorUtils.GetPropertyEditor(typeof(T), property);
+                var editor = property.Editor;
 
                 var value = editor is LookupEditor ?
                     (data.GetValueOrDefault(property.Name + "$ID") ?? data.GetValueOrDefault(property.Name)) :

+ 10 - 10
prs.server/Engines/WebEngine/WebUtils.cs

@@ -81,31 +81,31 @@ namespace PRSServer
             if (showType == EntityTableColumns.LOOKUP) return LookupFactory.DefineColumns(typeof(T)).ColumnNames().ToList<string>();
             var columns = new List<string>();
 
-            var properties = CoreUtils.PropertyInfoList(
-                typeof(T),
-                x => x.GetCustomAttribute<DoNotPersist>() == null &&
-                     x.GetCustomAttribute<DoNotSerialize>() == null &&
-                     x.PropertyType != typeof(UserProperties), true);
+            var properties = DatabaseSchema.Properties(typeof(T))
+                .Where(x => x.IsSerializable && x.IsPersistable);
             switch (showType)
             {
                 case EntityTableColumns.VISIBLE:
                     foreach (var property in properties)
                     {
-                        var editor = property.Value.GetEditor();
-                        if (editor != null && editor.Visible != Visible.Hidden) columns.Add(property.Key);
+                        var editor = property.Editor;
+                        if (editor != null && editor.Visible != Visible.Hidden)
+                            columns.Add(property.Name);
                     }
 
                     break;
                 case EntityTableColumns.REQUIRED:
                     foreach (var property in properties)
                     {
-                        var editor = property.Value.GetEditor();
-                        if (editor != null && editor.Visible == Visible.Default) columns.Add(property.Key);
+                        var editor = property.Editor;
+                        if (editor != null && editor.Visible == Visible.Default)
+                            columns.Add(property.Name);
                     }
 
                     break;
                 case EntityTableColumns.ALL:
-                    foreach (var property in properties.Keys) columns.Add(property);
+                    foreach (var property in properties)
+                        columns.Add(property.Name);
                     break;
             }