/***************************************************/ public MultiOutputAttribute(int index, string name, string description, InputClassificationAttribute classification, Type typeId) { Index = index; Name = name; Description = description; Classification = classification; }
public static string OutputDescription(this MethodBase method) { if (method == null) { return(""); } OutputAttribute attribute = method.GetCustomAttribute <OutputAttribute>(); InputClassificationAttribute classificationAttribute = null; string desc = ""; if (attribute != null && !string.IsNullOrWhiteSpace(attribute.Description)) { desc = attribute.Description + Environment.NewLine; } if (attribute != null) { classificationAttribute = attribute.Classification; } desc += method.OutputType().Description(classificationAttribute); return(desc); }
public static string Description(this MemberInfo member, bool addTypeDescription = true) { if (member == null) { Compute.RecordWarning("Cannot query the description of a null member info object. An empty string will be returned instead."); return(""); } DescriptionAttribute descriptionAttribute = member.GetCustomAttribute <DescriptionAttribute>(); InputClassificationAttribute classification = member.GetCustomAttribute <InputClassificationAttribute>(); string desc = ""; if (descriptionAttribute != null && !string.IsNullOrWhiteSpace(descriptionAttribute.Description)) { desc = descriptionAttribute.Description + Environment.NewLine; } if (addTypeDescription && member is PropertyInfo && (typeof(IObject).IsAssignableFrom(((PropertyInfo)member).PropertyType))) { desc += ((PropertyInfo)member).PropertyType.Description(classification) + Environment.NewLine; } return(desc); }
/***************************************************/ public OutputAttribute(string name, string description, Type classification = null) { Name = name; Description = description; if (classification != null && typeof(InputClassificationAttribute).IsAssignableFrom(classification) && classification != typeof(InputClassificationAttribute)) { Classification = (InputClassificationAttribute)Activator.CreateInstance(classification); } }
public static List <OutputAttribute> OutputAttributes(this MethodBase method) { if (method == null) { return(new List <OutputAttribute>()); } if (method.IsMultipleOutputs()) { Dictionary <int, MultiOutputAttribute> outputDefs = method.GetCustomAttributes <MultiOutputAttribute>().ToDictionary(x => x.Index); Type[] types = method.OutputType().GetGenericArguments(); List <OutputAttribute> outputs = new List <OutputAttribute>(); for (int i = 0; i < types.Length; i++) { if (outputDefs.ContainsKey(i)) { string desc = outputDefs[i].Description; if (types[i] != null) { desc += Environment.NewLine; InputClassificationAttribute classification = outputDefs[i].Classification; desc += types[i].UnderlyingType().Type.Description(classification); } outputs.Add(new OutputAttribute(outputDefs[i].Name, desc)); } else { string name = types[i].UnderlyingType().Type.Name.Substring(0, 1); int nbSame = outputs.Where(x => x.Name.StartsWith(name)).Count(); if (nbSame > 0) { name += (nbSame + 1).ToString(); } outputs.Add(new OutputAttribute(name, "")); } } return(outputs); } else { OutputAttribute attribute = method.GetCustomAttribute <OutputAttribute>(); if (attribute != null) { return new List <OutputAttribute> { attribute } } ; else { return(new List <OutputAttribute>()); } } }
public static string Description(this ParameterInfo parameter, bool addTypeDescription = true) { if (parameter == null) { Compute.RecordWarning("Cannot query the description of a null parameter object. An empty string will be returned instead."); return(""); } IEnumerable <InputAttribute> inputDesc = parameter.Member.GetCustomAttributes <InputAttribute>().Where(x => x.Name == parameter.Name); InputClassificationAttribute classification = null; string desc = ""; if (inputDesc.Count() > 0) { desc = inputDesc.First().Description + Environment.NewLine; classification = inputDesc.First().Classification; } else { //If no input descs are found, check if inputFromProperty descs can be found IEnumerable <InputFromProperty> inputFromPropDesc = parameter.Member.GetCustomAttributes <InputFromProperty>().Where(x => x.InputName == parameter.Name); //Only valid for engine type methods MethodInfo methodInfo = parameter.Member as MethodInfo; if (inputFromPropDesc.Count() > 0 && methodInfo != null && methodInfo.DeclaringType != null) { Type returnType = methodInfo.ReturnType.UnderlyingType().Type; if (returnType != null) { //Try to find matching proeprty type, matching both name and type PropertyInfo prop = returnType.GetProperty(inputFromPropDesc.First().PropertyName, parameter.ParameterType); //If found return description of property if (prop != null) { return(prop.Description()); } } } } if (addTypeDescription && parameter.ParameterType != null) { desc += parameter.ParameterType.Description(classification); } return(desc); }
/***************************************************/ public InputAttribute(string name, string description, InputClassificationAttribute classification, Type typeId) { Name = name; Description = description; Classification = classification; }
private static string Description(this InputClassificationAttribute classification) { return(""); }
public static string IDescription(this InputClassificationAttribute classification) { return(Description(classification as dynamic)); }
public static string Description(this Type type, InputClassificationAttribute classification) { if (type == null) { Compute.RecordWarning("Cannot query the description of a null type. An empty string will be returned instead."); return(""); } DescriptionAttribute attribute = type.GetCustomAttribute <DescriptionAttribute>(); string desc = ""; //If a quantity attribute is present, this is used to generate the default description if (classification != null) { desc += classification.IDescription(); desc += " (as a " + type.ToText(type.Namespace.StartsWith("BH.")) + ")"; return(desc); } //Add the default description desc += "This is a " + type.ToText(type.Namespace.StartsWith("BH.")); if (attribute != null) { desc += ":" + Environment.NewLine; desc += attribute.Description; } //If type is enum, list options with descriptions if (type.IsEnum) { desc += EnumItemDescription(type); } Type innerType = type; while (typeof(IEnumerable).IsAssignableFrom(innerType) && innerType.IsGenericType) { innerType = innerType.GenericTypeArguments.First(); } if (innerType.IsInterface) { desc += Environment.NewLine; desc += "This can be of the following types: "; List <Type> t = innerType.ImplementingTypes(); int m = Math.Min(15, t.Count); for (int i = 0; i < m; i++) { desc += $"{t[i].ToText()}, "; } if (t.Count > m) { desc += "and more..."; } else { desc = desc.Remove(desc.Length - 2, 2); } return(desc); } return(desc); }