public static void GetAllPublicStaticClassesOfAsm(Assembly asm, Dictionary <string, Type> map) { foreach (Type type in asm.GetTypes()) { if (type.IsStatic()) { object[] customAttributes = type.GetCustomAttributes(true); ToolAttribute toolAttribute = (ToolAttribute)customAttributes .Where(attr => attr is ToolAttribute).First(); if (toolAttribute != null || customAttributes .Where(attr => attr is NoToolAttribute).Count() <= 0) { string key = toolAttribute != null ? toolAttribute.Name : type.Name; if (map.ContainsKey(key)) { throw new Exception(string.Format( "Invalid Type name of static Tool class \"{0}\", used by {1} AND {2}", key, map[type.Name].FullName, type.FullName)); } map.Add(key, type); } } } }
public void AddStaticMethodsOfAsm(Assembly asm) { foreach (Type type in asm.GetTypes()) { HashSet <string> stringSet = new HashSet <string>(); object[] customAttributes = type.GetCustomAttributes(true); bool flag1 = customAttributes .Where(attr => attr is ToolAttribute).Count() > 0; if (flag1 || customAttributes .Where(attr => attr is NoToolAttribute).Count() <= 0) { foreach (MethodInfo method in type.GetMethods( BindingFlags.Static | BindingFlags.Public | BindingFlags.InvokeMethod)) { string name = method.Name; if (!name.StartsWith("get_") && !name.StartsWith("set_") && method.GetCustomAttributes <NoToolAttribute>().Length <= 0) { ToolAttribute toolAttribute = method.GetCustomAttributes <ToolAttribute>() .FirstOrDefault(); if (toolAttribute != null) { name = toolAttribute.Name ?? name; } else if (!flag1) { continue; } bool flag2 = true; foreach (ParameterInfo parameter in method.GetParameters()) { if (!parameter.ParameterType.IsSimpleType()) { flag2 = false; break; } } if (flag2) { if (!stringSet.Contains(name)) { stringSet.Add(name); Add(name, null, method); } else if (toolAttribute != null) { throw new ToolException( "Found multiple static methods with ToolAttribute, called: {0}.- Make sure that the names are unique.", (object)method.GetFullMemberName()); } } else if (toolAttribute != null) { throw new ToolException( "Static method {0} was marked with ToolAttribute but had non-simple Parameters. - Make sure to only give methods with simple parameters the ToolAttribute. You can exclude them with the NoToolAttribute.", (object)method.GetFullMemberName()); } } } } } }