From 0151b48216c78efcb19af5e642d9054824abb58f Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Wed, 17 Jun 2020 23:24:27 -0400 Subject: [PATCH] make Type property writable and move validation logic into the setter --- .../DataFormatReference.cs | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/Libraries/UniversalEditor.Core/DataFormatReference.cs b/Libraries/UniversalEditor.Core/DataFormatReference.cs index df409316..971d578f 100644 --- a/Libraries/UniversalEditor.Core/DataFormatReference.cs +++ b/Libraries/UniversalEditor.Core/DataFormatReference.cs @@ -54,7 +54,23 @@ namespace UniversalEditor } private Type mvarType = null; - public Type Type { get { return mvarType; } } + public Type Type + { + get { return mvarType; } + set + { + if (!value.IsSubclassOf(typeof(DataFormat))) + { + throw new InvalidCastException("Cannot create a data format reference to a non-DataFormat type"); + } + else if (value.IsAbstract) + { + throw new InvalidOperationException("Cannot create a data format reference to an abstract type"); + } + + mvarType = value; + } + } private string mvarTypeName = null; public string TypeName { get { return mvarTypeName; } set { mvarTypeName = value; } } @@ -123,16 +139,7 @@ namespace UniversalEditor } public DataFormatReference(Type dataFormatType) { - if (!dataFormatType.IsSubclassOf(typeof(DataFormat))) - { - throw new InvalidCastException("Cannot create a data format reference to a non-DataFormat type"); - } - else if (dataFormatType.IsAbstract) - { - throw new InvalidOperationException("Cannot create a data format reference to an abstract type"); - } - - mvarType = dataFormatType; + Type = dataFormatType; } private Guid mvarID = Guid.Empty;