Wiki

Clone wiki

C# RuleDocs / RuleData

Home

#RuleData The main purpose of RuleData is to be an intermediary collector of documentation data. It contains several pieces of info that is useful to someone who wants to customize the formatting.

##Constructors ###public static RuleData Construct<T>(string name, string description, T caller)

  • name: the name we want to appear in the documentation.
  • description: a plain text description of the rule.
  • caller: the instance creating the documentation.

##Properties ###public string Name { get; } The name of the rule, this is always passed in during construction. It can be the class name, but may well be something else. Most likely, it should be a name that a business manager will understand.

###public string Description { get; } The description of the rule, this is always passed in during construction.

###public bool HasChildren { get; } Checks to see if the current rule has any child rules.

###public int Depth { get; } Returns how deep the number of levels of child rules goes. A depth of 0 means there are no children. A depth of 3 means the current rule has one or more child rules, one or more grandchild rules, and one or more great grandchild rules.

###public string TypeName { get; } This is the name of the class that implements IDocumented. It may differ from Name. This field is not used in the default formatting. It is provided in the event that someone wishes to provide more advanced formatting, and by having the class name, the formatting may be applied to a specific class regardless of the value in the Name property.

This value is why "this" is in the call to RuleData.Construct();

###public string FullTypeName { get; } This is the same purpose as TypeName, but is provided in the event that there are collisions when using TypeName. ###public ReadOnlyCollection<string> GetAllKeys() This should only be typically called from the root rule. It will gather every data key for the current rule, and any of its child rules.

The keys are important for generating the header line of the documentation, as well as extracting the values from each rule.

##Methods ###public RuleData AddData<T>(string key, T value)

  • key: the key associated with the data
  • value: the value of the data.

This will add one piece of data to the RuleData instance. The passed in value will be converted to a string. The value will be associated with the key.

###public RuleData AddChild(IDocumented rule)

  • rule: this is any class that the current class contains, and that we want documented as well.

Note: it takes an IDocumented instance. From that instance, CreateDocumentation() will automatically be called.

###public RuleData AddChild<T>(T rule)

  • rule: this is any class that the current class contains.

This version of AddRule() will check to see if the passed in rule has implemented IDocumented. If it has, then the appropriate documentation will be generated. If it has not implemented IDocumented, then documentation will be generated indicating that documentation is missing.

###public string GetValue(string key) This will return a value that is associated with the key. If there is no data associated with a specific key, then an empty string will be returned. This method is always safe to call.

###public ReadOnlyCollection<RuleData> Children { get; } Returns a collection of child rules that may be iterated over.

Updated