public static void AddValueToNode( ref StringBuilder working, FieldInfo field, KPartModuleFieldConfigurationDocumentationAttribute attribute) { if (working == null) { return; } if (field == null) { return; } if (attribute == null) { return; } //Create description; working.Append("\t//"); working.AppendLine(attribute.Description); //WriteValue working.Append("\t"); working.Append(field.Name); working.Append(" = "); working.AppendLine(attribute.DefaultValue); working.AppendLine(); }
/// <summary> /// Adds all fields within the current moduleType /// to the referenced StrinBuilder. /// </summary> /// <returns> /// When TRUE, the fields were successfully added /// to the module; otherwise FALSE. /// </returns> public static bool AddModuleFields(ref StringBuilder working, Type moduleType) { if (working == null) { return(false); } if (moduleType == null) { return(false); } if (!typeof(PartModule).IsAssignableFrom(moduleType)) { return(false); } bool hasDocumentation = false; working.AppendLine("MODULE"); working.AppendLine("{"); working.Append("\tname = "); working.AppendLine(moduleType.Name); working.AppendLine(); foreach (FieldInfo current in moduleType.UnderlyingSystemType.GetFields(BindingFlags.Public | BindingFlags.Instance)) { object[] objs = current.GetCustomAttributes( typeof(KPartModuleFieldConfigurationDocumentationAttribute), true); if (objs == null || objs.Length != 1) { continue; } KPartModuleFieldConfigurationDocumentationAttribute attr = objs[0] as KPartModuleFieldConfigurationDocumentationAttribute; if (attr == null) { continue; } AddValueToNode(ref working, current, attr); hasDocumentation = true; } working.Remove(working.Length - 1, 1); working.AppendLine("}"); return(hasDocumentation); }
public static void AddValueToNode( ref StringBuilder working, FieldInfo field, KPartModuleFieldConfigurationDocumentationAttribute attribute) { if(working == null) return; if(field == null) return; if(attribute == null) return; //Create description; working.Append("\t//"); working.AppendLine(attribute.Description); //WriteValue working.Append("\t"); working.Append(field.Name); working.Append(" = "); working.AppendLine(attribute.DefaultValue); working.AppendLine(); }