本文整理汇总了C#中ImmutableArray.OrderBy方法的典型用法代码示例。如果您正苦于以下问题:C# ImmutableArray.OrderBy方法的具体用法?C# ImmutableArray.OrderBy怎么用?C# ImmutableArray.OrderBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImmutableArray
的用法示例。
在下文中一共展示了ImmutableArray.OrderBy方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateAttributeLists
public static SyntaxList<AttributeListSyntax> GenerateAttributeLists(
ImmutableArray<AttributeData> attributes,
CodeGenerationOptions options,
SyntaxToken? target = null)
{
if (options.MergeAttributes)
{
var attributeNodes = attributes.OrderBy(a => a.AttributeClass.Name).Select((a) => GenerateAttribute(a, options)).WhereNotNull().ToList();
return attributeNodes.Count == 0
? default(SyntaxList<AttributeListSyntax>)
: SyntaxFactory.SingletonList(SyntaxFactory.AttributeList(
target.HasValue ? SyntaxFactory.AttributeTargetSpecifier(target.Value) : null,
SyntaxFactory.SeparatedList(attributeNodes)));
}
else
{
var attributeDeclarations = attributes.OrderBy(a => a.AttributeClass.Name).Select(a => GenerateAttributeDeclaration(a, target, options)).WhereNotNull().ToList();
return attributeDeclarations.Count == 0
? default(SyntaxList<AttributeListSyntax>)
: SyntaxFactory.List<AttributeListSyntax>(attributeDeclarations);
}
}
示例2: WriteDiagnosticResults
private static void WriteDiagnosticResults(ImmutableArray<Tuple<ProjectId, Diagnostic>> diagnostics, string fileName)
{
var orderedDiagnostics =
diagnostics
.OrderBy(i => i.Item2.Id)
.ThenBy(i => i.Item2.Location.SourceTree?.FilePath, StringComparer.OrdinalIgnoreCase)
.ThenBy(i => i.Item2.Location.SourceSpan.Start)
.ThenBy(i => i.Item2.Location.SourceSpan.End);
var uniqueLines = new HashSet<string>();
StringBuilder completeOutput = new StringBuilder();
StringBuilder uniqueOutput = new StringBuilder();
foreach (var diagnostic in orderedDiagnostics)
{
string message = diagnostic.Item2.ToString();
string uniqueMessage = $"{diagnostic.Item1}: {diagnostic.Item2}";
completeOutput.AppendLine(message);
if (uniqueLines.Add(uniqueMessage))
{
uniqueOutput.AppendLine(message);
}
}
string directoryName = Path.GetDirectoryName(fileName);
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);
string extension = Path.GetExtension(fileName);
string uniqueFileName = Path.Combine(directoryName, $"{fileNameWithoutExtension}-Unique{extension}");
File.WriteAllText(fileName, completeOutput.ToString(), Encoding.UTF8);
File.WriteAllText(uniqueFileName, uniqueOutput.ToString(), Encoding.UTF8);
}
示例3: WriteDiagnosticsToLog
private static void WriteDiagnosticsToLog(string logFile, Project project, ImmutableArray<Diagnostic> diagnostics)
{
lock (_logLock)
{
try
{
var header = $"Found {diagnostics.Length} diagnostic in project '{project.Name}'";
var stringResult =
string.Join(
Environment.NewLine,
diagnostics
.OrderBy(i => i.Id)
.ThenBy(i => i.Location.SourceTree?.FilePath ?? "")
.ThenBy(i => i.Location.SourceSpan.Start)
.Select(i => i.ToString()));
File.AppendAllText(logFile, string.Join(Environment.NewLine, header, stringResult));
}
catch (Exception e)
{
WriteError($"Failed to write a log file:{Environment.NewLine}:{e}", enabled: true);
}
}
}
示例4: PrintDiagnostics
private static void PrintDiagnostics(Project project, ImmutableArray<Diagnostic> diagnostics)
{
lock (_consoleLock)
{
WriteCaption($"Found {diagnostics.Length} diagnostic in project '{project.Name}'", enabled: true);
foreach (var rd in diagnostics
.OrderBy(i => i.Id)
.ThenBy(i => i.Location.SourceTree?.FilePath ?? "")
.ThenBy(i => i.Location.SourceSpan.Start))
{
ConsoleDiagnosticPrinters[rd.Severity](rd.ToString());
}
}
}
示例5: LogDiagnostics
public static void LogDiagnostics(Project project, ImmutableArray<Diagnostic> diagnostics)
{
var caption = CreateCaption($"Found {diagnostics.Length} diagnostic in project '{project.Name}'");
var orderedDiagnostics =
diagnostics
.OrderBy(i => i.Id)
.ThenBy(i => i.Location.SourceTree?.FilePath ?? "")
.ThenBy(i => i.Location.SourceSpan.Start)
.ToList();
lock (_consoleLock)
{
WriteCaption(caption);
foreach (var rd in orderedDiagnostics)
{
ConsoleDiagnosticPrinters[rd.Severity](rd.ToString());
}
}
string logEntry = $"{caption}\r\n{string.Join("\r\n", orderedDiagnostics)}";
WriteFile(logEntry);
}