本文整理汇总了C#中Microsoft.VisualStudio.Package.ProjectNode.GetMkDocument方法的典型用法代码示例。如果您正苦于以下问题:C# ProjectNode.GetMkDocument方法的具体用法?C# ProjectNode.GetMkDocument怎么用?C# ProjectNode.GetMkDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.VisualStudio.Package.ProjectNode
的用法示例。
在下文中一共展示了ProjectNode.GetMkDocument方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetFileNamespace
/// <summary>
/// The goal here is to reduce the risk of name conflict between 2 classes
/// added in different directories. This code does NOT garanty uniqueness.
/// To garanty uniqueness, you should change this function to work with
/// the language service to verify that the namespace+class generated does
/// not conflict.
/// </summary>
/// <param name="fileFullPath">Full path to the new file</param>
/// <returns>Namespace to use for the new file</returns>
public string GetFileNamespace(string fileFullPath, ProjectNode node)
{
// Get base namespace from the project
string namespce = node.GetProjectProperty("RootNamespace");
if (String.IsNullOrEmpty(namespce))
namespce = Path.GetFileNameWithoutExtension(fileFullPath); ;
// If the item is added to a subfolder, the name space should reflect this.
// This is done so that class names from 2 files with the same name but different
// directories don't conflict.
string relativePath = Path.GetDirectoryName(fileFullPath);
string projectPath = Path.GetDirectoryName(node.GetMkDocument());
// Our project system only support adding files that are sibling of the project file or that are in subdirectories.
if (String.Compare(projectPath, 0, relativePath, 0, projectPath.Length, true, CultureInfo.CurrentCulture) == 0)
{
relativePath = relativePath.Substring(projectPath.Length);
}
else
{
Debug.Fail("Adding an item to the project that is NOT under the project folder.");
// We are going to use the full file path for generating the namespace
}
// Get the list of parts
int index = 0;
string[] pathParts;
pathParts = relativePath.Split(Path.DirectorySeparatorChar);
// Use a string builder with default size being the expected size
StringBuilder result = new StringBuilder(namespce, namespce.Length + relativePath.Length + 1);
// For each path part
while (index < pathParts.Length)
{
string part = pathParts[index];
++index;
// This could happen if the path had leading/trailing slash, we want to ignore empty pieces
if (String.IsNullOrEmpty(part))
continue;
// If we reach here, we will be adding something, so add a namespace separator '.'
result.Append('.');
// Make sure it starts with a letter
if (!char.IsLetter(part, 0))
result.Append('N');
// Filter invalid namespace characters
foreach (char c in part)
{
if (char.IsLetterOrDigit(c))
result.Append(c);
}
}
return result.ToString();
}