@ Added a very useful function in the map element fields. Why didn't I add this long ago?!

This commit is contained in:
codeimp 2010-09-15 20:29:40 +00:00
parent 0cc92a1fff
commit 7e13e3b45c

View file

@ -66,5 +66,22 @@ namespace CodeImp.DoomBuilder.Map
if(owner != null)
owner.BeforeFieldsChange();
}
/// <summary>This returns the value of a field by name, or returns the specified value when no such field exists or the field value fails to convert to the same datatype.</summary>
public T GetValue<T>(string fieldname, T defaultvalue)
{
if(!this.ContainsKey(fieldname))
return defaultvalue;
try
{
T val = (T)this[fieldname].Value;
return val;
}
catch(InvalidCastException)
{
return defaultvalue;
}
}
}
}