diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2009-10-31 16:27:49 -0700 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2009-10-31 16:27:49 -0700 |
commit | 55d6e4be43225184f9a656e6d9cc8fc1e8e7387b (patch) | |
tree | c382ef957455af8a39f80789dff9b112e97c2fe6 /tools/Sandcastle/Source/BuildAssembler/BuildComponents/CodeReference.cs | |
parent | 07a8ecbc4fc50d11179f7e0b3fadb9f2be430ae5 (diff) | |
parent | ebf5efb48cddbfaf08aec24117b7c5f9626f1c02 (diff) | |
download | DotNetOpenAuth-55d6e4be43225184f9a656e6d9cc8fc1e8e7387b.zip DotNetOpenAuth-55d6e4be43225184f9a656e6d9cc8fc1e8e7387b.tar.gz DotNetOpenAuth-55d6e4be43225184f9a656e6d9cc8fc1e8e7387b.tar.bz2 |
Merge branch 'contracts'
Diffstat (limited to 'tools/Sandcastle/Source/BuildAssembler/BuildComponents/CodeReference.cs')
-rw-r--r-- | tools/Sandcastle/Source/BuildAssembler/BuildComponents/CodeReference.cs | 117 |
1 files changed, 117 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..c0cbd11 --- /dev/null +++ b/tools/Sandcastle/Source/BuildAssembler/BuildComponents/CodeReference.cs @@ -0,0 +1,117 @@ +// Copyright © Microsoft Corporation. +// This source file is subject to the Microsoft Permissive License. +// See http://www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx. +// All other 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 |