Skip to content

Commit c6d4da3

Browse files
committed
Updated to use is / is not for null comparisons
1 parent 7a6f4de commit c6d4da3

File tree

64 files changed

+128
-154
lines changed

Some content is hidden

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

64 files changed

+128
-154
lines changed

src/Mages.Core.Tests/ExtensibilityTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ public void FunctionTakingComplexObjectShouldBeUnwrappedIfSpecified()
561561
{
562562
var engine = new Engine();
563563
engine.SetStatic(typeof(WrapUnwrapTest)).WithName("Test");
564-
var func = new Func<WrapUnwrapTest, Boolean>((obj) => obj != null);
564+
var func = new Func<WrapUnwrapTest, Boolean>((obj) => obj is not null);
565565
engine.SetFunction("verify", func.Method, func.Target);
566566

567567
var result = engine.Interpret("x = Test.create(); verify(x)");

src/Mages.Core.Tests/InvalidInputTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ private static ParameterDefinition Po(String v)
279279

280280
private static ParameterDefinition P(String v, Boolean r)
281281
{
282-
if (v != null)
282+
if (v is not null)
283283
{
284284
return new ParameterDefinition(v, r);
285285
}

src/Mages.Core.Tests/Mages.Core.Tests.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<AppDesignerFolder>Properties</AppDesignerFolder>
77
<RootNamespace>Mages.Core.Tests</RootNamespace>
88
<AssemblyName>Mages.Core.Tests</AssemblyName>
9+
<LangVersion>latest</LangVersion>
910
<ApplicationIcon />
1011
<StartupObject />
1112
<Platforms>x64</Platforms>

src/Mages.Core.Tests/ObservableTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void ClearObservableDictionaryEmitsEvents()
6565
var keys = new List<String>();
6666
obs.Changed += (s, ev) =>
6767
{
68-
if (ev.NewValue == null && ev.OldValue != null)
68+
if (ev.NewValue is null && ev.OldValue is not null)
6969
{
7070
keys.Add(ev.Key);
7171
}

src/Mages.Core/Ast/ExpressionParser.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ private IExpression ParsePower(IEnumerator<IToken> tokens)
639639
var x = ParseUnary(tokens);
640640
expressions.Push(x);
641641
}
642-
while (tokens.Current.Type == TokenType.Power && tokens.NextNonIgnorable() != null);
642+
while (tokens.Current.Type == TokenType.Power && tokens.NextNonIgnorable() is not null);
643643

644644
do
645645
{
@@ -1247,7 +1247,7 @@ private static ConstantExpression ParseNumber(IEnumerator<IToken> tokens)
12471247
private static ParameterExpression GetParameters(IExpression x)
12481248
{
12491249
var args = x as ArgumentsExpression;
1250-
return args != null ?
1250+
return args is not null ?
12511251
new ParameterExpression(args.Arguments, args.Start, args.End) :
12521252
new ParameterExpression([x], x.Start, x.End);
12531253
}

src/Mages.Core/Ast/Expressions/AssignmentExpression.cs

+2-4
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@ public sealed class AssignmentExpression(IExpression variable, IExpression value
3030
public String VariableName
3131
{
3232
get
33-
{
34-
var variable = Variable as VariableExpression;
35-
36-
if (variable != null)
33+
{
34+
if (Variable is VariableExpression variable)
3735
{
3836
return variable.Name;
3937
}

src/Mages.Core/Ast/Expressions/DeleteExpression.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void Validate(IValidationContext context)
4646
var member = _payload as MemberExpression;
4747
var isIdentifier = _payload is VariableExpression;
4848

49-
if (member != null)
49+
if (member is not null)
5050
{
5151
expression = member.Member;
5252
isIdentifier = expression is IdentifierExpression;

src/Mages.Core/Ast/Expressions/ParameterExpression.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ public ParameterDefinition[] Names
3434
{
3535
var identifier = _parameters[i] as VariableExpression;
3636
var assignment = _parameters[i] as AssignmentExpression;
37-
var required = assignment == null;
37+
var required = assignment is null;
3838

3939
if (!required)
4040
{
4141
identifier = assignment.Variable as VariableExpression;
4242
}
4343

44-
if (identifier != null)
44+
if (identifier is not null)
4545
{
4646
names[i] = new ParameterDefinition(identifier.Name, required);
4747
}
@@ -86,7 +86,7 @@ public void Validate(IValidationContext context)
8686
{
8787
var assignment = (AssignmentExpression)parameter;
8888

89-
if (assignment.VariableName == null)
89+
if (assignment.VariableName is null)
9090
{
9191
var error = new ParseError(ErrorCode.OptionalArgumentRequired, parameter);
9292
context.Report(error);

src/Mages.Core/Ast/StatementExtensions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public static IOperation[] MakeRunnable(this IEnumerable<IStatement> statements)
8181
public static Boolean IsEmpty(this IStatement statement)
8282
{
8383
var simple = statement as SimpleStatement;
84-
return simple != null && simple.Expression.IsEmpty();
84+
return simple is not null && simple.Expression.IsEmpty();
8585
}
8686

8787
/// <summary>

src/Mages.Core/Ast/Statements/VarStatement.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ public void Validate(IValidationContext context)
3838
{
3939
var assignment = _assignment as AssignmentExpression;
4040

41-
if (assignment == null)
41+
if (assignment is null)
4242
{
4343
//TODO Report invalid construction
4444
}
45-
else if (assignment.VariableName == null)
45+
else if (assignment.VariableName is null)
4646
{
4747
//TODO Report invalid construction
4848
}

src/Mages.Core/Ast/Walkers/CompletionTreeWalker.cs

+10-10
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,13 @@ public override void Visit(VarStatement statement)
8888
{
8989
var assignment = statement.Assignment as AssignmentExpression;
9090

91-
if (assignment != null)
91+
if (assignment is not null)
9292
{
9393
var c = _variables.Count - 1;
9494
var variables = _variables[c];
9595
var variable = assignment.VariableName;
9696

97-
if (variable != null && !variables.Contains(variable))
97+
if (variable is not null && !variables.Contains(variable))
9898
{
9999
variables.Add(variable);
100100
}
@@ -148,7 +148,7 @@ public override void Visit(AssignmentExpression expression)
148148
{
149149
var name = expression.VariableName;
150150

151-
if (name != null)
151+
if (name is not null)
152152
{
153153
var c = _variables.Count - 1;
154154

@@ -186,7 +186,7 @@ public override void Visit(ParameterExpression expression)
186186
{
187187
var variable = parameter as VariableExpression;
188188

189-
if (variable != null)
189+
if (variable is not null)
190190
{
191191
var variables = _variables[_variables.Count - 1];
192192

@@ -243,13 +243,13 @@ public override void Visit(MemberExpression expression)
243243
var prefix = String.Empty;
244244
var obj = Resolve(expression.Object);
245245

246-
if (member != null)
246+
if (member is not null)
247247
{
248248
var length = _position.Index - member.Start.Index;
249249
prefix = member.Name.Substring(0, length);
250250
}
251251

252-
if (obj != null)
252+
if (obj is not null)
253253
{
254254
AddSuggestions(prefix, obj.Select(m => m.Key));
255255
}
@@ -273,11 +273,11 @@ private IDictionary<String, Object> Resolve(IExpression expression)
273273
var host = _symbols;
274274
var name = default(String);
275275

276-
if (member != null)
276+
if (member is not null)
277277
{
278278
var child = member.Member as IdentifierExpression;
279279

280-
if (child != null)
280+
if (child is not null)
281281
{
282282
host = Resolve(member.Object);
283283
name = child.Name;
@@ -287,13 +287,13 @@ private IDictionary<String, Object> Resolve(IExpression expression)
287287
{
288288
var variable = expression as VariableExpression;
289289

290-
if (variable != null)
290+
if (variable is not null)
291291
{
292292
name = variable.Name;
293293
}
294294
}
295295

296-
if (!String.IsNullOrEmpty(name) && host != null)
296+
if (!String.IsNullOrEmpty(name) && host is not null)
297297
{
298298
host.TryGetValue(name, out value);
299299
return value as IDictionary<String, Object>;

src/Mages.Core/Ast/Walkers/SymbolTreeWalker.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,12 @@ public override void Visit(VariableExpression expression)
120120
{
121121
var list = Find(expression.Name, expression.Scope);
122122

123-
if (list == null && _assigning)
123+
if (list is null && _assigning)
124124
{
125125
list = [expression];
126126
_collector[expression] = list;
127127
}
128-
else if (list != null)
128+
else if (list is not null)
129129
{
130130
list.Add(expression);
131131
}

src/Mages.Core/Ast/Walkers/ValidationTreeWalker.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public sealed class ValidationTreeWalker(List<ParseError> errors) : ITreeWalker,
2424

2525
#region Properties
2626

27-
Boolean IValidationContext.IsInLoop => _loops.Count != 0 && _loops.Peek() != null;
27+
Boolean IValidationContext.IsInLoop => _loops.Count != 0 && _loops.Peek() is not null;
2828

2929
#endregion
3030

src/Mages.Core/EngineExtensions.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public static IPlacement SetStatic(this Engine engine, Assembly lib, Predicate<T
101101

102102
foreach (var type in types)
103103
{
104-
if (shouldInclude == null || shouldInclude.Invoke(type))
104+
if (shouldInclude is null || shouldInclude.Invoke(type))
105105
{
106106
var name = obj.Keys.FindName(type);
107107
var value = type.Expose();
@@ -203,7 +203,7 @@ public static Plugin AddPlugin(this Engine engine, Type type)
203203

204204
var constructor = type.GetConstructor([typeof(Engine)]);
205205

206-
if (constructor != null)
206+
if (constructor is not null)
207207
{
208208
var obj = constructor.Invoke(new[] { engine });
209209
var plugin = ConstructInstancePlugin(obj);
@@ -230,7 +230,7 @@ public static IEnumerable<Plugin> AddPlugins(this Engine engine, Assembly assemb
230230
{
231231
var plugin = engine.AddPlugin(type);
232232

233-
if (plugin != null)
233+
if (plugin is not null)
234234
{
235235
plugins.Add(plugin);
236236
}

src/Mages.Core/Function.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static Object Call(this Function function, params Object[] arguments)
3030
{
3131
var argument = arguments[i];
3232

33-
if (argument != null)
33+
if (argument is not null)
3434
{
3535
var from = argument.GetType();
3636
var type = from.FindPrimitive();
@@ -92,7 +92,7 @@ public static String[] GetParameterNames(this Function function)
9292
var local = function.Target as LocalFunction;
9393
var parameters = local?.Parameters;
9494

95-
if (parameters == null)
95+
if (parameters is null)
9696
{
9797
var nativeParams = function.Method.GetParameters();
9898
var parameterNames = new String[nativeParams.Length];

src/Mages.Core/Runtime/Container.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static class Container
2222
/// <returns>The optional lifetime controlling instance.</returns>
2323
public static IDisposable Register<T>(T service)
2424
{
25-
if (service != null && !_container.Contains(service))
25+
if (service is not null && !_container.Contains(service))
2626
{
2727
_container.Add(service);
2828
return new ServiceLifeTime(service);

src/Mages.Core/Runtime/Converters/CamelNameSelector.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public String Select(IEnumerable<String> registered, MemberInfo member)
4343

4444
private static String ConvertToCamelCase(String str)
4545
{
46-
if (str != null)
46+
if (str is not null)
4747
{
4848
if (str.Length > 1)
4949
{

src/Mages.Core/Runtime/Converters/ConverterExtensions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public static IDictionary<String, Object> ToObject(this Object value)
157157
{
158158
var result = new Dictionary<String, Object>();
159159

160-
if (value != null)
160+
if (value is not null)
161161
{
162162
result["0"] = value;
163163
}

src/Mages.Core/Runtime/Converters/TypeConverterMap.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public Func<Object, Object> FindConverter(Type to)
1515

1616
return obj =>
1717
{
18-
if (obj != null)
18+
if (obj is not null)
1919
{
2020
var converter = default(Func<Object, Object>);
2121
var type = obj.GetType();
@@ -63,7 +63,7 @@ public Func<Object, Object> FindConverter(Type from, Type to)
6363
var p = inv.GetParameters();
6464
var t = TargetWrapper.Construct(inv.ReturnType, p);
6565

66-
if (t != null)
66+
if (t is not null)
6767
{
6868
return obj =>
6969
{

src/Mages.Core/Runtime/Functions/Curry.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ public static Function Shuffle(Object[] args)
8282
var end = args.Length - 1;
8383
var target = args[end] as Function;
8484

85-
if (target != null)
85+
if (target is not null)
8686
{
8787
var wrapper = target.Target as LocalFunction;
8888
var parameters = wrapper?.Parameters;
8989

90-
if (parameters != null)
90+
if (parameters is not null)
9191
{
9292
var indices = new Int32[parameters.Length];
9393
var result = default(Function);
@@ -152,7 +152,7 @@ private static Int32 ShuffleParameters(Object[] args, ParameterDefinition[] para
152152
{
153153
var s = arg as String;
154154

155-
if (s != null)
155+
if (s is not null)
156156
{
157157
for (var j = 0; j < parameters.Length; j++)
158158
{

src/Mages.Core/Runtime/Functions/SimpleRandom.cs

+1-4
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,6 @@ private static Int32 ToInteger(Double argument)
5656

5757
private static void EnsureRandom()
5858
{
59-
if (_random == null)
60-
{
61-
_random = new Random();
62-
}
59+
_random ??= new Random();
6360
}
6461
}

src/Mages.Core/Runtime/Helpers.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public static Boolean Satisfies(this IDictionary<String, Object> constraints, Ob
120120
{
121121
var obj = value as IDictionary<String, Object>;
122122

123-
if (obj != null && obj.Count >= constraints.Count)
123+
if (obj is not null && obj.Count >= constraints.Count)
124124
{
125125
foreach (var constraint in constraints)
126126
{
@@ -129,8 +129,8 @@ public static Boolean Satisfies(this IDictionary<String, Object> constraints, Ob
129129
var simple = constraint.Value as String;
130130
var extended = constraint.Value as IDictionary<String, Object>;
131131

132-
if ((simple == null || val.ToType()["name"].ToString() == simple) &&
133-
(extended == null || extended.Satisfies(val)))
132+
if ((simple is null || val.ToType()["name"].ToString() == simple) &&
133+
(extended is null || extended.Satisfies(val)))
134134
{
135135
continue;
136136
}
@@ -367,7 +367,7 @@ public static Function WrapFunction(this MethodInfo method, Object target)
367367
{
368368
var result = Curry.Min(parameters.Length, f, args);
369369

370-
if (result == null && method.TryMatch(parameters, ref args))
370+
if (result is null && method.TryMatch(parameters, ref args))
371371
{
372372
result = method.Call(target, args);
373373
}
@@ -390,7 +390,7 @@ public static Object WrapObject(this Object value)
390390
return new Future(task);
391391
}
392392

393-
if (value != null)
393+
if (value is not null)
394394
{
395395
var type = value.GetType();
396396
var target = type.FindPrimitive();

src/Mages.Core/Runtime/JsonSerializer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ private void SerializeTo(IDictionary<String, Object> obj, StringBuilder buffer,
4747

4848
private void SerializeTo(Object value, StringBuilder buffer, Int32 level)
4949
{
50-
if (value == null)
50+
if (value is null)
5151
{
5252
buffer.Append("null");
5353
}

0 commit comments

Comments
 (0)