Skip to content

Commit

Permalink
Using file-scoped namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
lethek committed Dec 16, 2024
1 parent 56721f2 commit dfb16d1
Show file tree
Hide file tree
Showing 36 changed files with 2,001 additions and 2,048 deletions.
265 changes: 132 additions & 133 deletions src/Serilog.Sinks.LINQPad/Formatting/ThemedDisplayValueFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,207 +19,206 @@
using Serilog.Formatting.Json;
using Serilog.Sinks.LINQPad.Themes;

namespace Serilog.Sinks.LINQPad.Formatting
namespace Serilog.Sinks.LINQPad.Formatting;

internal class ThemedDisplayValueFormatter : ThemedValueFormatter
{
internal class ThemedDisplayValueFormatter : ThemedValueFormatter
{

public ThemedDisplayValueFormatter(ConsoleTheme theme, IFormatProvider formatProvider) : base(theme)
=> _formatProvider = formatProvider;
public ThemedDisplayValueFormatter(ConsoleTheme theme, IFormatProvider formatProvider) : base(theme)
=> _formatProvider = formatProvider;


public override ThemedValueFormatter SwitchTheme(ConsoleTheme theme)
=> new ThemedDisplayValueFormatter(theme, _formatProvider);
public override ThemedValueFormatter SwitchTheme(ConsoleTheme theme)
=> new ThemedDisplayValueFormatter(theme, _formatProvider);


protected override int VisitScalarValue(ThemedValueFormatterState state, ScalarValue scalar)
{
if (scalar == null) {
throw new ArgumentNullException(nameof(scalar));
}
return FormatLiteralValue(scalar, state.Output, state.Format);
protected override int VisitScalarValue(ThemedValueFormatterState state, ScalarValue scalar)
{
if (scalar == null) {
throw new ArgumentNullException(nameof(scalar));
}
return FormatLiteralValue(scalar, state.Output, state.Format);
}


protected override int VisitSequenceValue(ThemedValueFormatterState state, SequenceValue sequence)
{
if (sequence == null) {
throw new ArgumentNullException(nameof(sequence));
}
protected override int VisitSequenceValue(ThemedValueFormatterState state, SequenceValue sequence)
{
if (sequence == null) {
throw new ArgumentNullException(nameof(sequence));
}

var count = 0;
var count = 0;

using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count)) {
state.Output.Write('[');
}
using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count)) {
state.Output.Write('[');
}

var delim = String.Empty;
for (var index = 0; index < sequence.Elements.Count; ++index) {
if (delim.Length != 0) {
using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count)) {
state.Output.Write(delim);
}
var delim = String.Empty;
for (var index = 0; index < sequence.Elements.Count; ++index) {
if (delim.Length != 0) {
using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count)) {
state.Output.Write(delim);
}

delim = ", ";
Visit(state, sequence.Elements[index]);
}

using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count)) {
state.Output.Write(']');
}

return count;
delim = ", ";
Visit(state, sequence.Elements[index]);
}

using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count)) {
state.Output.Write(']');
}

protected override int VisitStructureValue(ThemedValueFormatterState state, StructureValue structure)
{
var count = 0;
return count;
}

if (structure.TypeTag != null) {
using (ApplyStyle(state.Output, ConsoleThemeStyle.Name, ref count)) {
state.Output.Write(structure.TypeTag);
}

state.Output.Write(' ');
}
protected override int VisitStructureValue(ThemedValueFormatterState state, StructureValue structure)
{
var count = 0;

using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count)) {
state.Output.Write('{');
if (structure.TypeTag != null) {
using (ApplyStyle(state.Output, ConsoleThemeStyle.Name, ref count)) {
state.Output.Write(structure.TypeTag);
}

var delim = String.Empty;
for (var index = 0; index < structure.Properties.Count; ++index) {
if (delim.Length != 0) {
using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count)) {
state.Output.Write(delim);
}
}

delim = ", ";

var property = structure.Properties[index];
state.Output.Write(' ');
}

using (ApplyStyle(state.Output, ConsoleThemeStyle.Name, ref count)) {
state.Output.Write(property.Name);
}
using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count)) {
state.Output.Write('{');
}

var delim = String.Empty;
for (var index = 0; index < structure.Properties.Count; ++index) {
if (delim.Length != 0) {
using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count)) {
state.Output.Write('=');
state.Output.Write(delim);
}
}

delim = ", ";

var property = structure.Properties[index];

count += Visit(state.Nest(), property.Value);
using (ApplyStyle(state.Output, ConsoleThemeStyle.Name, ref count)) {
state.Output.Write(property.Name);
}

