static bool InitIdToMessageNameMapping()
{
// make sure a message exists, even if it's just to indicate a problem
for ( int i = 0; i < idToMessageTemplateName.Length; i++ )
{
idToMessageTemplateName[i] = "INVALID MESSAGE ID: " + i;
}
// get list of fields and use it to fill in idToMessageTemplateName mapping
FieldInfo[] fields = typeof( ErrorManager ).GetFields();
for ( int i = 0; i < fields.Length; i++ )
{
FieldInfo f = fields[i];
String fieldName = f.Name;
if ( !fieldName.StartsWith( "MSG_" ) )
{
continue;
}
String templateName =
fieldName.Substring( "MSG_".Length );
int msgID = 0;
try
{
// get the constant value from this class object
msgID = (int)f.GetValue( null );
//msgID = f.getInt( typeof( ErrorManager ) );
}
catch ( FieldAccessException /*iae*/ )
{
Console.Out.WriteLine( "cannot get const value for " + f.Name );
continue;
}
if ( fieldName.StartsWith( "MSG_" ) )
{
idToMessageTemplateName[msgID] = templateName;
}
}
return true;
}