Skip to content

Add more StringSyntaxAttribute syntaxes #67621

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Apr 7, 2022
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public partial class ConsoleFormatterOptions
{
public ConsoleFormatterOptions() { }
public bool IncludeScopes { get { throw null; } set { } }
[System.Diagnostics.CodeAnalysis.StringSyntaxAttribute(System.Diagnostics.CodeAnalysis.StringSyntaxAttribute.DateTimeFormat)]
[System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("DateTimeFormat")]
public string TimestampFormat { get { throw null; } set { } }
public bool UseUtcTimestamp { get { throw null; } set { } }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public RangeAttribute([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMember
[System.AttributeUsageAttribute(System.AttributeTargets.Field | System.AttributeTargets.Parameter | System.AttributeTargets.Property, AllowMultiple=false)]
public partial class RegularExpressionAttribute : System.ComponentModel.DataAnnotations.ValidationAttribute
{
public RegularExpressionAttribute([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute(System.Diagnostics.CodeAnalysis.StringSyntaxAttribute.Regex)] string pattern) { }
public RegularExpressionAttribute([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("Regex")] string pattern) { }
public int MatchTimeoutInMilliseconds { get { throw null; } set { } }
public System.TimeSpan MatchTimeout { get { throw null; } }
public string Pattern { get { throw null; } }
Expand Down
16 changes: 8 additions & 8 deletions src/libraries/System.Console/ref/System.Console.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@ public static void Write(long value) { }
public static void Write(object? value) { }
public static void Write(float value) { }
public static void Write(string? value) { }
public static void Write(string format, object? arg0) { }
public static void Write(string format, object? arg0, object? arg1) { }
public static void Write(string format, object? arg0, object? arg1, object? arg2) { }
public static void Write(string format, params object?[]? arg) { }
public static void Write([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("CompositeFormat")] string format, object? arg0) { }
public static void Write([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("CompositeFormat")] string format, object? arg0, object? arg1) { }
public static void Write([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("CompositeFormat")] string format, object? arg0, object? arg1, object? arg2) { }
public static void Write([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("CompositeFormat")] string format, params object?[]? arg) { }
[System.CLSCompliantAttribute(false)]
public static void Write(uint value) { }
[System.CLSCompliantAttribute(false)]
Expand All @@ -180,10 +180,10 @@ public static void WriteLine(long value) { }
public static void WriteLine(object? value) { }
public static void WriteLine(float value) { }
public static void WriteLine(string? value) { }
public static void WriteLine(string format, object? arg0) { }
public static void WriteLine(string format, object? arg0, object? arg1) { }
public static void WriteLine(string format, object? arg0, object? arg1, object? arg2) { }
public static void WriteLine(string format, params object?[]? arg) { }
public static void WriteLine([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("CompositeFormat")] string format, object? arg0) { }
public static void WriteLine([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("CompositeFormat")] string format, object? arg0, object? arg1) { }
public static void WriteLine([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("CompositeFormat")] string format, object? arg0, object? arg1, object? arg2) { }
public static void WriteLine([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("CompositeFormat")] string format, params object?[]? arg) { }
[System.CLSCompliantAttribute(false)]
public static void WriteLine(uint value) { }
[System.CLSCompliantAttribute(false)]
Expand Down
17 changes: 9 additions & 8 deletions src/libraries/System.Console/src/System/Console.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -808,25 +809,25 @@ public static void WriteLine(string? value)
}

[MethodImplAttribute(MethodImplOptions.NoInlining)]
public static void WriteLine(string format, object? arg0)
public static void WriteLine([StringSyntax(StringSyntaxAttribute.CompositeFormat)] string format, object? arg0)
{
Out.WriteLine(format, arg0);
}

[MethodImplAttribute(MethodImplOptions.NoInlining)]
public static void WriteLine(string format, object? arg0, object? arg1)
public static void WriteLine([StringSyntax(StringSyntaxAttribute.CompositeFormat)] string format, object? arg0, object? arg1)
{
Out.WriteLine(format, arg0, arg1);
}

[MethodImplAttribute(MethodImplOptions.NoInlining)]
public static void WriteLine(string format, object? arg0, object? arg1, object? arg2)
public static void WriteLine([StringSyntax(StringSyntaxAttribute.CompositeFormat)] string format, object? arg0, object? arg1, object? arg2)
{
Out.WriteLine(format, arg0, arg1, arg2);
}

[MethodImplAttribute(MethodImplOptions.NoInlining)]
public static void WriteLine(string format, params object?[]? arg)
public static void WriteLine([StringSyntax(StringSyntaxAttribute.CompositeFormat)] string format, params object?[]? arg)
{
if (arg == null) // avoid ArgumentNullException from String.Format
Out.WriteLine(format, null, null); // faster than Out.WriteLine(format, (Object)arg);
Expand All @@ -835,25 +836,25 @@ public static void WriteLine(string format, params object?[]? arg)
}

[MethodImplAttribute(MethodImplOptions.NoInlining)]
public static void Write(string format, object? arg0)
public static void Write([StringSyntax(StringSyntaxAttribute.CompositeFormat)] string format, object? arg0)
{
Out.Write(format, arg0);
}

[MethodImplAttribute(MethodImplOptions.NoInlining)]
public static void Write(string format, object? arg0, object? arg1)
public static void Write([StringSyntax(StringSyntaxAttribute.CompositeFormat)] string format, object? arg0, object? arg1)
{
Out.Write(format, arg0, arg1);
}

[MethodImplAttribute(MethodImplOptions.NoInlining)]
public static void Write(string format, object? arg0, object? arg1, object? arg2)
public static void Write([StringSyntax(StringSyntaxAttribute.CompositeFormat)] string format, object? arg0, object? arg1, object? arg2)
{
Out.Write(format, arg0, arg1, arg2);
}

[MethodImplAttribute(MethodImplOptions.NoInlining)]
public static void Write(string format, params object?[]? arg)
public static void Write([StringSyntax(StringSyntaxAttribute.CompositeFormat)] string format, params object?[]? arg)
{
if (arg == null) // avoid ArgumentNullException from String.Format
Out.Write(format, null, null); // faster than Out.Write(format, (Object)arg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public DelimitedListTraceListener(string? fileName, string? name) { }
public override void TraceData(System.Diagnostics.TraceEventCache? eventCache, string source, System.Diagnostics.TraceEventType eventType, int id, object? data) { }
public override void TraceData(System.Diagnostics.TraceEventCache? eventCache, string source, System.Diagnostics.TraceEventType eventType, int id, params object?[]? data) { }
public override void TraceEvent(System.Diagnostics.TraceEventCache? eventCache, string source, System.Diagnostics.TraceEventType eventType, int id, string? message) { }
public override void TraceEvent(System.Diagnostics.TraceEventCache? eventCache, string source, System.Diagnostics.TraceEventType eventType, int id, string? format, params object?[]? args) { }
public override void TraceEvent(System.Diagnostics.TraceEventCache? eventCache, string source, System.Diagnostics.TraceEventType eventType, int id, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("CompositeFormat")] string? format, params object?[]? args) { }
}
public partial class TextWriterTraceListener : System.Diagnostics.TraceListener
{
Expand Down Expand Up @@ -56,7 +56,7 @@ public override void Fail(string? message, string? detailMessage) { }
public override void TraceData(System.Diagnostics.TraceEventCache? eventCache, string source, System.Diagnostics.TraceEventType eventType, int id, object? data) { }
public override void TraceData(System.Diagnostics.TraceEventCache? eventCache, string source, System.Diagnostics.TraceEventType eventType, int id, params object?[]? data) { }
public override void TraceEvent(System.Diagnostics.TraceEventCache? eventCache, string source, System.Diagnostics.TraceEventType eventType, int id, string? message) { }
public override void TraceEvent(System.Diagnostics.TraceEventCache? eventCache, string source, System.Diagnostics.TraceEventType eventType, int id, string? format, params object?[]? args) { }
public override void TraceEvent(System.Diagnostics.TraceEventCache? eventCache, string source, System.Diagnostics.TraceEventType eventType, int id, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("CompositeFormat")] string? format, params object?[]? args) { }
public override void TraceTransfer(System.Diagnostics.TraceEventCache? eventCache, string source, int id, string? message, System.Guid relatedActivityId) { }
public override void Write(string? message) { }
public override void WriteLine(string? message) { }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Text;
using System.Globalization;
using System.IO;
using System.Collections;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Globalization;
using System.Text;

namespace System.Diagnostics
{
Expand Down Expand Up @@ -82,7 +83,7 @@ public string Delimiter
// warning would be hitted.
protected override string[] GetSupportedAttributes() => new string[] { DelimiterKey };

public override void TraceEvent(TraceEventCache? eventCache, string source, TraceEventType eventType, int id, string? format, params object?[]? args)
public override void TraceEvent(TraceEventCache? eventCache, string source, TraceEventType eventType, int id, [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string? format, params object?[]? args)
{
if (Filter != null && !Filter.ShouldTrace(eventCache, source, eventType, id, format, args, null, null))
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Runtime.Versioning;
Expand Down Expand Up @@ -84,7 +85,7 @@ public override void Fail(string? message, string? detailMessage)
}));
}

public override void TraceEvent(TraceEventCache? eventCache, string source, TraceEventType eventType, int id, string? format, params object?[]? args)
public override void TraceEvent(TraceEventCache? eventCache, string source, TraceEventType eventType, int id, [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string? format, params object?[]? args)
{
if (Filter != null && !Filter.ShouldTrace(eventCache, source, eventType, id, format, args, null, null))
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ public partial class EventTypeFilter : System.Diagnostics.TraceFilter
{
public EventTypeFilter(System.Diagnostics.SourceLevels level) { }
public System.Diagnostics.SourceLevels EventType { get { throw null; } set { } }
public override bool ShouldTrace(System.Diagnostics.TraceEventCache? cache, string source, System.Diagnostics.TraceEventType eventType, int id, string? formatOrMessage, object?[]? args, object? data1, object?[]? data) { throw null; }
public override bool ShouldTrace(System.Diagnostics.TraceEventCache? cache, string source, System.Diagnostics.TraceEventType eventType, int id, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("CompositeFormat")] string? formatOrMessage, object?[]? args, object? data1, object?[]? data) { throw null; }
}
public partial class SourceFilter : System.Diagnostics.TraceFilter
{
public SourceFilter(string source) { }
public string Source { get { throw null; } set { } }
public override bool ShouldTrace(System.Diagnostics.TraceEventCache? cache, string source, System.Diagnostics.TraceEventType eventType, int id, string? formatOrMessage, object?[]? args, object? data1, object?[]? data) { throw null; }
public override bool ShouldTrace(System.Diagnostics.TraceEventCache? cache, string source, System.Diagnostics.TraceEventType eventType, int id, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("CompositeFormat")] string? formatOrMessage, object?[]? args, object? data1, object?[]? data) { throw null; }
}
[System.FlagsAttribute]
public enum SourceLevels
Expand Down Expand Up @@ -124,15 +124,15 @@ public static void Refresh() { }
[System.Diagnostics.ConditionalAttribute("TRACE")]
public static void TraceError(string? message) { }
[System.Diagnostics.ConditionalAttribute("TRACE")]
public static void TraceError(string format, params object?[]? args) { }
public static void TraceError([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("CompositeFormat")] string format, params object?[]? args) { }
[System.Diagnostics.ConditionalAttribute("TRACE")]
public static void TraceInformation(string? message) { }
[System.Diagnostics.ConditionalAttribute("TRACE")]
public static void TraceInformation(string format, params object?[]? args) { }
public static void TraceInformation([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("CompositeFormat")] string format, params object?[]? args) { }
[System.Diagnostics.ConditionalAttribute("TRACE")]
public static void TraceWarning(string? message) { }
[System.Diagnostics.ConditionalAttribute("TRACE")]
public static void TraceWarning(string format, params object?[]? args) { }
public static void TraceWarning([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("CompositeFormat")] string format, params object?[]? args) { }
[System.Diagnostics.ConditionalAttribute("TRACE")]
public static void Unindent() { }
[System.Diagnostics.ConditionalAttribute("TRACE")]
Expand Down Expand Up @@ -194,7 +194,7 @@ public enum TraceEventType
public abstract partial class TraceFilter
{
protected TraceFilter() { }
public abstract bool ShouldTrace(System.Diagnostics.TraceEventCache? cache, string source, System.Diagnostics.TraceEventType eventType, int id, string? formatOrMessage, object?[]? args, object? data1, object?[]? data);
public abstract bool ShouldTrace(System.Diagnostics.TraceEventCache? cache, string source, System.Diagnostics.TraceEventType eventType, int id, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("CompositeFormat")] string? formatOrMessage, object?[]? args, object? data1, object?[]? data);
}
public enum TraceLevel
{
Expand Down Expand Up @@ -228,7 +228,7 @@ public virtual void TraceData(System.Diagnostics.TraceEventCache? eventCache, st
public virtual void TraceData(System.Diagnostics.TraceEventCache? eventCache, string source, System.Diagnostics.TraceEventType eventType, int id, params object?[]? data) { }
public virtual void TraceEvent(System.Diagnostics.TraceEventCache? eventCache, string source, System.Diagnostics.TraceEventType eventType, int id) { }
public virtual void TraceEvent(System.Diagnostics.TraceEventCache? eventCache, string source, System.Diagnostics.TraceEventType eventType, int id, string? message) { }
public virtual void TraceEvent(System.Diagnostics.TraceEventCache? eventCache, string source, System.Diagnostics.TraceEventType eventType, int id, string? format, params object?[]? args) { }
public virtual void TraceEvent(System.Diagnostics.TraceEventCache? eventCache, string source, System.Diagnostics.TraceEventType eventType, int id, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("CompositeFormat")] string? format, params object?[]? args) { }
public virtual void TraceTransfer(System.Diagnostics.TraceEventCache? eventCache, string source, int id, string? message, System.Guid relatedActivityId) { }
public virtual void Write(object? o) { }
public virtual void Write(object? o, string? category) { }
Expand Down Expand Up @@ -301,11 +301,11 @@ public void TraceEvent(System.Diagnostics.TraceEventType eventType, int id) { }
[System.Diagnostics.ConditionalAttribute("TRACE")]
public void TraceEvent(System.Diagnostics.TraceEventType eventType, int id, string? message) { }
[System.Diagnostics.ConditionalAttribute("TRACE")]
public void TraceEvent(System.Diagnostics.TraceEventType eventType, int id, string? format, params object?[]? args) { }
public void TraceEvent(System.Diagnostics.TraceEventType eventType, int id, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("CompositeFormat")] string? format, params object?[]? args) { }
[System.Diagnostics.ConditionalAttribute("TRACE")]
public void TraceInformation(string? message) { }
[System.Diagnostics.ConditionalAttribute("TRACE")]
public void TraceInformation(string? format, params object?[]? args) { }
public void TraceInformation([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("CompositeFormat")] string? format, params object?[]? args) { }
[System.Diagnostics.ConditionalAttribute("TRACE")]
public void TraceTransfer(int id, string? message, System.Guid relatedActivityId) { }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Diagnostics.CodeAnalysis;

namespace System.Diagnostics
{
Expand All @@ -14,7 +15,7 @@ public EventTypeFilter(SourceLevels level)
_level = level;
}

public override bool ShouldTrace(TraceEventCache? cache, string source, TraceEventType eventType, int id, string? formatOrMessage,
public override bool ShouldTrace(TraceEventCache? cache, string source, TraceEventType eventType, int id, [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string? formatOrMessage,
object?[]? args, object? data1, object?[]? data)
{
return ((int)eventType & (int)_level) != 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public SourceFilter(string source)
Source = source;
}

public override bool ShouldTrace(TraceEventCache? cache, string source!!, TraceEventType eventType, int id, string? formatOrMessage,
public override bool ShouldTrace(TraceEventCache? cache, string source!!, TraceEventType eventType, int id, [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string? formatOrMessage,
object?[]? args, object? data1, object?[]? data)
{
return string.Equals(_src, source);
Expand Down
Loading