Skip to content

Commit 20956ef

Browse files
authored
Prepare System.Xaml for nullable reference type annotations (#8520)
* start process of annotating System.Xaml for NRT * showcase: annotate EventConverter
1 parent 98d7e17 commit 20956ef

File tree

179 files changed

+648
-296
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

179 files changed

+648
-296
lines changed

src/Microsoft.DotNet.Wpf/src/Common/src/System/SR.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
#nullable disable
6+
57
using System;
68
using System.Resources;
79
using System.Runtime.CompilerServices;

src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/CriticalExceptions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
#nullable disable
6+
57
using System;
68

79
#if PBTCOMPILER

src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/FriendAccessAllowedAttribute.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
#nullable disable
6+
57
// Description: Implementation of a FriendAccessAllowedAttribute attribute that is used to mark internal metadata
68
// that is allowed to be accessed from friend assemblies.
79

@@ -10,7 +12,7 @@
1012
#if WINDOWS_BASE
1113
namespace MS.Internal.WindowsBase
1214
#elif PRESENTATION_CORE
13-
namespace MS.Internal.PresentationCore
15+
namespace MS.Internal.PresentationCore
1416
#elif PRESENTATIONFRAMEWORK
1517
namespace MS.Internal.PresentationFramework
1618
#elif PRESENTATION_CFF_RASTERIZER

src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/SafeSecurityHelper.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
#nullable disable
6+
57
// Purpose: Helper functions that require elevation but are safe to use.
68

79
using System;

src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/SecurityCriticalDataForSet.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
#nullable disable
6+
57
// Description:
68
// This is a helper class to facilate the storage of data that's Critical for set.
79
// The data itself is not information disclosure but the value controls a critical
@@ -10,7 +12,7 @@
1012
// For example a filepath variable might control what part of the file system the
1113
// code gets access to.
1214

13-
using System ;
15+
using System ;
1416
using System.Security ;
1517

1618
#if WINDOWS_BASE
@@ -43,11 +45,11 @@ namespace MS.Internal
4345
internal struct SecurityCriticalDataForSet<T>
4446
{
4547
internal SecurityCriticalDataForSet(T value)
46-
{
47-
_value = value;
48+
{
49+
_value = value;
4850
}
4951

50-
internal T Value
52+
internal T Value
5153
{
5254
#if DEBUG
5355
[System.Diagnostics.DebuggerStepThrough]

src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/Xaml/Context/XamlContextStack.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
#nullable disable
6+
57
using System;
68
using System.Collections.Generic;
79
using System.Text;
@@ -111,7 +113,7 @@ public void PushScope()
111113
Debug.Assert(CurrentFrame.Depth == Depth);
112114
}
113115

114-
//Consumers of this stack call PopScope, and we'll move the currentFrame from the main
116+
//Consumers of this stack call PopScope, and we'll move the currentFrame from the main
115117
// linked list to the recylced linked list and call .Reset
116118
public void PopScope()
117119
{

src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/Xaml/Context/XamlFrame.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
#nullable disable
6+
57
using System;
68
using System.Collections.Generic;
79
using System.Text;
@@ -28,8 +30,8 @@ protected XamlFrame(XamlFrame source)
2830
public virtual XamlFrame Clone()
2931
{
3032
// Clone should only be overridden for the classes that really need it
31-
// ObjectWriterFrame overrides this so we can reuse the context for
32-
// Templates.
33+
// ObjectWriterFrame overrides this so we can reuse the context for
34+
// Templates.
3335
throw new NotImplementedException();
3436
}
3537

src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/Xaml/Parser/SpecialBracketCharacters.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
#nullable disable
6+
57
// Description: Data model for the Bracket characters specified on a Markup Extension property.
68

79
using System;
@@ -13,7 +15,7 @@
1315
namespace MS.Internal.Xaml.Parser
1416
{
1517
/// <summary>
16-
/// Class that provides helper functions for the parser/Xaml Reader
18+
/// Class that provides helper functions for the parser/Xaml Reader
1719
/// to process Bracket Characters specified on a Markup Extension Property
1820
/// </summary>
1921
internal class SpecialBracketCharacters : ISupportInitialize
@@ -24,7 +26,7 @@ internal class SpecialBracketCharacters : ISupportInitialize
2426
private bool _initializing;
2527
private StringBuilder _startCharactersStringBuilder;
2628
private StringBuilder _endCharactersStringBuilder;
27-
29+
2830
internal SpecialBracketCharacters()
2931
{
3032
BeginInit();
@@ -59,7 +61,7 @@ private void Tokenize(IReadOnlyDictionary<char,char> attributeList)
5961
foreach (char openingBracket in attributeList.Keys)
6062
{
6163
char closingBracket = attributeList[openingBracket];
62-
string errorMessage = string.Empty;
64+
string errorMessage = string.Empty;
6365
if (IsValidBracketCharacter(openingBracket, closingBracket))
6466
{
6567
_startCharactersStringBuilder.Append(openingBracket);

src/Microsoft.DotNet.Wpf/src/Shared/MS/Utility/FrugalList.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
#nullable disable
6+
57
using System;
68
using System.Diagnostics;
79
using System.Collections;

src/Microsoft.DotNet.Wpf/src/Shared/System/Windows/Markup/ReflectionHelper.cs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
#nullable disable
6+
57
//
68
//
79
//
@@ -50,16 +52,16 @@ internal static class ReflectionHelper
5052
// System.Reflection.MetadataLoadContext instance
5153
private static MetadataLoadContext _metadataLoadContext = null;
5254

53-
// MetadataLoadContext Assembly cache
54-
private static Dictionary<string, Assembly> _cachedMetadataLoadContextAssemblies = null;
55-
private static Dictionary<string, Assembly> _cachedMetadataLoadContextAssembliesByNameNoExtension = null;
55+
// MetadataLoadContext Assembly cache
56+
private static Dictionary<string, Assembly> _cachedMetadataLoadContextAssemblies = null;
57+
private static Dictionary<string, Assembly> _cachedMetadataLoadContextAssembliesByNameNoExtension = null;
5658

5759
// The local assembly that contains the baml.
5860
private static string _localAssemblyName = string.Empty;
5961

6062
internal static void Initialize(IEnumerable<string> assemblyPaths)
61-
{
62-
// System.Reflection.MetadataLoadContext Assembly cache
63+
{
64+
// System.Reflection.MetadataLoadContext Assembly cache
6365
_cachedMetadataLoadContextAssemblies = new Dictionary<string, Assembly>(StringComparer.OrdinalIgnoreCase);
6466
_cachedMetadataLoadContextAssembliesByNameNoExtension = new Dictionary<string, Assembly>(StringComparer.OrdinalIgnoreCase);
6567
_metadataLoadContext = new MetadataLoadContext(new PathAssemblyResolver(assemblyPaths), MscorlibReflectionAssemblyName);
@@ -168,7 +170,7 @@ internal static Type GetFrameworkType(string assemblyName, Type type)
168170
{
169171
#if PBTCOMPILER
170172
Assembly reflectionAssembly = LoadAssembly(assemblyName, null);
171-
173+
172174
if (reflectionAssembly != null)
173175
{
174176
type = reflectionAssembly.GetType(type.FullName);
@@ -209,7 +211,7 @@ internal static Type GetReflectionType(object item)
209211
return ictp.GetCustomType();
210212
}
211213
#endif
212-
214+
213215
#endregion Type
214216

215217
#region Attributes
@@ -534,13 +536,13 @@ internal static Assembly GetAlreadyReflectionOnlyLoadedAssembly(string assemblyN
534536
// For a given assembly name and its full path, Reflection-Only load the assembly directly
535537
// from the file in disk or load the file to memory and then create assembly instance from
536538
// memory buffer data.
537-
//
539+
//
538540
private static Assembly ReflectionOnlyLoadAssembly(string assemblyName, string fullPathToAssembly)
539541
{
540-
Assembly assembly = null;
542+
Assembly assembly = null;
541543

542-
// If the assembly path is empty, try to load assembly by name. LoadFromAssemblyName
543-
// will result in a MetadataLoadContext.Resolve event that will contain more information about the
544+
// If the assembly path is empty, try to load assembly by name. LoadFromAssemblyName
545+
// will result in a MetadataLoadContext.Resolve event that will contain more information about the
544546
// requested assembly.
545547
if (String.IsNullOrEmpty(fullPathToAssembly))
546548
{

src/Microsoft.DotNet.Wpf/src/Shared/System/Windows/Markup/Replacements/TypeUriConverter.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
#nullable disable
6+
57
using System.ComponentModel;
68
using System.ComponentModel.Design.Serialization;
79
using System.Globalization;
@@ -23,7 +25,7 @@ public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceT
2325

2426
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
2527
{
26-
return
28+
return
2729
destinationType == typeof(InstanceDescriptor) ||
2830
destinationType == typeof(string) ||
2931
destinationType == typeof(Uri);

src/Microsoft.DotNet.Wpf/src/Shared/System/Windows/Markup/RuntimeIdentifierPropertyAttribute.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
#nullable disable
6+
57
// Description:
68
// This attribute is placed on a class to identify the property that will
79
// function as an Name for the given class

src/Microsoft.DotNet.Wpf/src/Shared/System/Windows/Markup/TypeConverterHelper.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
#nullable disable
6+
57
// Description: Specifies that the whitespace surrounding an element should be trimmed.
68

79
using System;

src/Microsoft.DotNet.Wpf/src/Shared/System/Windows/Markup/XmlCompatibilityReader.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
#nullable disable
6+
57
using System;
68
using System.Xml;
79
using System.Collections;
@@ -170,7 +172,7 @@ public override bool Read()
170172

171173
bool more = Reader.Read(); //passed as ref arg to ReadStartElement and ReadEndElement
172174
bool result = false;
173-
175+
174176
while (more)
175177
{
176178
switch (Reader.NodeType)
@@ -279,7 +281,7 @@ private bool ReadStartElement(ref bool more)
279281
}
280282
}
281283

282-
// if the element is empty (e.g. "<a ... />" and we pushed a scope then we need to set a flag
284+
// if the element is empty (e.g. "<a ... />" and we pushed a scope then we need to set a flag
283285
// to get rid of the scope when we hit the next element.
284286
// We also need to store the current elementDepth.
285287
if (isEmpty)

src/Microsoft.DotNet.Wpf/src/Shared/System/Windows/Markup/XmlWrappingReader.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
#nullable disable
6+
57
using System;
68
using System.Xml;
79
using System.Xml.Schema;
@@ -13,7 +15,7 @@ namespace MS.Internal.Markup
1315
#elif SYSTEM_XAML
1416
namespace System.Xaml
1517
#else
16-
namespace System.Windows.Markup
18+
namespace System.Windows.Markup
1719
#endif
1820
{
1921
internal class XmlWrappingReader : XmlReader, IXmlLineInfo, IXmlNamespaceResolver {
@@ -23,8 +25,8 @@ internal class XmlWrappingReader : XmlReader, IXmlLineInfo, IXmlNamespaceResolve
2325
protected XmlReader _reader;
2426
protected IXmlLineInfo _readerAsIXmlLineInfo;
2527
protected IXmlNamespaceResolver _readerAsResolver;
26-
27-
//
28+
29+
//
2830
// Constructor
2931
//
3032
internal XmlWrappingReader( XmlReader baseReader ) {
@@ -105,7 +107,7 @@ public override bool Read() {
105107
public override void Close() {
106108
_reader.Close();
107109
}
108-
110+
109111
public override void Skip() {
110112
_reader.Skip();
111113
}
@@ -160,7 +162,7 @@ public virtual int LineNumber {
160162
}
161163
}
162164

163-
public virtual int LinePosition {
165+
public virtual int LinePosition {
164166
get {
165167
return ( _readerAsIXmlLineInfo == null ) ? 0 : _readerAsIXmlLineInfo.LinePosition;
166168
}
@@ -181,5 +183,5 @@ protected XmlReader Reader {
181183
}
182184
}
183185
}
184-
186+
185187

src/Microsoft.DotNet.Wpf/src/System.Xaml/GlobalSuppressions.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
// This file is used by Code Analysis to maintain SuppressMessage
5+
#nullable disable
6+
7+
#nullable disable// This file is used by Code Analysis to maintain SuppressMessage
68
// attributes that are applied to this project.
7-
// Project-level suppressions either have no target or are given
9+
// Project-level suppressions either have no target or are given
810
// a specific target and scoped to a namespace, type, member, etc.
911

1012
using System.Diagnostics.CodeAnalysis;

src/Microsoft.DotNet.Wpf/src/System.Xaml/OtherAssemblyAttrs.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
#nullable disable
6+
57
//
68
// This file specifies various assembly level attributes.
79
//

src/Microsoft.DotNet.Wpf/src/System.Xaml/System.Xaml.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
<PropertyGroup>
33
<ProjectGuid>{9AC36357-34B7-40A1-95CA-FE9F46D089A7}</ProjectGuid>
44
<AssemblyName>System.Xaml</AssemblyName>
5-
5+
66
<Platforms>AnyCPU;x64;arm64</Platforms>
77
<NoWarn>$(NoWarn);0618;NU5125;0618</NoWarn>
88
<DefineConstants>$(DefineConstants);OLDRESOURCES;SYSTEM_XAML</DefineConstants>
99
<EnableAnalyzers>true</EnableAnalyzers>
10+
<Nullable>enable</Nullable>
1011
</PropertyGroup>
1112

1213
<ItemGroup>

src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/AcceptedMarkupExtensionExpressionTypeAttribute.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
#nullable disable
6+
57
namespace System.Windows.Markup
68
{
79
[Obsolete("This is not used by the XAML parser. Please look at XamlSetMarkupExtensionAttribute.")]

src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/AmbientAttribute.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
#nullable disable
6+
57
using System.Runtime.CompilerServices;
68

79
namespace System.Windows.Markup

0 commit comments

Comments
 (0)