Skip to content

Commit d021d8e

Browse files
committed
Performed a migration to the modern C# null/not-null checks
1 parent 3f2bcbf commit d021d8e

File tree

79 files changed

+358
-315
lines changed

Some content is hidden

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

79 files changed

+358
-315
lines changed

build/common.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
<Copyright>Copyright © 2013-2026 Andrey Taritsyn</Copyright>
44
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
55
<GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute>
6+
<LangVersion>14.0</LangVersion>
67
</PropertyGroup>
78
</Project>

samples/JavaScriptEngineSwitcher.Sample.AspNet4.Mvc4/Web.config

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@
2727
</system.webServer>
2828
<runtime>
2929
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
30+
<dependentAssembly>
31+
<assemblyIdentity name="AdvancedStringBuilder" culture="neutral" publicKeyToken="e818a2fc08933ddb" />
32+
<bindingRedirect oldVersion="0.0.0.0-0.2.0.0" newVersion="0.2.0.0" />
33+
</dependentAssembly>
34+
<dependentAssembly>
35+
<assemblyIdentity name="PolyfillsForOldDotNet.System.Buffers" culture="neutral" publicKeyToken="7c096c79220f0d91" />
36+
<bindingRedirect oldVersion="0.0.0.0-0.1.3.0" newVersion="0.1.3.0" />
37+
</dependentAssembly>
38+
<dependentAssembly>
39+
<assemblyIdentity name="PolyfillsForOldDotNet.System.Threading" culture="neutral" publicKeyToken="7c096c79220f0d91" />
40+
<bindingRedirect oldVersion="0.0.0.0-0.1.3.0" newVersion="0.1.3.0" />
41+
</dependentAssembly>
3042
<dependentAssembly>
3143
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
3244
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />

