Skip to content

Commit 790d82d

Browse files
committed
Enable nullable
Fixes #124
1 parent fdf4f2c commit 790d82d

28 files changed

Lines changed: 137 additions & 137 deletions

Directory.Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
2020
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
2121
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
22+
<Nullable>enable</Nullable>
2223
</PropertyGroup>
2324

2425
<PropertyGroup>

ValveKeyValue/ValveKeyValue.Console/ValveKeyValue.Console.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<TargetFramework>net10.0</TargetFramework>
55
<RollForward>LatestMajor</RollForward>
66
<ImplicitUsings>enable</ImplicitUsings>
7-
<Nullable>enable</Nullable>
87
<PublishAot>true</PublishAot>
98
</PropertyGroup>
109
<ItemGroup>

ValveKeyValue/ValveKeyValue.Test/ValveKeyValue.Test.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<Description>Unit Tests for library to parse and write Valve KeyValue formats</Description>
88
<SignAssembly>true</SignAssembly>
99
<AssemblyOriginatorKeyFile>../ValveKeyValue/ValveKeyValue.snk</AssemblyOriginatorKeyFile>
10+
<Nullable>disable</Nullable>
1011
</PropertyGroup>
1112
<ItemGroup>
1213
<None Remove="Test Data\**\*.txt" />

ValveKeyValue/ValveKeyValue/Abstraction/IVisitationListener.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ namespace ValveKeyValue.Abstraction
22
{
33
interface IVisitationListener : IDisposable
44
{
5-
void OnObjectStart(string name, KVFlag flag);
5+
void OnObjectStart(string? name, KVFlag flag);
66

77
void OnObjectEnd();
88

99
void OnKeyValuePair(string name, KVObject value);
1010

11-
void OnArrayStart(string name, KVFlag flag, int elementCount, bool allSimpleElements);
11+
void OnArrayStart(string? name, KVFlag flag, int elementCount, bool allSimpleElements);
1212

1313
void OnArrayValue(KVObject value);
1414

ValveKeyValue/ValveKeyValue/Abstraction/KVObjectVisitor.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ public KVObjectVisitor(IVisitationListener listener)
1111

1212
readonly IVisitationListener listener;
1313

14-
public void Visit(string name, KVObject @object)
14+
public void Visit(string? name, KVObject @object)
1515
{
1616
VisitObject(name, @object, false);
1717
}
1818

19-
void VisitObject(string name, KVObject obj, bool isArray)
19+
void VisitObject(string? name, KVObject obj, bool isArray)
2020
{
2121
switch (obj.ValueType)
2222
{
@@ -66,7 +66,7 @@ void VisitObject(string name, KVObject obj, bool isArray)
6666
listener.OnArrayValue(obj);
6767
break;
6868
}
69-
listener.OnKeyValuePair(name, obj);
69+
listener.OnKeyValuePair(name!, obj);
7070
break;
7171

7272
default:

ValveKeyValue/ValveKeyValue/DefaultObjectReflector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ IEnumerable<IObjectMember> IObjectReflector.GetMembers([DynamicallyAccessedMembe
3636
}
3737

3838
static bool IsValueTupleType(Type type)
39-
=> type.IsGenericType && type.FullName.StartsWith("System.ValueTuple`", StringComparison.Ordinal);
39+
=> type.IsGenericType && type.FullName!.StartsWith("System.ValueTuple`", StringComparison.Ordinal);
4040
}
4141
}

ValveKeyValue/ValveKeyValue/Deserialization/KVObjectBuilder.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void OnArrayValue(KVObject value)
5454
if (StateStack.Count > 0)
5555
{
5656
var state = StateStack.Peek();
57-
state.Items.Add(new KeyValuePair<string, KVObject>(null, value));
57+
state.Items.Add(new KeyValuePair<string, KVObject>(null!, value));
5858
}
5959
else
6060
{
@@ -76,7 +76,7 @@ public void OnObjectEnd()
7676

7777
var state = StateStack.Pop();
7878
var completedObject = MakeObject(state);
79-
StateStack.Peek().Items.Add(new KeyValuePair<string, KVObject>(state.Key, completedObject));
79+
StateStack.Peek().Items.Add(new KeyValuePair<string, KVObject>(state.Key!, completedObject!));
8080
}
8181

8282
public void OnArrayEnd()
@@ -88,7 +88,7 @@ public void OnArrayEnd()
8888

8989
var state = StateStack.Pop();
9090
var completedObject = MakeArray(state);
91-
StateStack.Peek().Items.Add(new KeyValuePair<string, KVObject>(state.Key, completedObject));
91+
StateStack.Peek().Items.Add(new KeyValuePair<string, KVObject>(state.Key!, completedObject!));
9292
}
9393

9494
public void DiscardCurrentObject()
@@ -104,7 +104,7 @@ public void DiscardCurrentObject()
104104
}
105105
}
106106

