/// <summary> /// Registers all attribute names with their respective parser. /// </summary> /// <remarks> /// Methods meant to serve as attribute parsers should use a method attribute to /// </remarks> private void RegisterParsers() { MethodInfo[] methods = this.GetType().GetMethods(); // loop through all methods and look for ones marked with attributes for (int i = 0; i < methods.Length; i++) { // get the current method in the loop MethodInfo method = methods[i]; // see if the method should be used to parse one or more material attributes AttributeParserAttribute[] parserAtts = (AttributeParserAttribute[])method.GetCustomAttributes(typeof(AttributeParserAttribute), true); // loop through each one we found and register its parser for (int j = 0; j < parserAtts.Length; j++) { AttributeParserAttribute parserAtt = parserAtts[j]; switch (parserAtt.ParserType) { // this method should parse a material attribute case PARTICLE: attribParsers.Add(parserAtt.Name, method); break; } // switch } // for } // for }
/// <summary> /// Registers all attribute names with their respective parser. /// </summary> /// <remarks> /// Methods meant to serve as attribute parsers should use a method attribute to /// </remarks> protected virtual void RegisterParsers() { MethodInfo[] methods = this.GetType().GetMethods(BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Static); // loop through all methods and look for ones marked with attributes for (int i = 0; i < methods.Length; i++) { // get the current method in the loop MethodInfo method = methods[i]; // see if the method should be used to parse one or more material attributes AttributeParserAttribute[] parserAtts = (AttributeParserAttribute[])method.GetCustomAttributes(typeof(AttributeParserAttribute), true); // loop through each one we found and register its parser for (int j = 0; j < parserAtts.Length; j++) { AttributeParserAttribute parserAtt = parserAtts[j]; attribParsers.Add(parserAtt.Name, Delegate.CreateDelegate(typeof(AttributeParserMethod), method)); } // for } // for }