codeReference
A codeReference element is used to insert a
commonly used code snippet into a conceptual topic. The code snippets are
stored in an external file.
When using the Sandcastle Help File Builder or the standalone build
components from it, the Code Block Component offers
the same set of features and several others for both inline and external code
snippets. In addition, it supports many other languages and can import code
from working source code files which allows you to pull in examples from
working projects that you can maintain and build without having to update a
separate example snippets file. As such, you may prefer to use it
rather than the code snippets file.
To use a code reference, simply insert its ID as the inner text of
a codeReference element anywhere within a
topic. You can combine multiple snippets with a common example ID into one
code reference by specifying their sample IDs as a comma-separated list after
the hash character.
This example uses the samples from the example file in the
Code Snippets File topic. The first three are the
individual snippets. The last one combines the "create instance"
snippets into one example.
Define a class
<codeReference>ClassDefinition#Define</codeReference>
Create a local instance
<codeReference>CreateInstance#Local</codeReference>
Create a static (shared) instance
<codeReference>CreateInstance#Static</codeReference>
An example of combining snippets with a common example ID
<codeReference>CreateInstance#Local,Static</codeReference>
Define a class
public class CSharpClass()
{
}
Public Class VBClass
End Class
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
Create a local instance
CSharpClass x = new CSharpClass();
Dim x As VBClass = New VBClass()
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
Create a static (shared) instance
public static CSharpClass sharedInstance = new CSharpClass();
Public Shared sharedInstance As VBClass = New VBClass()
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
An example of combining snippets with a common example ID
CSharpClass x = new CSharpClass();
...
public static CSharpClass sharedInstance = new CSharpClass();
Dim x As VBClass = New VBClass()
...
Public Shared sharedInstance As VBClass = New VBClass()
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.