make Type property writable and move validation logic into the setter

This commit is contained in:
Michael Becker 2020-06-17 23:24:27 -04:00
parent 250891d517
commit 0151b48216
No known key found for this signature in database
GPG Key ID: 506F54899E2BFED7

View File

@ -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;