本文整理汇总了C#中FileInfo.StartsWith方法的典型用法代码示例。如果您正苦于以下问题:C# FileInfo.StartsWith方法的具体用法?C# FileInfo.StartsWith怎么用?C# FileInfo.StartsWith使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileInfo
的用法示例。
在下文中一共展示了FileInfo.StartsWith方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DumpProjRefs
public static void DumpProjRefs(string projectFilename, string baseDirectory)
{
List<string> files = new List<string>();
var stream = new MemoryStream(File.ReadAllBytes(projectFilename)); // cache file in memoty
var document = XDocument.Load(stream);
var xmlNamespaceManager = new XmlNamespaceManager(new NameTable());
xmlNamespaceManager.AddNamespace("ns", namespaceName);
IEnumerable<XElement> listOfSourceFiles = document.XPathSelectElements("/ns:Project/ns:ItemGroup/ns:ProjectReference[@Include]", xmlNamespaceManager);
foreach (var el in listOfSourceFiles)
{
files.Add(el.Attribute("Include").Value);
}
string separator = new string(Path.DirectorySeparatorChar, 1);
string projDir = (new FileInfo(projectFilename)).Directory.FullName;
foreach (string relativeName in files)
{
var correctedRelativeName = relativeName.Replace("\\", separator);
string fullFileName = Path.Combine(projDir, correctedRelativeName);
fullFileName = new FileInfo(fullFileName).FullName;
string shortName;
if (fullFileName.StartsWith(baseDirectory, StringComparison.InvariantCulture))
{
shortName = fullFileName.Substring(baseDirectory.Length);
if (shortName.StartsWith(separator, StringComparison.InvariantCulture))
{
shortName = shortName.Substring(1);
}
}
else
{
shortName = fullFileName;
}
Console.WriteLine(shortName);
}
}