This commit is contained in:
asayre 2012-01-02 14:25:42 +00:00
parent b9f0138b08
commit ba01533df9

View file

@ -1131,23 +1131,24 @@ namespace Server
return ReadEnum( xml, attribute, ref value, true ); return ReadEnum( xml, attribute, ref value, true );
} }
public static bool ReadEnum<T>( XmlElement xml, string attribute, ref T value, bool mandatory ) where T : struct public static bool ReadEnum<T>( XmlElement xml, string attribute, ref T value, bool mandatory ) where T : struct // We can't limit the where clause to Enums only :(
{ {
string s = GetAttribute( xml, attribute, mandatory ); string s = GetAttribute( xml, attribute, mandatory );
if ( s == null ) if ( s == null )
return false; return false;
Type type = typeof(T);
T tempVal; T tempVal;
if( Enum.TryParse( s, true, out tempVal ) ) if( type.IsEnum && Enum.TryParse( s, true, out tempVal ) )
{ {
value = tempVal; value = tempVal;
return true; return true;
} }
else else
{ {
Console.WriteLine( "Could not parse {0} enum attribute '{1}' in element '{2}'", typeof(T), attribute, xml.Name ); Console.WriteLine( "Could not parse {0} enum attribute '{1}' in element '{2}'", attribute, xml.Name );
return false; return false;
} }
} }