Skip to content

Commit 0bf3148

Browse files
committed
Keep MemberNotNullAttribute in sync for src<->ref
Enable ApiCompat protection for the MemberNotNull attribute.
1 parent b61687b commit 0bf3148

File tree

14 files changed

+25
-21
lines changed

14 files changed

+25
-21
lines changed

eng/ApiCompatExcludeAttributes.txt

-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
T:System.Diagnostics.CodeAnalysis.MemberNotNullAttribute
21
T:System.Diagnostics.DebuggerGuidedStepThroughAttribute
32
T:System.Runtime.CompilerServices.EagerStaticClassConstructionAttribute

eng/DefaultGenApiDocIds.txt

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ T:System.ComponentModel.Design.Serialization.RootDesignerSerializerAttribute
44
T:System.Configuration.ConfigurationPropertyAttribute
55
T:System.Diagnostics.CodeAnalysis.DynamicDependencyAttribute
66
T:System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute
7-
T:System.Diagnostics.CodeAnalysis.MemberNotNullAttribute
87
T:System.Diagnostics.CodeAnalysis.SuppressMessageAttribute
98
T:System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute
109
T:System.Diagnostics.DebuggerBrowsableAttribute

eng/referenceAssemblies.props

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616
<!-- We dont need to add null annotation within the ref for explicit interface methods. -->
1717
<NoWarn>$(NoWarn);CS8617</NoWarn>
18+
19+
<!-- MemberNotNullAttribute without underlying field. -->
20+
<NoWarn>$(NoWarn);CS8776</NoWarn>
1821
</PropertyGroup>
1922

2023
<!-- All reference assemblies should have a ReferenceAssemblyAttribute and the 0x70 flag which prevents them from loading. -->

src/libraries/System.ComponentModel.TypeConverter/ref/System.ComponentModel.TypeConverter.cs

+1
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ public CultureInfoConverter() { }
277277
public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) { throw null; }
278278
public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) { throw null; }
279279
protected virtual string GetCultureName(System.Globalization.CultureInfo culture) { throw null; }
280+
[System.Diagnostics.CodeAnalysis.MemberNotNullAttribute("_values")]
280281
public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext? context) { throw null; }
281282
public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext? context) { throw null; }
282283
public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext? context) { throw null; }

src/libraries/System.Diagnostics.TraceSource/ref/System.Diagnostics.TraceSource.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public EventTypeFilter(System.Diagnostics.SourceLevels level) { }
4242
public partial class SourceFilter : System.Diagnostics.TraceFilter
4343
{
4444
public SourceFilter(string source) { }
45-
public string Source { get { throw null; } set { } }
45+
public string Source { get { throw null; } [System.Diagnostics.CodeAnalysis.MemberNotNullAttribute("_src")] set { } }
4646
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; }
4747
}
4848
[System.FlagsAttribute]
@@ -84,16 +84,16 @@ public sealed partial class SwitchAttribute : System.Attribute
8484
{
8585
public SwitchAttribute(string switchName, System.Type switchType) { }
8686
public string? SwitchDescription { get { throw null; } set { } }
87-
public string SwitchName { get { throw null; } set { } }
88-
public System.Type SwitchType { get { throw null; } set { } }
87+
public string SwitchName { get { throw null; } [System.Diagnostics.CodeAnalysis.MemberNotNullAttribute("_name")] set { } }
88+
public System.Type SwitchType { get { throw null; } [System.Diagnostics.CodeAnalysis.MemberNotNullAttribute("_type")] set { } }
8989
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Types may be trimmed from the assembly.")]
9090
public static System.Diagnostics.SwitchAttribute[] GetAll(System.Reflection.Assembly assembly) { throw null; }
9191
}
9292
[System.AttributeUsageAttribute(System.AttributeTargets.Class)]
9393
public sealed partial class SwitchLevelAttribute : System.Attribute
9494
{
9595
public SwitchLevelAttribute(System.Type switchLevelType) { }
96-
public System.Type SwitchLevelType { get { throw null; } set { } }
96+
public System.Type SwitchLevelType { get { throw null; } [System.Diagnostics.CodeAnalysis.MemberNotNullAttribute("_type")] set { } }
9797
}
9898
public sealed partial class Trace
9999
{

src/libraries/System.DirectoryServices/ref/System.DirectoryServices.cs

+1
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ protected override void Dispose(bool disposing) { }
182182
public void InvokeSet(string propertyName, params object?[]? args) { }
183183
public void MoveTo(System.DirectoryServices.DirectoryEntry newParent) { }
184184
public void MoveTo(System.DirectoryServices.DirectoryEntry newParent, string? newName) { }
185+
[System.Diagnostics.CodeAnalysis.MemberNotNullAttribute("_adsObject")]
185186
public void RefreshCache() { }
186187
public void RefreshCache(string[] propertyNames) { }
187188
public void Rename(string? newName) { }

src/libraries/System.Net.Primitives/ref/System.Net.Primitives.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ public NetworkCredential(string? userName, System.Security.SecureString? passwor
297297
public NetworkCredential(string? userName, string? password) { }
298298
public NetworkCredential(string? userName, string? password, string? domain) { }
299299
[System.Diagnostics.CodeAnalysis.AllowNullAttribute]
300-
public string Domain { get { throw null; } set { } }
300+
public string Domain { get { throw null; } [System.Diagnostics.CodeAnalysis.MemberNotNullAttribute("_domain")] set { } }
301301
[System.Diagnostics.CodeAnalysis.AllowNullAttribute]
302302
public string Password { get { throw null; } set { } }
303303
[System.CLSCompliantAttribute(false)]
@@ -538,4 +538,4 @@ public enum ChannelBindingKind
538538
Unique = 25,
539539
Endpoint = 26,
540540
}
541-
}
541+
}

