Constrain generic type of DataOperationException to an enum

This commit is contained in:
Ronald Barendse
2019-11-14 00:28:24 +01:00
parent 4a84f63ab4
commit 3ef10ac8fc

View File

@@ -8,9 +8,9 @@ namespace Umbraco.Core.Exceptions
/// </summary>
/// <typeparam name="T"></typeparam>
/// <seealso cref="System.Exception" />
[Obsolete("Refactor the generic type to a concrete serializable type.")]
[Serializable]
internal class DataOperationException<T> : Exception
where T : Enum
{
/// <summary>
/// Gets the operation.
@@ -74,7 +74,7 @@ namespace Umbraco.Core.Exceptions
protected DataOperationException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
Operation = (T)info.GetValue(nameof(Operation), typeof(T));
Operation = (T)Enum.Parse(typeof(T), info.GetString(nameof(Operation)));
}
/// <summary>
@@ -90,7 +90,7 @@ namespace Umbraco.Core.Exceptions
throw new ArgumentNullException(nameof(info));
}
info.AddValue(nameof(Operation), Operation);
info.AddValue(nameof(Operation), Enum.GetName(typeof(T), Operation));
base.GetObjectData(info, context);
}