本文整理汇总了C#中HashSet.ToImmutableArray方法的典型用法代码示例。如果您正苦于以下问题:C# HashSet.ToImmutableArray方法的具体用法?C# HashSet.ToImmutableArray怎么用?C# HashSet.ToImmutableArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HashSet
的用法示例。
在下文中一共展示了HashSet.ToImmutableArray方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Build
public void Build(FileModel model, IHostService host)
{
model.File = Path.ChangeExtension(model.File, ".json");
var toc = (TocViewModel)model.Content;
HashSet<string> links = new HashSet<string>();
Dictionary<string, HashSet<string>> tocMap = new Dictionary<string, HashSet<string>>();
UpdateRelativePathAndAddTocMap(toc, model, links, tocMap, host);
model.Properties.LinkToFiles = links.ToImmutableArray();
model.Properties.TocMap = tocMap.ToImmutableDictionary();
// todo : metadata.
}
示例2: DetermineCascadedSymbolsAsync
public async Task<ImmutableArray<SymbolAndProjectId>> DetermineCascadedSymbolsAsync(
SymbolAndProjectId symbolAndProjectId, Solution solution, IImmutableSet<Project> projects = null, CancellationToken cancellationToken = default(CancellationToken))
{
var linkedSymbols = new HashSet<SymbolAndProjectId>();
var symbol = symbolAndProjectId.Symbol;
foreach (var location in symbol.DeclaringSyntaxReferences)
{
var originalDocument = solution.GetDocument(location.SyntaxTree);
// GetDocument will return null for locations in #load'ed trees.
// TODO: Remove this check and add logic to fetch the #load'ed tree's
// Document once https://github.com/dotnet/roslyn/issues/5260 is fixed.
if (originalDocument == null)
{
Debug.Assert(solution.Workspace.Kind == "Interactive");
continue;
}
foreach (var linkedDocumentId in originalDocument.GetLinkedDocumentIds())
{
var linkedDocument = solution.GetDocument(linkedDocumentId);
var linkedSyntaxRoot = await linkedDocument.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
// Defend against constructed solutions with inconsistent linked documents
if (!linkedSyntaxRoot.FullSpan.Contains(location.Span))
{
continue;
}
var linkedNode = linkedSyntaxRoot.FindNode(location.Span, getInnermostNodeForTie: true);
var semanticModel = await linkedDocument.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
var linkedSymbol = semanticModel.GetDeclaredSymbol(linkedNode, cancellationToken);
if (linkedSymbol != null &&
linkedSymbol.Kind == symbol.Kind &&
linkedSymbol.Name == symbol.Name)
{
var linkedSymbolAndProjectId = SymbolAndProjectId.Create(linkedSymbol, linkedDocument.Project.Id);
if (!linkedSymbols.Contains(linkedSymbolAndProjectId))
{
linkedSymbols.Add(linkedSymbolAndProjectId);
}
}
}
}
return linkedSymbols.ToImmutableArray();
}
示例3: Markup
public MarkupResult Markup(string src, string path)
{
var dependency = new HashSet<string>();
var html = _builder.CreateDfmEngine(new DfmRenderer() { Tokens = _tokens }).Markup(src, path, dependency);
var result = new MarkupResult
{
Html = html,
};
if (dependency.Count > 0)
{
result.Dependency = dependency.ToImmutableArray();
}
return result;
}
示例4: AddOrReplace
public static ILogger AddOrReplace(ILogger newLogger, ILogger oldLogger, Func<ILogger, bool> predicate)
{
if (newLogger == null)
{
return oldLogger;
}
if (oldLogger == null)
{
return newLogger;
}
var aggregateLogger = oldLogger as AggregateLogger;
if (aggregateLogger == null)
{
// replace old logger with new logger
if (predicate(oldLogger))
{
// this might not aggregate logger
return newLogger;
}
// merge two
return new AggregateLogger(ImmutableArray.Create(newLogger, oldLogger));
}
var set = new HashSet<ILogger>();
foreach (var logger in aggregateLogger._loggers)
{
// replace this logger with new logger
if (predicate(logger))
{
set.Add(newLogger);
continue;
}
// add old one back
set.Add(logger);
}
// add new logger. if we already added one, this will be ignored.
set.Add(newLogger);
return new AggregateLogger(set.ToImmutableArray());
}
示例5: Markup
public MarkupResult Markup(string src, string path)
{
var dependency = new HashSet<string>();
var json = _builder.CreateDfmEngine(new DfmJsonTokenTreeRender()).Markup(src, path, dependency);
if (json.Length != 0 && json.EndsWith(","))
{
json = json.Remove(json.Length - 1);
}
var result = new MarkupResult
{
// TODO: rename
Html = $"{{\"name\":\"0>0>markdown\",\"children\":[{json}]}}",
};
if (dependency.Count > 0)
{
result.Dependency = dependency.ToImmutableArray();
}
return result;
}
示例6: Create
public static AggregateLogger Create(params ILogger[] loggers)
{
var set = new HashSet<ILogger>();
// flatten loggers
foreach (var logger in loggers.WhereNotNull())
{
var aggregateLogger = logger as AggregateLogger;
if (aggregateLogger != null)
{
set.UnionWith(aggregateLogger.loggers);
continue;
}
set.Add(logger);
}
return new AggregateLogger(set.ToImmutableArray());
}
示例7: MarkupCore
private MarkupResult MarkupCore(string markdown, FileAndType ft)
{
var html = _engine.CreateDfmEngine(DocfxFlavoredMarked.Renderer).Markup(markdown, Path.Combine(ft.BaseDir, ft.File));
var doc = new HtmlDocument();
doc.LoadHtml(html);
var result = new MarkupResult();
var node = doc.DocumentNode.SelectSingleNode("//yamlheader");
if (node != null)
{
using (var sr = new StringReader(StringHelper.HtmlDecode(node.InnerHtml)))
{
result.YamlHeader = YamlUtility.Deserialize<Dictionary<string, object>>(sr).ToImmutableDictionary();
}
node.Remove();
}
var linkToFiles = new HashSet<string>();
foreach (var link in from n in doc.DocumentNode.Descendants()
where !string.Equals(n.Name, "xref", StringComparison.OrdinalIgnoreCase)
from attr in n.Attributes
where string.Equals(attr.Name, "src", StringComparison.OrdinalIgnoreCase) ||
string.Equals(attr.Name, "href", StringComparison.OrdinalIgnoreCase)
where !string.IsNullOrWhiteSpace(attr.Value)
select attr)
{
string linkFile;
string anchor = null;
if (PathUtility.IsRelativePath(link.Value))
{
var index = link.Value.IndexOf('#');
if (index == -1)
{
linkFile = link.Value;
}
else if (index == 0)
{
continue;
}
else
{
linkFile = link.Value.Remove(index);
anchor = link.Value.Substring(index);
}
var path = (RelativePath)ft.File + (RelativePath)linkFile;
var file = path.GetPathFromWorkingFolder();
link.Value = file + anchor;
linkToFiles.Add(HttpUtility.UrlDecode(file));
}
}
result.LinkToFiles = linkToFiles.ToImmutableArray();
result.LinkToUids = (from n in doc.DocumentNode.Descendants()
where string.Equals(n.Name, "xref", StringComparison.OrdinalIgnoreCase)
from attr in n.Attributes
where string.Equals(attr.Name, "href", StringComparison.OrdinalIgnoreCase)
where !string.IsNullOrWhiteSpace(attr.Value)
select attr.Value).ToImmutableHashSet();
using (var sw = new StringWriter())
{
doc.Save(sw);
result.Html = sw.ToString();
}
return result;
}
示例8: FindMatchingPackagesAsync
private async Task<ImmutableArray<PackageWithAssemblyResult>> FindMatchingPackagesAsync(
PackageSource source,
ISymbolSearchService searchService,
IPackageInstallerService installerService,
ISet<string> assemblyNames,
CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
var result = new HashSet<PackageWithAssemblyResult>();
foreach (var assemblyName in assemblyNames)
{
var packagesWithAssembly = await searchService.FindPackagesWithAssemblyAsync(
source.Name, assemblyName, cancellationToken).ConfigureAwait(false);
result.AddRange(packagesWithAssembly);
}
// Ensure the packages are sorted by rank.
var sortedPackages = result.ToImmutableArray().Sort();
return sortedPackages;
}
示例9: MarkupCore
public MarkupResult MarkupCore(string markdown, FileAndType ft)
{
var html = DocfxFlavoredMarked.Markup(markdown, Path.Combine(ft.BaseDir, ft.File));
var doc = new HtmlDocument();
doc.LoadHtml(html);
var result = new MarkupResult();
// TODO: how to get TITLE
// InnerText in HtmlAgilityPack is not decoded, should be a bug
var headerNode = doc.DocumentNode.SelectSingleNode("//h1|//h2|//h3");
result.Title = StringHelper.HtmlDecode(headerNode?.InnerText);
var node = doc.DocumentNode.SelectSingleNode("//yamlheader");
if (node != null)
{
using (var sr = new StringReader(StringHelper.HtmlDecode(node.InnerHtml)))
{
result.YamlHeader = YamlUtility.Deserialize<Dictionary<string, object>>(sr).ToImmutableDictionary();
}
node.Remove();
}
var linkToFiles = new HashSet<string>();
foreach (var link in from n in doc.DocumentNode.Descendants()
where !string.Equals(n.Name, "xref", StringComparison.OrdinalIgnoreCase)
from attr in n.Attributes
where string.Equals(attr.Name, "src", StringComparison.OrdinalIgnoreCase) ||
string.Equals(attr.Name, "href", StringComparison.OrdinalIgnoreCase)
where !string.IsNullOrWhiteSpace(attr.Value)
select attr)
{
string linkFile;
string anchor = null;
if (PathUtility.IsRelativePath(link.Value))
{
var index = link.Value.IndexOf('#');
if (index == -1)
{
linkFile = link.Value;
}
else if (index == 0)
{
continue;
}
else
{
linkFile = link.Value.Remove(index);
anchor = link.Value.Substring(index);
}
var path = (RelativePath)ft.File + (RelativePath)linkFile;
if (path.ParentDirectoryCount > 0)
{
Logger.LogError($"Cannot refer path: \"{path}\" out of project.", file: ft.File);
throw new DocumentException($"Cannot refer path \"{path}\" out of project in file \"{ft.File}\".");
}
var file = path.GetPathFromWorkingFolder();
link.Value = file + anchor;
linkToFiles.Add(HttpUtility.UrlDecode(file));
}
}
result.LinkToFiles = linkToFiles.ToImmutableArray();
result.LinkToUids = (from n in doc.DocumentNode.Descendants()
where string.Equals(n.Name, "xref", StringComparison.OrdinalIgnoreCase)
from attr in n.Attributes
where string.Equals(attr.Name, "href", StringComparison.OrdinalIgnoreCase)
where !string.IsNullOrWhiteSpace(attr.Value)
select attr.Value).ToImmutableArray();
using (var sw = new StringWriter())
{
doc.Save(sw);
result.Html = sw.ToString();
}
return result;
}