src/libraries/System.Runtime/ref/System.Runtime.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9494,7 +9494,7 @@ public DateTimeFormatInfo() { }
94949494
public string[] AbbreviatedMonthGenitiveNames { get { throw null; } set { } }
94959495
public string[] AbbreviatedMonthNames { get { throw null; } set { } }
94969496
public string AMDesignator { get { throw null; } set { } }
9497-
public System.Globalization.Calendar Calendar { get { throw null; } set { } }
9497+
public System.Globalization.Calendar Calendar { get { throw null; } [System.Diagnostics.CodeAnalysis.MemberNotNullAttribute("calendar")] set { } }
94989498
public System.Globalization.CalendarWeekRule CalendarWeekRule { get { throw null; } set { } }
94999499
public static System.Globalization.DateTimeFormatInfo CurrentInfo { get { throw null; } }
95009500
public string DateSeparator { get { throw null; } set { } }
@@ -9943,7 +9943,7 @@ public partial class StringInfo
99439943
public StringInfo() { }
99449944
public StringInfo(string value) { }
99459945
public int LengthInTextElements { get { throw null; } }
9946-
public string String { get { throw null; } set { } }
9946+
public string String { get { throw null; } [System.Diagnostics.CodeAnalysis.MemberNotNullAttribute("_str")] set { } }
99479947
public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? value) { throw null; }
99489948
public override int GetHashCode() { throw null; }
99499949
public static string GetNextTextElement(string str) { throw null; }

