Well, thatβs what I came up with.
I use a special xml tag in dependency properties that will be replaced by xsl conversion. This could have been done without it, but then Visual Studio displays a warning because the field is displayed undocumented.
The C # property is documented as usual, just make sure you don't forget the value description.
Visual studio creates an XML file from these comments during creation. With a little xsl conversion, the dpdoc node is replaced with a modified version of the property documentation. The resulting xml file is the same as if we had a well-documented property identifier. It even includes a short note that there is an alternative way to access a variable:
Thus, both APIs have proper documentation, and we do not need to duplicate the documentation in the code. The xsl conversion can be performed in post-build events or integrated into the documentation creation process.
Here is xsl:
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="//dpdoc"> <xsl:variable name="propertyName" select="concat('P:', substring(../@name,3,string-length(../@name)-10))" /> <summary> <xsl:apply-templates select="//member[@name=$propertyName]/value/node()"/> </summary> <xsl:apply-templates select="//member[@name=$propertyName]/*[not(self::remarks)][not(self::summary)][not(self::value)]"/> <remarks> <xsl:apply-templates select="//member[@name=$propertyName]/remarks/node()"/> <para> This dependency property can be accessed via the <see> <xsl:attribute name="cref"><xsl:value-of select="$propertyName"/></xsl:attribute> </see> property. </para> </remarks> </xsl:template> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> </xsl:stylesheet>
Why I want to have it this way:
- The property identifier (
DependencyProperty instance) and the property are publicly available and therefore can be legally used to access the property. We have two APIs for the same boolean variable. - The code documentation should describe what is not yet visible. In this context, it should describe the value of the property and its value and how to use it correctly. Because both property identifiers and C # properties refer to the same boolean, they have the same value.
- The user is free to choose one of two ways to access the logical variable and does not need to know the other. These documents must be properly documented.
- Copying pasted code comments is just as bad as copying code.
Stefan
source share