diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2009-09-20 21:18:59 -0700 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2009-09-21 08:06:22 -0700 |
commit | bbe3f9cc9c8a1e5909273c1a162a63ea7a66afd8 (patch) | |
tree | c91f66e642c4d26fca266e226b3f2765f546d700 /tools/Sandcastle/Source/BuildAssembler/BuildComponents/CodeReference.cs | |
parent | 627014f0bbc3fd576277375e70f8391d150b0a67 (diff) | |
download | DotNetOpenAuth-bbe3f9cc9c8a1e5909273c1a162a63ea7a66afd8.zip DotNetOpenAuth-bbe3f9cc9c8a1e5909273c1a162a63ea7a66afd8.tar.gz DotNetOpenAuth-bbe3f9cc9c8a1e5909273c1a162a63ea7a66afd8.tar.bz2 |
Switched out the Sandcastle binaries for the source code.
Diffstat (limited to 'tools/Sandcastle/Source/BuildAssembler/BuildComponents/CodeReference.cs')
-rw-r--r-- | tools/Sandcastle/Source/BuildAssembler/BuildComponents/CodeReference.cs | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/tools/Sandcastle/Source/BuildAssembler/BuildComponents/CodeReference.cs b/tools/Sandcastle/Source/BuildAssembler/BuildComponents/CodeReference.cs new file mode 100644 index 0000000..974a28d --- /dev/null +++ b/tools/Sandcastle/Source/BuildAssembler/BuildComponents/CodeReference.cs @@ -0,0 +1,115 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// + +using System; +using System.Text.RegularExpressions; +using System.Collections.Generic; + + +namespace Microsoft.Ddue.Tools { + + public enum CodeReferenceType { + Invalid, // not initialized, invalid reference string + Snippet, // MSDN style snippet for all build targets + Msdn, // MSDN style snippet for MSDN build only + Run, // runnable code sample with pop-up source browser for WebDocs build + View // code sample shown in pop-up source browser for WebDocs build + } + + /// <summary> + /// The CodeReference class encapsulates DDUE code reference elements and provides easy access + /// to individual code reference parts, such as the type, name, title, etc.. + /// </summary> + /// <remarks> + /// Examples of valid code reference strings include: + /// - SampleName#SnippetNumber + /// - SampleName#SnippetNumber1,SnippetNumber2,SnippetNumber3 + /// - msdn:SampleName#SnippetNumber + /// - run:SampleName + /// - run:SampleName;title text + /// - run:SampleName#startPage.aspx + /// - run:SampleName/path/to/startPage.aspx + /// - run:SampleName#startPage.aspx;title text + /// - run:SampleName/path/to/startPage.aspx;title text + /// - view:SampleName + /// - view:SampleName#defaultFile + /// - view:SampleName/path/to/defaultFile + /// - view:SampleName#defaultFile;title text + /// - view:SampleName/path/to/defaultFile;title text + /// </remarks> + public class CodeReference { + + string _ddueCodeReference; + public string DdueCodeReference { + get { return _ddueCodeReference; } + } + + CodeReferenceType _type; + public CodeReferenceType Type { + get { return _type; } + } + + string _exampleName; + public string ExampleName { + get { return _exampleName; } + } + + string _examplePath; + public string ExamplePath { + get { return _examplePath; } + } + + string _snippetId; + public string SnippetId { + get { return _snippetId; } + } + + string _title; + public string Title { + get { return _title; } + } + + public CodeReference(string ddueCodeReference) { + _ddueCodeReference = ddueCodeReference; + Parse(); + } + + static Regex codeReferenceRx = new Regex( + @"^\s*(" + + @"((?<type>msdn|run|view):)?" + + @"(?<examplePath>(" + + @"(?<exampleName>[\w\.,\-]+)" + + @"((#(?<snippetId>[\w,]+))|(([/\\#,\.\w\-]+)?))" + + @"))" + + @"(;(?<title>.*))?" + + @")\s*$", + RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase | RegexOptions.Compiled); + + void Parse() { + Match m = codeReferenceRx.Match(DdueCodeReference); + if (m.Success) { + _exampleName = m.Groups["exampleName"].Value; + _snippetId = m.Groups["snippetId"].Value; + _examplePath = m.Groups["examplePath"].Value; + _title = m.Groups["title"].Value; + // The default value of _type is CodeReferenceType.Invalid, if it isn't set in the following + // block. + if (m.Groups["type"].Length > 0) { + try { + _type = (CodeReferenceType)Enum.Parse(typeof(CodeReferenceType), m.Groups["type"].Value, true); + } + catch (ArgumentException) { + // _type = CodeReferenceType.Invalid + } + } + else if (m.Groups["exampleName"].Length > 0 && m.Groups["snippetId"].Length > 0) { + _type = CodeReferenceType.Snippet; + } + } + } + + public override string ToString() { + return DdueCodeReference; + } + } +}
\ No newline at end of file |