public static Type[] GetAppliesTo(Type type) { if (!type.IsSubclassOf(typeof(Extension))) { return(null); } object[] attrs = type.GetCustomAttributes(typeof(Attributes.ExtensionAttribute), true); if (attrs != null && attrs.Length > 0) { Attributes.ExtensionAttribute extattr = (Attributes.ExtensionAttribute)attrs[0]; return(extattr.AppliesTo); } else { return(new Type[] {}); } }
public static string GetDescription(Type type) { if (!type.IsSubclassOf(typeof(Extension))) { return(null); } object[] attrs = type.GetCustomAttributes(typeof(Attributes.ExtensionAttribute), true); string desc = ""; if (attrs != null && attrs.Length > 0) { Attributes.ExtensionAttribute extattr = (Attributes.ExtensionAttribute)attrs[0]; if (extattr.Description != null) { desc = extattr.Description; } } return(desc); }
public static string GetName(Type type) { if (!type.IsSubclassOf(typeof(Extension))) { return(null); } object[] attrs = type.GetCustomAttributes(typeof(Attributes.ExtensionAttribute), true); string name = null; if (attrs != null && attrs.Length > 0) { Attributes.ExtensionAttribute extattr = (Attributes.ExtensionAttribute)attrs[0]; name = extattr.Name; } if (String.IsNullOrEmpty(name)) { name = type.Name; } return(name); }
private void CheckAppliesTo() { object[] attrs = GetType().GetCustomAttributes(typeof(Attributes.ExtensionAttribute), true); if (attrs != null && attrs.Length > 0) { Attributes.ExtensionAttribute attr = (Attributes.ExtensionAttribute)attrs[0]; if (attr.AppliesTo != null && attr.AppliesTo.Length > 0) { Type opttype = d_job.Optimizer.GetType(); foreach (Type type in attr.AppliesTo) { if (type == opttype || opttype.IsSubclassOf(type)) { return; } } throw new Exception(String.Format("The extension `{0}' cannot be applied to optimizer `{1}'", Name, d_job.Optimizer.Name)); } } }