src/libraries/System.Security.AccessControl/ref/System.Security.AccessControl.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ public abstract partial class KnownAce : System.Security.AccessControl.GenericAc
317317
{
318318
internal KnownAce() { }
319319
public int AccessMask { get { throw null; } set { } }
320-
public System.Security.Principal.SecurityIdentifier SecurityIdentifier { get { throw null; } set { } }
320+
public System.Security.Principal.SecurityIdentifier SecurityIdentifier { get { throw null; } [System.Diagnostics.CodeAnalysis.MemberNotNullAttribute("_sid")] set { } }
321321
}
322322
public abstract partial class NativeObjectSecurity : System.Security.AccessControl.CommonObjectSecurity
323323
{

src/libraries/System.Security.Cryptography/ref/System.Security.Cryptography.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public AsnEncodedData(System.Security.Cryptography.Oid? oid, System.ReadOnlySpan
167167
public AsnEncodedData(string oid, byte[] rawData) { }
168168
public AsnEncodedData(string oid, System.ReadOnlySpan<byte> rawData) { }
169169
public System.Security.Cryptography.Oid? Oid { get { throw null; } set { } }
170-
public byte[] RawData { get { throw null; } set { } }
170+
public byte[] RawData { get { throw null; } [System.Diagnostics.CodeAnalysis.MemberNotNullAttribute("_rawData")] set { } }
171171
public virtual void CopyFrom(System.Security.Cryptography.AsnEncodedData asnEncodedData) { }
172172
public virtual string Format(bool multiLine) { throw null; }
173173
}

src/libraries/System.ServiceProcess.ServiceController/ref/System.ServiceProcess.ServiceController.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public ServiceBase() { }
4040
public int ExitCode { get { throw null; } set { } }
4141
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
4242
protected System.IntPtr ServiceHandle { get { throw null; } }
43-
public string ServiceName { get { throw null; } set { } }
43+
public string ServiceName { get { throw null; } [System.Diagnostics.CodeAnalysis.MemberNotNullAttribute("_serviceName")] set { } }
4444
protected override void Dispose(bool disposing) { }
4545
protected virtual void OnContinue() { }
4646
protected virtual void OnCustomCommand(int command) { }

src/libraries/System.Text.RegularExpressions/ref/System.Text.RegularExpressions.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,10 @@ public RegexCompilationInfo(string pattern, System.Text.RegularExpressions.Regex
223223
public RegexCompilationInfo(string pattern, System.Text.RegularExpressions.RegexOptions options, string name, string fullnamespace, bool ispublic, System.TimeSpan matchTimeout) { }
224224
public bool IsPublic { get { throw null; } set { } }
225225
public System.TimeSpan MatchTimeout { get { throw null; } set { } }
226-
public string Name { get { throw null; } set { } }
227-
public string Namespace { get { throw null; } set { } }
226+
public string Name { get { throw null; } [System.Diagnostics.CodeAnalysis.MemberNotNullAttribute("_name")] set { } }
227+
public string Namespace { get { throw null; } [System.Diagnostics.CodeAnalysis.MemberNotNullAttribute("_nspace")] set { } }
228228
public System.Text.RegularExpressions.RegexOptions Options { get { throw null; } set { } }
229-
public string Pattern { get { throw null; } set { } }
229+
public string Pattern { get { throw null; } [System.Diagnostics.CodeAnalysis.MemberNotNullAttribute("_pattern")] set { } }
230230
}
231231
[System.AttributeUsageAttribute(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
232232
public sealed partial class RegexGeneratorAttribute : System.Attribute

src/libraries/System.Xml.ReaderWriter/ref/System.Xml.ReaderWriter.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -283,13 +283,13 @@ public partial class XmlDeclaration : System.Xml.XmlLinkedNode
283283
{
284284
protected internal XmlDeclaration(string version, string? encoding, string? standalone, System.Xml.XmlDocument doc) { }
285285
[System.Diagnostics.CodeAnalysis.AllowNullAttribute]
286-
public string Encoding { get { throw null; } set { } }
286+
public string Encoding { get { throw null; } [System.Diagnostics.CodeAnalysis.MemberNotNullAttribute("_encoding")] set { } }
287287
public override string InnerText { get { throw null; } set { } }
288288
public override string LocalName { get { throw null; } }
289289
public override string Name { get { throw null; } }
290290
public override System.Xml.XmlNodeType NodeType { get { throw null; } }
291291
[System.Diagnostics.CodeAnalysis.AllowNullAttribute]
292-
public string Standalone { get { throw null; } set { } }
292+
public string Standalone { get { throw null; } [System.Diagnostics.CodeAnalysis.MemberNotNullAttribute("_standalone")] set { } }
293293
public override string? Value { get { throw null; } set { } }
294294
public string Version { get { throw null; } }
295295
public override System.Xml.XmlNode CloneNode(bool deep) { throw null; }
@@ -1337,11 +1337,11 @@ public XmlWriterSettings() { }
13371337
public bool CloseOutput { get { throw null; } set { } }
13381338
public System.Xml.ConformanceLevel ConformanceLevel { get { throw null; } set { } }
13391339
public bool DoNotEscapeUriAttributes { get { throw null; } set { } }
1340-
public System.Text.Encoding Encoding { get { throw null; } set { } }
1340+
public System.Text.Encoding Encoding { get { throw null; } [System.Diagnostics.CodeAnalysis.MemberNotNullAttribute("_encoding")] set { } }
13411341
public bool Indent { get { throw null; } set { } }
1342-
public string IndentChars { get { throw null; } set { } }
1342+
public string IndentChars { get { throw null; } [System.Diagnostics.CodeAnalysis.MemberNotNullAttribute("_indentChars")] set { } }
13431343
public System.Xml.NamespaceHandling NamespaceHandling { get { throw null; } set { } }
1344-
public string NewLineChars { get { throw null; } set { } }
1344+
public string NewLineChars { get { throw null; } [System.Diagnostics.CodeAnalysis.MemberNotNullAttribute("_newLineChars")] set { } }
13451345
public System.Xml.NewLineHandling NewLineHandling { get { throw null; } set { } }
13461346
public bool NewLineOnAttributes { get { throw null; } set { } }
13471347
public bool OmitXmlDeclaration { get { throw null; } set { } }

src/libraries/System.Xml.XmlSerializer/ref/System.Xml.XmlSerializer.cs

+1
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,7 @@ protected void ReadEndElement() { }
519519
protected object? ReadReferencedElement(string? name, string? ns) { throw null; }
520520
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Members from serialized types may be trimmed if not referenced directly")]
521521
protected void ReadReferencedElements() { }
522+
[System.Diagnostics.CodeAnalysis.MemberNotNullAttribute("_callbacks")]
522523
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Members from serialized types may be trimmed if not referenced directly")]
523524
protected object? ReadReferencingElement(string? name, string? ns, bool elementCanBeType, out string? fixupReference) { throw null; }
524525
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Members from serialized types may be trimmed if not referenced directly")]

0 commit comments

Comments
 (0)