mirror of
https://github.com/mgroves/MonodroidStockPortfolio.git
synced 2024-12-29 11:17:07 +00:00
30 lines
No EOL
609 B
C#
30 lines
No EOL
609 B
C#
using System;
|
|
|
|
namespace FileHelpers
|
|
{
|
|
internal class EnumConverter : ConverterBase
|
|
{
|
|
Type mEnumType;
|
|
|
|
public EnumConverter(Type sourceEnum)
|
|
{
|
|
if (sourceEnum.IsEnum == false)
|
|
throw new BadUsageException("The sourceType must be an Enum and is of type " + sourceEnum.Name);
|
|
|
|
mEnumType = sourceEnum;
|
|
}
|
|
|
|
public override object StringToField(string from)
|
|
{
|
|
try
|
|
{
|
|
return Enum.Parse(mEnumType, from.Trim(), true);
|
|
}
|
|
catch (ArgumentException)
|
|
{
|
|
throw new ConvertException(from, mEnumType, "The value don't is on the Enum.");
|
|
}
|
|
}
|
|
|
|
}
|
|
} |