Skip to content
This repository was archived by the owner on Dec 10, 2020. It is now read-only.

Commit acc2d5e

Browse files
authored
Build with C# 9 / SDK 3.1.400 (#48)
* Use C# 9 patterns `is`/`is not` for `null` comparisons * Bump up SDK to 3.1.400 (C# 9), 3.1.401 for AppVeyor * Include GitHub `ci.yml` in solution
1 parent 991d187 commit acc2d5e

20 files changed

+129
-131
lines changed

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ environment:
1212
DOTNET_NOLOGO: 1
1313
DOTNET_CLI_TELEMETRY_OPTOUT: 1
1414
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
15-
DOTNET_SDK_URL: 'https://dotnetcli.azureedge.net/dotnet/Sdk/3.1.301/dotnet-sdk-3.1.301-win-x64.zip'
15+
DOTNET_SDK_URL: 'https://dotnetcli.azureedge.net/dotnet/Sdk/3.1.401/dotnet-sdk-3.1.401-win-x64.zip'
1616

1717
cache:
1818
- '%LocalAppData%\NuGet\v3-cache' # NuGet v3

dotnet-xdt.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Misc", "Misc", "{403FCE60-1
1111
.gitignore = .gitignore
1212
appveyor.yml = appveyor.yml
1313
build.ps1 = build.ps1
14+
.github\workflows\ci.yml = .github\workflows\ci.yml
1415
global.json = global.json
1516
LICENSE.txt = LICENSE.txt
1617
README.md = README.md

dotnet-xdt/NamedTypeFactory.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ internal void AddPathRegistration(string path, string nameSpace)
4343

4444
Type? type = GetType(typeName);
4545

46-
if (type == null)
46+
if (type is null)
4747
throw new XmlTransformationException(string.Format(System.Globalization.CultureInfo.CurrentCulture, SR.XMLTRANSFORMATION_UnknownTypeName, typeName, typeof(TObjectType).Name));
4848

4949
if (!type.IsSubclassOf(typeof(TObjectType)))
5050
throw new XmlTransformationException(string.Format(System.Globalization.CultureInfo.CurrentCulture, SR.XMLTRANSFORMATION_IncorrectBaseType, type.FullName, typeof(TObjectType).Name));
5151

5252
ConstructorInfo constructor = type.GetConstructor(Type.EmptyTypes);
53-
if (constructor == null)
53+
if (constructor is null)
5454
throw new XmlTransformationException(string.Format(System.Globalization.CultureInfo.CurrentCulture, SR.XMLTRANSFORMATION_NoValidConstructor, type.FullName));
5555

5656
return constructor.Invoke(Array.Empty<object>()) as TObjectType;
@@ -63,8 +63,8 @@ internal void AddPathRegistration(string path, string nameSpace)
6363
{
6464
if (!registration.IsValid) continue;
6565
Type regType = registration.Assembly.GetType(string.Concat(registration.NameSpace, ".", typeName));
66-
if (regType == null) continue;
67-
if (foundType == null)
66+
if (regType is null) continue;
67+
if (foundType is null)
6868
foundType = regType;
6969
else
7070
throw new XmlTransformationException(string.Format(System.Globalization.CultureInfo.CurrentCulture, SR.XMLTRANSFORMATION_AmbiguousTypeMatch, typeName));
@@ -80,7 +80,7 @@ public Registration(Assembly assembly, string nameSpace)
8080
NameSpace = nameSpace;
8181
}
8282

83-
public bool IsValid => Assembly != null;
83+
public bool IsValid => Assembly is not null;
8484
public string NameSpace { get; }
8585
public Assembly Assembly { get; }
8686
}