using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count)) {
state.Output.Write('}');
state.Output.Write('=');
}

return count;
count += Visit(state.Nest(), property.Value);
}

using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count)) {
state.Output.Write('}');
}

protected override int VisitDictionaryValue(ThemedValueFormatterState state, DictionaryValue dictionary)
{
var count = 0;
return count;
}

using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count)) {
state.Output.Write('{');
}

var delim = String.Empty;
foreach (var element in dictionary.Elements) {
if (delim.Length != 0) {
using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count)) {
state.Output.Write(delim);
}
}
protected override int VisitDictionaryValue(ThemedValueFormatterState state, DictionaryValue dictionary)
{
var count = 0;

delim = ", ";
using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count)) {
state.Output.Write('{');
}

var delim = String.Empty;
foreach (var element in dictionary.Elements) {
if (delim.Length != 0) {
using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count)) {
state.Output.Write('[');
state.Output.Write(delim);
}
}

using (ApplyStyle(state.Output, ConsoleThemeStyle.String, ref count)) {
count += Visit(state.Nest(), element.Key);
}
delim = ", ";

using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count)) {
state.Output.Write("]=");
}
using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count)) {
state.Output.Write('[');
}

count += Visit(state.Nest(), element.Value);
using (ApplyStyle(state.Output, ConsoleThemeStyle.String, ref count)) {
count += Visit(state.Nest(), element.Key);
}

using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count)) {
state.Output.Write('}');
state.Output.Write("]=");
}

return count;
count += Visit(state.Nest(), element.Value);
}

using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count)) {
state.Output.Write('}');
}

public int FormatLiteralValue(ScalarValue scalar, TextWriter output, string format)
{
var value = scalar.Value;
var count = 0;
return count;
}

if (value == null) {
using (ApplyStyle(output, ConsoleThemeStyle.Null, ref count)) {
output.Write("null");
}
return count;

public int FormatLiteralValue(ScalarValue scalar, TextWriter output, string format)
{
var value = scalar.Value;
var count = 0;

if (value == null) {
using (ApplyStyle(output, ConsoleThemeStyle.Null, ref count)) {
output.Write("null");
}
return count;
}

if (value is string str) {
using (ApplyStyle(output, ConsoleThemeStyle.String, ref count)) {
if (format != "l") {
JsonValueFormatter.WriteQuotedJsonString(str, output);
} else {
output.Write(str);
}
if (value is string str) {
using (ApplyStyle(output, ConsoleThemeStyle.String, ref count)) {
if (format != "l") {
JsonValueFormatter.WriteQuotedJsonString(str, output);
} else {
output.Write(str);
}
return count;
}
return count;
}

if (value is ValueType) {
if (value is int || value is uint || value is long || value is ulong ||
value is decimal || value is byte || value is sbyte || value is short ||
value is ushort || value is float || value is double) {
using (ApplyStyle(output, ConsoleThemeStyle.Number, ref count)) {
scalar.Render(output, format, _formatProvider);
}
return count;
if (value is ValueType) {
if (value is int || value is uint || value is long || value is ulong ||
value is decimal || value is byte || value is sbyte || value is short ||
value is ushort || value is float || value is double) {
using (ApplyStyle(output, ConsoleThemeStyle.Number, ref count)) {
scalar.Render(output, format, _formatProvider);
}
return count;
}

if (value is bool b) {
using (ApplyStyle(output, ConsoleThemeStyle.Boolean, ref count)) {
output.Write(b);
}

return count;
if (value is bool b) {
using (ApplyStyle(output, ConsoleThemeStyle.Boolean, ref count)) {
output.Write(b);
}

if (value is char ch) {
using (ApplyStyle(output, ConsoleThemeStyle.Scalar, ref count)) {
output.Write('\'');
output.Write(ch);
output.Write('\'');
}
return count;
}
return count;
}

using (ApplyStyle(output, ConsoleThemeStyle.Scalar, ref count)) {
scalar.Render(output, format, _formatProvider);
if (value is char ch) {
using (ApplyStyle(output, ConsoleThemeStyle.Scalar, ref count)) {
output.Write('\'');
output.Write(ch);
output.Write('\'');
}
return count;
}

return count;
}

using (ApplyStyle(output, ConsoleThemeStyle.Scalar, ref count)) {
scalar.Render(output, format, _formatProvider);
}

private readonly IFormatProvider _formatProvider;
return count;
}


private readonly IFormatProvider _formatProvider;
}
Loading

0 comments on commit dfb16d1

Please sign in to comment.