107-
public void OnObjectStart(string name, KVFlag flag)
107+
public void OnObjectStart(string? name, KVFlag flag)
108108
{
109109
var state = new KVPartialState
110110
{
@@ -114,7 +114,7 @@ public void OnObjectStart(string name, KVFlag flag)
114114
StateStack.Push(state);
115115
}
116116

117-
public void OnArrayStart(string name, KVFlag flag, int elementCount, bool allSimpleElements)
117+
public void OnArrayStart(string? name, KVFlag flag, int elementCount, bool allSimpleElements)
118118
{
119119
var state = new KVPartialState
120120
{
@@ -153,12 +153,12 @@ protected virtual void FinalizeState()
153153
}
154154
}
155155

156-
static KeyValuePair<string, KVObject> MakeResult(KVPartialState state, KVObject obj)
156+
static KeyValuePair<string, KVObject> MakeResult(KVPartialState state, KVObject? obj)
157157
{
158-
return new KeyValuePair<string, KVObject>(state.Key, obj);
158+
return new KeyValuePair<string, KVObject>(state.Key!, obj!);
159159
}
160160

161-
KVObject MakeObject(KVPartialState state)
161+
KVObject? MakeObject(KVPartialState state)
162162
{
163163
if (state.Discard)
164164
{
@@ -187,7 +187,7 @@ KVObject MakeObject(KVPartialState state)
187187
return result;
188188
}
189189

190-
static KVObject MakeArray(KVPartialState state)
190+
static KVObject? MakeArray(KVPartialState state)
191191
{
192192
if (state.Discard)
193193
{

ValveKeyValue/ValveKeyValue/Deserialization/KVPartialState.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ namespace ValveKeyValue.Deserialization
22
{
33
class KVPartialState
44
{
5-
public string Key { get; set; }
5+
public string? Key { get; set; }
66

77
public KVFlag Flag { get; set; }
88

9-
public KVObject Value { get; set; }
9+
public KVObject? Value { get; set; }
1010

1111
public List<KeyValuePair<string, KVObject>> Items { get; } = new List<KeyValuePair<string, KVObject>>();
1212

ValveKeyValue/ValveKeyValue/Deserialization/KVTokenReader.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ public void Dispose()
2828
if (!disposed)
2929
{
3030
textReader.Dispose();
31-
textReader = null;
32-
3331
disposed = true;
3432
}
3533
}

ValveKeyValue/ValveKeyValue/Deserialization/KeyValues1/KV1TextReader.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public KVHeader ReadHeader()
5353
switch (token.TokenType)
5454
{
5555
case KVTokenType.String:
56-
ReadText(token.Value);
56+
ReadText(token.Value!);
5757
break;
5858

5959
case KVTokenType.ObjectStart:
@@ -65,7 +65,7 @@ public KVHeader ReadHeader()
6565
break;
6666

6767
case KVTokenType.Condition:
68-
HandleCondition(token.Value);
68+
HandleCondition(token.Value!);
6969
break;
7070

7171
case KVTokenType.EndOfFile:
@@ -89,7 +89,7 @@ public KVHeader ReadHeader()
8989
throw new KeyValueException($"Inclusions are only valid at the beginning of a file, but found one at {tokenReader.PreviousTokenPosition}.");
9090
}
9191

92-
stateMachine.AddItemForMerging(token.Value);
92+
stateMachine.AddItemForMerging(token.Value!);
9393
break;
9494

9595
case KVTokenType.IncludeAndAppend:
@@ -98,7 +98,7 @@ public KVHeader ReadHeader()
9898
throw new KeyValueException($"Inclusions are only valid at the beginning of a file, but found one at {tokenReader.PreviousTokenPosition}.");
9999
}
100100

101-
stateMachine.AddItemForAppending(token.Value);
101+
stateMachine.AddItemForAppending(token.Value!);
102102
break;
103103

104104
default:
@@ -135,7 +135,7 @@ void ReadText(string text)
135135

136136
case KV1TextReaderState.InObjectBetweenKeyAndValue:
137137
var value = ParseValue(text);
138-
var name = stateMachine.CurrentName;
138+
var name = stateMachine.CurrentName!;
139139
listener.OnKeyValuePair(name, value);
140140

141141
stateMachine.Push(KV1TextReaderState.InObjectAfterValue);

0 commit comments

Comments
 (0)