dotnet-xdt/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ static bool ParseArguments(IReadOnlyList<string> args, ref string? sourceFilePat
154154
bool TryRead(ref int index, ref string? value)
155155
{
156156
++index;
157-
if (index >= args.Count || value != null) return false;
157+
if (index >= args.Count || value is not null) return false;
158158
value = args[index];
159159
return true;
160160
}

dotnet-xdt/XmlArgumentUtility.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static IList<string> RecombineArguments(IList<string> arguments, char separator)
3232

3333
foreach (string argument in arguments)
3434
{
35-
combinedArgument = combinedArgument == null
35+
combinedArgument = combinedArgument is null
3636
? argument
3737
: string.Concat(combinedArgument, separator, argument);
3838

@@ -44,7 +44,7 @@ static IList<string> RecombineArguments(IList<string> arguments, char separator)
4444
}
4545

4646
// mismatched parens, we'll let the caller handle it
47-
if (combinedArgument != null)
47+
if (combinedArgument is not null)
4848
combinedArguments.Add(combinedArgument);
4949

5050
// If the count didn't change, then nothing was recombined

dotnet-xdt/XmlAttributePreservationDict.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,15 @@ static int EnumerateAttributes(string elementStartTag, Action<int, int, string>
6767
internal void WritePreservedAttributes(XmlAttributePreservingWriter writer, XmlAttributeCollection attributes)
6868
{
6969
string? oldNewLineString = null;
70-
if (_attributeNewLineString != null)
70+
if (_attributeNewLineString is not null)
7171
oldNewLineString = writer.SetAttributeNewLineString(_attributeNewLineString);
7272

7373
try
7474
{
7575
foreach (string attributeName in _orderedAttributes)
7676
{
7777
XmlAttribute attr = attributes[attributeName];
78-
if (attr == null) continue;
78+
if (attr is null) continue;
7979
if (_leadingSpaces.ContainsKey(attributeName))
8080
writer.WriteAttributeWhitespace(_leadingSpaces[attributeName]);
8181

@@ -87,7 +87,7 @@ internal void WritePreservedAttributes(XmlAttributePreservingWriter writer, XmlA
8787
}
8888
finally
8989
{
90-
if (oldNewLineString != null)
90+
if (oldNewLineString is not null)
9191
writer.SetAttributeNewLineString(oldNewLineString);
9292
}
9393
}
@@ -145,8 +145,7 @@ internal void UpdatePreservationInfo(XmlAttributeCollection updatedAttributes, X
145145
string leadingSpace = _leadingSpaces[key];
146146
if (firstAttribute)
147147
{
148-
if (keepLeadingWhitespace == null)
149-
keepLeadingWhitespace = leadingSpace;
148+
keepLeadingWhitespace ??= leadingSpace;
150149
}
151150
else if (ContainsNewLine(leadingSpace))
152151
keepLeadingWhitespace = leadingSpace;
@@ -155,7 +154,7 @@ internal void UpdatePreservationInfo(XmlAttributeCollection updatedAttributes, X
155154
}
156155
}
157156

158-
else if (keepLeadingWhitespace != null)
157+
else if (keepLeadingWhitespace is not null)
159158
{
160159
// Exception to rule #2 above: Don't replace an existing
161160
// newline with one that was removed

dotnet-xdt/XmlAttributePreservingWriter.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ class XmlAttributePreservingWriter : XmlWriter
1313
readonly AttributeTextWriter _textWriter;
1414

1515
public XmlAttributePreservingWriter(string fileName, Encoding? encoding)
16-
: this(encoding == null ? new StreamWriter(fileName) : new StreamWriter(fileName, false, encoding))
16+
: this(encoding is null ? new StreamWriter(fileName) : new StreamWriter(fileName, false, encoding))
1717
{ }
1818

1919
public XmlAttributePreservingWriter(Stream w, Encoding? encoding)
20-
: this(encoding == null ? new StreamWriter(w) : new StreamWriter(w, encoding))
20+
: this(encoding is null ? new StreamWriter(w) : new StreamWriter(w, encoding))
2121
{ }
2222

2323
public XmlAttributePreservingWriter(TextWriter textWriter)
@@ -58,10 +58,9 @@ public string SetAttributeNewLineString(string newLineString)
5858
{
5959
string old = _textWriter.AttributeNewLineString;
6060

61-
if (newLineString == null && _xmlWriter.Settings != null)
61+
if (newLineString is null && _xmlWriter.Settings is not null)
6262
newLineString = _xmlWriter.Settings.NewLineChars;
63-
if (newLineString == null)
64-
newLineString = "\r\n";
63+
newLineString ??= "\r\n";
6564
_textWriter.AttributeNewLineString = newLineString;
6665

6766
return old;
@@ -193,15 +192,15 @@ static bool StateRequiresBuffer(State state)
193192

194193
void CreateBuffer()
195194
{
196-
Debug.Assert(_writeBuffer == null);
197-
if (_writeBuffer == null)
195+
Debug.Assert(_writeBuffer is null);
196+
if (_writeBuffer is null)
198197
_writeBuffer = new StringBuilder();
199198
}
200199

201200
void FlushBuffer()
202201
{
203-
Debug.Assert(_writeBuffer != null);
204-
if (_writeBuffer == null) return;
202+
Debug.Assert(_writeBuffer is not null);
203+
if (_writeBuffer is null) return;
205204
State oldState = _state;
206205
try
207206
{
@@ -232,7 +231,7 @@ void ReallyWriteCharacter(char value)
232231
void WriteQueuedAttribute()
233232
{
234233
// Write leading whitespace
235-
if (AttributeLeadingWhitespace != null)
234+
if (AttributeLeadingWhitespace is not null)
236235
{
237236
_writeBuffer?.Insert(0, AttributeLeadingWhitespace);
238237
AttributeLeadingWhitespace = null;

dotnet-xdt/XmlAttributeTransform.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ protected XmlNodeList TransformAttributes
1919
{
2020
get
2121
{
22-
if (_transformAttributes == null || _transformAttributeSource != TransformNode)
22+
if (_transformAttributes is null || _transformAttributeSource != TransformNode)
2323
{
2424
_transformAttributeSource = TransformNode;
2525
_transformAttributes = GetAttributesFrom(TransformNode);
@@ -32,7 +32,7 @@ protected XmlNodeList TargetAttributes
3232
{
3333
get
3434
{
35-
if (_targetAttributes == null || _targetAttributeSource != TargetNode)
35+
if (_targetAttributes is null || _targetAttributeSource != TargetNode)
3636
{
3737
_targetAttributeSource = TargetNode;
3838
_targetAttributes = GetAttributesFrom(TargetNode);
@@ -43,7 +43,7 @@ protected XmlNodeList TargetAttributes
4343

4444
XmlNodeList GetAttributesFrom(XmlNode node)
4545
{
46-
if (Arguments == null || Arguments.Count == 0)
46+
if (Arguments is null || Arguments.Count == 0)
4747
return GetAttributesFrom(node, "*", false);
4848

4949
if (Arguments.Count == 1)

dotnet-xdt/XmlElementContext.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public XmlElementContext(XmlElementContext? parent, XmlElement element, XmlDocum
3434

3535
public T? GetService<T>() where T : class
3636
{
37-
if (_serviceProvider != null)
37+
if (_serviceProvider is not null)
3838
{
3939
// note it is legal to return service that's null -- due to SetTokenizeAttributeStorage
4040
return _serviceProvider.GetService(typeof(T)) as T;
@@ -74,7 +74,7 @@ string ConstructXPath()
7474
{
7575
try
7676
{
77-
string parentPath = _parentContext == null ? string.Empty : _parentContext.XPath;
77+
string parentPath = _parentContext is null ? string.Empty : _parentContext.XPath;
7878

7979
Locator locator = CreateLocator(out string? argumentString);
8080

@@ -90,7 +90,7 @@ string ConstructParentXPath()
9090
{
9191
try
9292
{
93-
string parentPath = _parentContext == null ? string.Empty : _parentContext.XPath;
93+
string parentPath = _parentContext is null ? string.Empty : _parentContext.XPath;
9494

9595
Locator locator = CreateLocator(out string? argumentString);
9696

@@ -105,7 +105,7 @@ string ConstructParentXPath()
105105
Locator CreateLocator(out string? argumentString)
106106
{
107107
var locator = CreateObjectFromAttribute<Locator>(out argumentString, out _locatorAttribute);
108-
if (locator == null)
108+
if (locator is null)
109109
{
110110
argumentString = null;
111111
//avoid using singleton of "DefaultLocator.Instance", so unit tests can run parallel
@@ -122,7 +122,7 @@ internal XmlNodeList TargetParents
122122
{
123123
get
124124
{
125-
if (_targetParents == null && _parentContext != null)
125+
if (_targetParents is null && _parentContext is not null)
126126
_targetParents = GetTargetNodes(ParentXPath);
127127
return _targetParents!;
128128
}
@@ -135,7 +135,7 @@ XmlNode CreateCloneInTargetDocument(XmlNode? sourceNode)
135135
var infoDocument = TargetDocument as XmlFileInfoDocument;
136136
XmlNode clonedNode;
137137

138-
if (infoDocument != null)
138+
if (infoDocument is not null)
139139
clonedNode = infoDocument.CloneNodeFromOtherDocument(sourceNode);
140140
else
141141
{
@@ -150,7 +150,7 @@ XmlNode CreateCloneInTargetDocument(XmlNode? sourceNode)
150150

151151
static void ScrubTransformAttributesAndNamespaces(XmlNode node)
152152
{
153-
if (node.Attributes != null)
153+
if (node.Attributes is not null)
154154
{
155155
var attributesToRemove = new List<XmlAttribute>();
156156

@@ -181,7 +181,7 @@ static void ScrubTransformAttributesAndNamespaces(XmlNode node)
181181

182182
XmlNamespaceManager GetNamespaceManager()
183183
{
184-
if (_namespaceManager == null)
184+
if (_namespaceManager is null)
185185
{
186186
XmlNodeList localNamespaces = Element!.SelectNodes("namespace::*");
187187

@@ -206,7 +206,7 @@ XmlNamespaceManager GetNamespaceManager()
206206
}
207207

208208
XmlNameTable? GetParentNameTable()
209-
=> _parentContext == null ? Element?.OwnerDocument?.NameTable : _parentContext.GetNamespaceManager().NameTable;
209+
=> _parentContext is null ? Element?.OwnerDocument?.NameTable : _parentContext.GetNamespaceManager().NameTable;
210210

211211
static Regex? _nameAndArgumentsRegex;
212212
static Regex NameAndArgumentsRegex => _nameAndArgumentsRegex ??= new Regex(@"\A\s*(?<name>\w+)(\s*\((?<arguments>.*)\))?\s*\Z", RegexOptions.Compiled | RegexOptions.Singleline);
@@ -236,7 +236,7 @@ static string ParseNameAndArguments(string name, out string? arguments)
236236
objectAttribute = Element?.Attributes.GetNamedItem(typeof(TObjectType).Name, XmlTransformation.TransformNamespace) as XmlAttribute;
237237
try
238238
{
239-
if (objectAttribute != null)
239+
if (objectAttribute is not null)
240240
{
241241
string typeName = ParseNameAndArguments(objectAttribute.Value, out argumentString);
242242
if (!string.IsNullOrEmpty(typeName))
@@ -260,7 +260,7 @@ internal bool HasTargetNode(out XmlElementContext? failedContext, out bool exist
260260
if (TargetNodes.Count == 0)
261261
{
262262
failedContext = this;
263-
while (failedContext._parentContext != null && failedContext._parentContext.TargetNodes.Count == 0)
263+
while (failedContext._parentContext is not null && failedContext._parentContext.TargetNodes.Count == 0)
264264
failedContext = failedContext._parentContext;
265265

266266
existedInOriginal = ExistedInOriginal(failedContext.XPath);
@@ -292,7 +292,7 @@ bool ExistedInOriginal(string xpath)
292292
{
293293
var service = GetService<IXmlOriginalDocumentService>();
294294
XmlNodeList? nodeList = service?.SelectNodes(xpath, GetNamespaceManager());
295-
return nodeList != null && nodeList.Count > 0;
295+
return nodeList is not null && nodeList.Count > 0;
296296
}
297297
}
298298
}

0 commit comments

Comments
 (0)