Просмотр исходного кода

Added ObsoleteReplacementProperty attribute

Kenric Nugteren 2 дней назад
Родитель
Сommit
ea1c40cc82

+ 1 - 0
InABox.Core/Classes/Address.cs

@@ -228,6 +228,7 @@ namespace InABox.Core
         private LocalityLink _locality;
 
         [Obsolete("Replaced with Locality")]
+        [ObsoleteProperty(nameof(Locality))]
         public LocalityLink LocalityLink
         {
             get => Locality;

+ 4 - 0
InABox.Core/Classes/Document/EntityDocument.cs

@@ -7,11 +7,13 @@ namespace InABox.Core
         new T Entity { get; }
 
         [Obsolete("Replaced by Entity")]
+        [ObsoleteProperty(nameof(Entity))]
         new T EntityLink { get; }
 
         IEntityLink IEntityDocument.Entity => Entity;
 
         [Obsolete]
+        [ObsoleteProperty(nameof(Entity))]
         IEntityLink IEntityDocument.EntityLink => EntityLink;
     }
 
@@ -29,6 +31,7 @@ namespace InABox.Core
         private T? _entity;
 
         [Obsolete("Replaced with Entity")]
+        [ObsoleteProperty(nameof(Entity))]
         public T EntityLink
         {
             get => Entity;
@@ -41,6 +44,7 @@ namespace InABox.Core
         private DocumentLink? _document;
 
         [Obsolete("Replaced with Document")]
+        [ObsoleteProperty(nameof(Document))]
         public DocumentLink DocumentLink
         {
             get => Document;

+ 2 - 0
InABox.Core/Classes/Document/IEntityDocument.cs

@@ -7,11 +7,13 @@ namespace InABox.Core
         IEntityLink Entity { get; }
 
         [Obsolete("Replaced by Entity")]
+        [ObsoleteProperty(nameof(Entity))]
         IEntityLink EntityLink { get; }
         
         DocumentLink Document { get; }
 
         [Obsolete("Replaced by Document")]
+        [ObsoleteProperty(nameof(Document))]
         DocumentLink DocumentLink { get; }
         
 

+ 26 - 0
InABox.Core/DatabaseSchema/StandardProperty.cs

@@ -180,12 +180,38 @@ namespace InABox.Core
             return IsPropertyObsolete(prop.Parent as StandardProperty);
         }
 
+        private string? GetObsoleteReplacementProperty(StandardProperty? prop)
+        {
+            if (prop is null) return null;
+            if(prop.Property.GetCustomAttribute<ObsoletePropertyAttribute>() is ObsoletePropertyAttribute attr)
+            {
+                if(prop.Parent != null)
+                {
+                    return $"{prop.Parent}.{attr.ReplacementProperty}";
+                }
+                else
+                {
+                    return attr.ReplacementProperty;
+                }
+            }
+            else if(GetObsoleteReplacementProperty(prop.Parent as StandardProperty) is string parent)
+            {
+                return $"{parent}.{prop.Property.Name}";
+            }
+            else
+            {
+                return null;
+            }
+        }
+
         public bool IsPersistable => IsPropertyPersistable(this);
 
         public bool IsSerializable => IsPropertySerializable(this);
 
         public bool IsObsolete => IsPropertyObsolete(this);
 
+        public string? ObsoleteReplacementProperty => GetObsoleteReplacementProperty(this);
+
         private bool? _dbColumn;
         public bool IsDBColumn
         {

+ 2 - 0
InABox.Core/DigitalForms/Forms/BaseEntityForm.cs

@@ -36,6 +36,7 @@ namespace InABox.Core
 
         [NullEditor]
         [Obsolete("Being Replaced by Form")]
+        [ObsoleteProperty(nameof(Form))]
         public QAFormLink QAForm => InitializeField(ref _qAForm, nameof(QAForm));
         private QAFormLink _qAForm;
 
@@ -80,6 +81,7 @@ namespace InABox.Core
 
         [NullEditor]
         [Obsolete("Being Replaced by FormCompletedBy")]
+        [ObsoleteProperty(nameof(FormCompletedBy))]
         public UserLink QACompletedBy => InitializeField(ref _qACompletedBy, nameof(QACompletedBy));
         private UserLink _qACompletedBy;
 

+ 1 - 0
InABox.Core/DigitalForms/Forms/DigitalFormLayout.cs

@@ -12,6 +12,7 @@ namespace InABox.Core
     {
         [NullEditor]
         [Obsolete("Replaced by Form")]
+        [ObsoleteProperty(nameof(Form))]
         public QAFormLink QAForm => InitializeField(ref _qAForm, nameof(QAForm));
         private QAFormLink _qAForm;
 

+ 1 - 0
InABox.Core/DigitalForms/Forms/DigitalFormVariable.cs

@@ -37,6 +37,7 @@ namespace InABox.Core
 
         [NullEditor]
         [Obsolete("Replaced with Form")]
+        [ObsoleteProperty(nameof(Form))]
         public QAFormLink QAForm => InitializeField(ref _qAForm, nameof(QAForm));
         private QAFormLink _qAForm;
 

+ 1 - 0
InABox.Core/DigitalForms/Forms/IDigitalForm.cs

@@ -9,6 +9,7 @@ namespace InABox.Core
     public interface IDigitalForm<T> : IDigitalForm
     {
         [Obsolete("Being Replaced with Form", true)]
+        [ObsoleteProperty(nameof(Form))]
         QAFormLink QAForm { get; }
 
         DigitalFormLink Form { get; }

+ 4 - 0
InABox.Core/DigitalForms/Forms/IDigitalFormInstance.cs

@@ -16,9 +16,11 @@ namespace InABox.Core
     public interface ICoreDigitalFormInstance : IBaseDigitalFormInstance
     {
         [Obsolete("Replaced with Form", true)]
+        [ObsoleteProperty(nameof(Form))]
         QAFormLink QAForm { get; }
         
         [Obsolete("Replaced with FormData", true)]
+        [ObsoleteProperty(nameof(FormData))]
         string QAData { get; set; }
         
         String Number { get; set; }
@@ -30,9 +32,11 @@ namespace InABox.Core
         string? BlobData { get; set; }
 
         [Obsolete("Replaced with FormCompleted", true)]
+        [ObsoleteProperty(nameof(FormCompleted))]
         DateTime QACompleted { get; set; }
         
         [Obsolete("Replaced with FormCompletedBy", true)]
+        [ObsoleteProperty(nameof(FormCompletedBy))]
         UserLink QACompletedBy { get; }
 
         UserLink FormCompletedBy { get; }

+ 1 - 0
InABox.Core/DigitalForms/Obsolete/QAQuestion.cs

@@ -16,6 +16,7 @@ namespace InABox.Core
 
         [NullEditor]
         [Obsolete("Replaced with Form")]
+        [ObsoleteProperty(nameof(Form))]
         public QAFormLink QAForm => InitializeField(ref _qAForm, nameof(QAForm));
         private QAFormLink? _qAForm;
 

+ 18 - 0
InABox.Core/Objects/Attributes/ObsoletePropertyAttribute.cs

@@ -0,0 +1,18 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace InABox.Core
+{
+    public class ObsoletePropertyAttribute : Attribute
+    {
+        public string ReplacementProperty { get; set; }
+
+        public ObsoletePropertyAttribute(string replacement)
+        {
+            ReplacementProperty = replacement;
+        }
+    }
+}

+ 9 - 0
InABox.Core/Serialization.cs

@@ -749,6 +749,15 @@ namespace InABox.Core
                 {
                     var value = reader.ReadBinaryValue(prop.PropertyType);
                     obj.OriginalValueList[prop.Name] = value;
+
+                    if(prop is StandardProperty stdProp
+                        && stdProp.ObsoleteReplacementProperty is string replacement)
+                    {
+                        if (!obj.OriginalValueList.ContainsKey(replacement))
+                        {
+                            obj.OriginalValueList[replacement] = value;
+                        }
+                    }
                 }
             }
         }