samples/JavaScriptEngineSwitcher.Sample.Logic/Services/JsEvaluationService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public JsEvaluationViewModel Evaluate(JsEvaluationViewModel model)
8585
}
8686
finally
8787
{
88-
if (engine != null)
88+
if (engine is not null)
8989
{
9090
engine.Dispose();
9191
}

src/JavaScriptEngineSwitcher.ChakraCore/ChakraCoreJsEngine.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ private WrapperException WrapJsException(OriginalException originalException,
316316
string sourceFragment = string.Empty;
317317

318318
var originalScriptException = originalException as OriginalScriptException;
319-
if (originalScriptException != null)
319+
if (originalScriptException is not null)
320320
{
321321
JsValue metadataValue = originalScriptException.Metadata;
322322

@@ -782,7 +782,7 @@ protected override void InnerExecute(string code, string documentName)
782782
protected override void InnerExecute(IPrecompiledScript precompiledScript)
783783
{
784784
var chakraCorePrecompiledScript = precompiledScript as ChakraCorePrecompiledScript;
785-
if (chakraCorePrecompiledScript == null)
785+
if (chakraCorePrecompiledScript is null)
786786
{
787787
throw new WrapperUsageException(
788788
string.Format(CoreStrings.Usage_CannotConvertPrecompiledScriptToInternalType,
@@ -1099,15 +1099,15 @@ private void Dispose(bool disposing)
10991099
{
11001100
if (_disposedFlag.Set())
11011101
{
1102-
if (_dispatcher != null)
1102+
if (_dispatcher is not null)
11031103
{
11041104
_dispatcher.Invoke(DisposeUnmanagedResources);
11051105

11061106
_dispatcher.Dispose();
11071107
_dispatcher = null;
11081108
}
11091109

1110-
if (_typeMapper != null)
1110+
if (_typeMapper is not null)
11111111
{
11121112
_typeMapper.Dispose();
11131113
_typeMapper = null;

src/JavaScriptEngineSwitcher.ChakraCore/ChakraCorePrecompiledScript.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,11 @@ public ChakraCorePrecompiledScript(string code, JsParseScriptAttributes parseAtt
117117
private bool LoadScriptSourceCode(JsSourceContext sourceContext, out JsValue value,
118118
out JsParseScriptAttributes parseAttributes)
119119
{
120-
if (_codeBytes == null)
120+
if (_codeBytes is null)
121121
{
122122
lock (_scriptLoadingSynchronizer)
123123
{
124-
if (_codeBytes == null)
124+
if (_codeBytes is null)
125125
{
126126
Encoding encoding = _parseAttributes.HasFlag(JsParseScriptAttributes.ArrayBufferIsUtf16Encoded) ?
127127
Encoding.Unicode : Encoding.UTF8;

src/JavaScriptEngineSwitcher.ChakraCore/Helpers/ReflectionHelpers.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public static bool IsFullyFledgedMethod(MethodInfo method)
7777

7878
public static void FixFieldValueType(ref object value, FieldInfo field)
7979
{
80-
if (value == null)
80+
if (value is null)
8181
{
8282
return;
8383
}
@@ -98,7 +98,7 @@ public static void FixFieldValueType(ref object value, FieldInfo field)
9898

9999
public static void FixPropertyValueType(ref object value, PropertyInfo property)
100100
{
101-
if (value == null)
101+
if (value is null)
102102
{
103103
return;
104104
}
@@ -135,7 +135,7 @@ public static void FixArgumentTypes(ref object[] argValues, ParameterInfo[] para
135135
}
136136

137137
object argValue = argValues[argIndex];
138-
if (argValue == null)
138+
if (argValue is null)
139139
{
140140
continue;
141141
}
@@ -223,7 +223,7 @@ public static MethodBase GetBestFitMethod(MethodBase[] methods, object[] argValu
223223
methodArrayPool.Return(buffer, clearArray);
224224
}
225225

226-
if (compatibleMethods != null)
226+
if (compatibleMethods is not null)
227227
{
228228
MethodWithMetadata bestFitMethod = compatibleMethods
229229
.OrderByDescending(m => m.CompatibilityScore)
@@ -256,7 +256,7 @@ private static bool CompareParameterTypes(object[] argValues, ParameterInfo[] pa
256256
for (int argIndex = 0; argIndex < argCount; argIndex++)
257257
{
258258
object argValue = argValues[argIndex];
259-
Type argType = argValue != null ? argValue.GetType() : typeof(object);
259+
Type argType = argValue is not null ? argValue.GetType() : typeof(object);
260260
ParameterInfo parameter = parameters[argIndex];
261261
Type parameterType = parameter.ParameterType;
262262

@@ -295,11 +295,11 @@ private MemberComparer()
295295

296296
public override bool Equals(T x, T y)
297297
{
298-
if (x == null && y == null)
298+
if (x is null && y is null)
299299
{
300300
return true;
301301
}
302-
else if (x == null || y == null)
302+
else if (x is null || y is null)
303303
{
304304
return false;
305305
}
@@ -316,7 +316,7 @@ public override bool Equals(T x, T y)
316316

317317
public override int GetHashCode(T obj)
318318
{
319-
return obj != null ? obj.GetHashCode() : 0;
319+
return obj is not null ? obj.GetHashCode() : 0;
320320
}
321321

322322
#endregion

src/JavaScriptEngineSwitcher.ChakraCore/JavaScriptEngineSwitcher.ChakraCore.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<PackageIconFullPath>../../Icons/JavaScriptEngineSwitcher_ChakraCore_Logo128x128.png</PackageIconFullPath>
2525
<Description>JavaScriptEngineSwitcher.ChakraCore contains a `ChakraCoreJsEngine` adapter (wrapper for the ChakraCore).</Description>
2626
<PackageTags>$(PackageCommonTags);ChakraCore</PackageTags>
27-
<PackageReleaseNotes>Optimized a memory usage in the `ReflectionHelpers.GetBestFitMethod` method.</PackageReleaseNotes>
27+
<PackageReleaseNotes>Performed a migration to the modern C# null/not-null checks.</PackageReleaseNotes>
2828
</PropertyGroup>
2929

3030
<ItemGroup>

src/JavaScriptEngineSwitcher.ChakraCore/JsEngineFactoryCollectionExtensions.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static class JsEngineFactoryCollectionExtensions
1717
/// <returns>Instance of <see cref="JsEngineFactoryCollection"/></returns>
1818
public static JsEngineFactoryCollection AddChakraCore(this JsEngineFactoryCollection source)
1919
{
20-
if (source == null)
20+
if (source is null)
2121
{
2222
throw new ArgumentNullException(nameof(source));
2323
}
@@ -35,12 +35,12 @@ public static JsEngineFactoryCollection AddChakraCore(this JsEngineFactoryCollec
3535
public static JsEngineFactoryCollection AddChakraCore(this JsEngineFactoryCollection source,
3636
Action<ChakraCoreSettings> configure)
3737
{
38-
if (source == null)
38+
if (source is null)
3939
{
4040
throw new ArgumentNullException(nameof(source));
4141
}
4242

43-
if (configure == null)
43+
if (configure is null)
4444
{
4545
throw new ArgumentNullException(nameof(configure));
4646
}
@@ -60,12 +60,12 @@ public static JsEngineFactoryCollection AddChakraCore(this JsEngineFactoryCollec
6060
/// <returns>Instance of <see cref="JsEngineFactoryCollection"/></returns>
6161
public static JsEngineFactoryCollection AddChakraCore(this JsEngineFactoryCollection source, ChakraCoreSettings settings)
6262
{
63-
if (source == null)
63+
if (source is null)
6464
{
6565
throw new ArgumentNullException(nameof(source));
6666
}
6767

68-
if (settings == null)
68+
if (settings is null)
6969
{
7070
throw new ArgumentNullException(nameof(settings));
7171
}

src/JavaScriptEngineSwitcher.ChakraCore/JsRt/Embedding/EmbeddedItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public void Dispose()
106106
_hostObject = null;
107107

108108
IList<JsNativeFunction> nativeFunctions = _nativeFunctions;
109-
if (nativeFunctions != null)
109+
if (nativeFunctions is not null)
110110
{
111111
nativeFunctions.Clear();
112112
_nativeFunctions = null;

src/JavaScriptEngineSwitcher.ChakraCore/JsRt/Embedding/EmbeddedObjectKey.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public bool Equals(EmbeddedObjectKey other)
5353

5454
bool IStructuralEquatable.Equals(object other, IEqualityComparer comparer)
5555
{
56-
if (other == null || !(other is EmbeddedObjectKey))
56+
if (other is null || !(other is EmbeddedObjectKey))
5757
{
5858
return false;
5959
}
@@ -75,7 +75,7 @@ int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
7575

7676
int IComparable.CompareTo(object other)
7777
{
78-
if (other == null)
78+
if (other is null)
7979
{
8080
return 1;
8181
}
@@ -112,7 +112,7 @@ public int CompareTo(EmbeddedObjectKey other)
112112

113113
int IStructuralComparable.CompareTo(object other, IComparer comparer)
114114
{
115-
if (other == null)
115+
if (other is null)
116116
{
117117
return 1;
118118
}

0 commit comments

Comments
 (0)