mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2024-11-26 22:01:45 +00:00
@ Added a very useful function in the map element fields. Why didn't I add this long ago?!
This commit is contained in:
parent
0cc92a1fff
commit
7e13e3b45c
1 changed files with 17 additions and 0 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue