Skip to content

Commit bf49bcd

Browse files
committed
Performed a migration to the modern C# null/not-null checks
1 parent a64c499 commit bf49bcd

39 files changed

+185
-182
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 © 2012-2024 Andrey Taritsyn</Copyright>
44
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
55
<GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute>
6+
<LangVersion>14.0</LangVersion>
67
</PropertyGroup>
78
</Project>

src/MsieJavaScriptEngine/ActiveScript/ActiveScriptException.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public ActiveScriptException(string message, Exception innerException)
163163
private ActiveScriptException(SerializationInfo info, StreamingContext context)
164164
: base(info, context)
165165
{
166-
if (info != null)
166+
if (info is not null)
167167
{
168168
_errorCode = info.GetInt32("ErrorCode");
169169
_type = info.GetString("Type");
@@ -187,7 +187,7 @@ private ActiveScriptException(SerializationInfo info, StreamingContext context)
187187
[SecurityPermission(SecurityAction.Demand, SerializationFormatter = true)]
188188
public override void GetObjectData(SerializationInfo info, StreamingContext context)
189189
{
190-
if (info == null)
190+
if (info is null)
191191
{
192192
throw new ArgumentNullException("info");
193193
}

src/MsieJavaScriptEngine/ActiveScript/ActiveScriptJsEngineBase.ScriptSiteBase.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public void GetLcid(out int lcid)
200200
public void GetItemInfo(string name, ScriptInfoFlags mask, ref IntPtr pUnkItem, ref IntPtr pTypeInfo)
201201
{
202202
object item = _jsEngine._hostItems[name];
203-
if (item == null)
203+
if (item is null)
204204
{
205205
throw new COMException(
206206
string.Format(NetFrameworkStrings.Runtime_ItemNotFound, name),
@@ -254,7 +254,7 @@ public void OnScriptErrorDebug(IActiveScriptErrorDebug errorDebug, out bool ente
254254
out bool callOnScriptErrorWhenContinuing)
255255
{
256256
var error = errorDebug as IActiveScriptError;
257-
if (error != null)
257+
if (error is not null)
258258
{
259259
ProcessActiveScriptError(error);
260260
}
@@ -329,7 +329,7 @@ public CustomQueryInterfaceResult GetInterface(ref Guid iid, out IntPtr pInterfa
329329
|| iid == typeof(IActiveScriptSiteDebug64).GUID
330330
|| iid == typeof(IActiveScriptSiteDebugEx).GUID)
331331
{
332-
return _jsEngine._processDebugManagerWrapper != null ?
332+
return _jsEngine._processDebugManagerWrapper is not null ?
333333
CustomQueryInterfaceResult.NotHandled : CustomQueryInterfaceResult.Failed;
334334
}
335335

src/MsieJavaScriptEngine/ActiveScript/ActiveScriptJsEngineBase.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ protected ActiveScriptJsEngineBase(JsEngineSettings settings, string clsid,
172172
}
173173
finally
174174
{
175-
if (_dispatch == null)
175+
if (_dispatch is null)
176176
{
177177
Dispose();
178178
}
@@ -187,14 +187,14 @@ protected ActiveScriptJsEngineBase(JsEngineSettings settings, string clsid,
187187
/// or <c>0</c> to use the default maximum stack size specified in the header for the executable.</param>
188188
private static void InitScriptDispatcher(int maxStackSize)
189189
{
190-
if (_dispatcher != null)
190+
if (_dispatcher is not null)
191191
{
192192
return;
193193
}
194194

195195
lock (_dispatcherSynchronizer)
196196
{
197-
if (_dispatcher != null)
197+
if (_dispatcher is not null)
198198
{
199199
return;
200200
}
@@ -328,7 +328,7 @@ private ActiveScriptException GetAndResetLastException()
328328
private void ThrowError()
329329
{
330330
ActiveScriptException last = GetAndResetLastException();
331-
if (last != null)
331+
if (last is not null)
332332
{
333333
throw last;
334334
}
@@ -539,7 +539,7 @@ private void InnerEmbedHostItem(string itemName, object value)
539539
}
540540
catch
541541
{
542-
if (oldValue != null)
542+
if (oldValue is not null)
543543
{
544544
_hostItems[itemName] = oldValue;
545545
}
@@ -607,12 +607,12 @@ private object[] MapToHostType(object[] args)
607607
private static IExpando WrapScriptDispatch(object dispatch)
608608
{
609609
IExpando wrappedDispatch = null;
610-
if (dispatch != null && dispatch.GetType().IsCOMObject)
610+
if (dispatch is not null && dispatch.GetType().IsCOMObject)
611611
{
612612
wrappedDispatch = dispatch as IExpando;
613613
}
614614

615-
if (wrappedDispatch == null)
615+
if (wrappedDispatch is null)
616616
{
617617
throw new InvalidOperationException(
618618
NetFrameworkStrings.Engine_ActiveScriptDispatcherNotInitialized);
@@ -652,7 +652,7 @@ private JsException WrapActiveScriptException(ActiveScriptException originalExce
652652
wrapperException.Description = originalException.Description;
653653

654654
var wrapperScriptException = wrapperException as JsScriptException;
655-
if (wrapperScriptException != null)
655+
if (wrapperScriptException is not null)
656656
{
657657
wrapperScriptException.Type = originalException.Type;
658658
wrapperScriptException.DocumentName = originalException.DocumentName;
@@ -798,7 +798,7 @@ public override bool HasVariable(string variableName)
798798
try
799799
{
800800
object variableValue = InnerGetVariableValue(variableName);
801-
variableExist = variableValue != null;
801+
variableExist = variableValue is not null;
802802
}
803803
catch (ActiveScriptException e)
804804
{
@@ -933,7 +933,7 @@ public override void Dispose()
933933
{
934934
if (_disposedFlag.Set())
935935
{
936-
if (_debuggingStarted && _debugDocuments != null)
936+
if (_debuggingStarted && _debugDocuments is not null)
937937
{
938938
foreach (UIntPtr debugDocumentKey in _debugDocuments.Keys)
939939
{
@@ -945,11 +945,11 @@ public override void Dispose()
945945
_debugDocuments = null;
946946
}
947947

948-
if (_processDebugManagerWrapper != null)
948+
if (_processDebugManagerWrapper is not null)
949949
{
950950
_processDebugManagerWrapper.RemoveApplication(_debugApplicationCookie);
951951

952-
if (_debugApplicationWrapper != null)
952+
if (_debugApplicationWrapper is not null)
953953
{
954954
_debugApplicationWrapper.Close();
955955
_debugApplicationWrapper = null;
@@ -958,28 +958,28 @@ public override void Dispose()
958958
_processDebugManagerWrapper = null;
959959
}
960960

961-
if (_documentNames != null)
961+
if (_documentNames is not null)
962962
{
963963
_documentNames.Clear();
964964
_documentNames = null;
965965
}
966966

967967
_dispatcher.Invoke(() =>
968968
{
969-
if (_dispatch != null)
969+
if (_dispatch is not null)
970970
{
971971
Marshal.ReleaseComObject(_dispatch);
972972
_dispatch = null;
973973
}
974974

975-
if (_activeScriptWrapper != null)
975+
if (_activeScriptWrapper is not null)
976976
{
977977
_activeScriptWrapper.Dispose();
978978
_activeScriptWrapper = null;
979979
}
980980
});
981981

982-
if (_hostItems != null)
982+
if (_hostItems is not null)
983983
{
984984
_hostItems.Clear();
985985
_hostItems = null;

src/MsieJavaScriptEngine/ActiveScript/ActiveScriptJsErrorHelpers.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ public static string GetErrorTypeByNumber(int errorNumber, Dictionary<int, strin
7171
/// <returns>Short name of error item</returns>
7272
public static string ShortenErrorItemName(string itemName, string prefix)
7373
{
74-
if (itemName == null)
74+
if (itemName is null)
7575
{
7676
throw new ArgumentNullException(nameof(itemName));
7777
}
7878

79-
if (prefix == null)
79+
if (prefix is null)
8080
{
8181
throw new ArgumentNullException(nameof(prefix));
8282
}

src/MsieJavaScriptEngine/ActiveScript/ActiveScriptWrapper32.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public override object ParseScriptText(string code, string itemName, object cont
116116

117117
public override void EnumStackFrames(out IEnumDebugStackFrames enumFrames)
118118
{
119-
if (_debugStackFrameSniffer32 != null)
119+
if (_debugStackFrameSniffer32 is not null)
120120
{
121121
_debugStackFrameSniffer32.EnumStackFrames(out enumFrames);
122122
}

src/MsieJavaScriptEngine/ActiveScript/ActiveScriptWrapper64.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public override object ParseScriptText(string code, string itemName, object cont
116116

117117
public override void EnumStackFrames(out IEnumDebugStackFrames enumFrames)
118118
{
119-
if (_debugStackFrameSniffer64 != null)
119+
if (_debugStackFrameSniffer64 is not null)
120120
{
121121
_debugStackFrameSniffer64.EnumStackFrames(out enumFrames);
122122
}

src/MsieJavaScriptEngine/ActiveScript/ActiveScriptWrapperBase.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ protected ActiveScriptWrapperBase(string clsid, ScriptLanguageVersion languageVe
6969
if (languageVersion != ScriptLanguageVersion.None)
7070
{
7171
var activeScriptProperty = _activeScript as IActiveScriptProperty;
72-
if (activeScriptProperty != null)
72+
if (activeScriptProperty is not null)
7373
{
7474
object scriptLanguageVersion = (int)languageVersion;
7575
uint result = activeScriptProperty.SetProperty((uint)ScriptProperty.InvokeVersioning,
@@ -222,7 +222,7 @@ public void InterruptScriptThread(uint scriptThreadId, ref EXCEPINFO exceptionIn
222222
/// <param name="type">The type of garbage collection</param>
223223
public void CollectGarbage(ScriptGCType type)
224224
{
225-
if (_activeScriptGarbageCollector != null)
225+
if (_activeScriptGarbageCollector is not null)
226226
{
227227
_activeScriptGarbageCollector.CollectGarbage(type);
228228
}
@@ -247,7 +247,7 @@ protected virtual void Dispose(bool disposing)
247247
{
248248
_activeScriptGarbageCollector = null;
249249

250-
if (_activeScript != null)
250+
if (_activeScript is not null)
251251
{
252252
_activeScript.Close();
253253
Marshal.FinalReleaseComObject(_activeScript);

src/MsieJavaScriptEngine/ActiveScript/ClassicActiveScriptJsEngine.ScriptSite.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ protected override CallStackItem[] GetCallStackItems()
9595
uint lineNumber = 0;
9696
uint columnNumber = 0;
9797

98-
if (documentContext != null)
98+
if (documentContext is not null)
9999
{
100100
IDebugDocument document;
101101
documentContext.GetDocument(out document);

src/MsieJavaScriptEngine/ActiveScript/Debugging/DebugDocument.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,14 @@ private void Initialize()
120120
/// </summary>
121121
public void Close()
122122
{
123-
if (_node != null)
123+
if (_node is not null)
124124
{
125125
_node.Detach();
126126
_node.Close();
127127
_node = null;
128128
}
129129

130-
if (_lines != null)
130+
if (_lines is not null)
131131
{
132132
_lines.Clear();
133133
}

0 commit comments

Comments
 (0)