Skip to content

Commit

Permalink
Merge pull request #56 from Exouxas/38-fix-null-related-warnings
Browse files Browse the repository at this point in the history
Fix null related warnings
  • Loading branch information
Exouxas authored Oct 20, 2023
2 parents bb87899 + 4ea426d commit 8cc6708
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/Core/Agents/Module.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public Module()
protected Module(SerializationInfo info, StreamingContext context) : this()
{
Body = (Actor?)info.GetValue(nameof(Body), typeof(Actor));
Dependencies = (Dictionary<string, int[]>)info.GetValue(nameof(Dependencies), typeof(Dictionary<string, int[]>));
DependencyReferences = (Dictionary<string, Module>)info.GetValue(nameof(DependencyReferences), typeof(Dictionary<string, Module>));
Dependencies = (Dictionary<string, int[]>)(info.GetValue(nameof(Dependencies), typeof(Dictionary<string, int[]>)) ?? throw new SerializationException());
DependencyReferences = (Dictionary<string, Module>)(info.GetValue(nameof(DependencyReferences), typeof(Dictionary<string, Module>)) ?? throw new SerializationException());
}

public override void GetObjectData(SerializationInfo info, StreamingContext context)
Expand Down
6 changes: 3 additions & 3 deletions src/Core/NeuralNetwork/Brain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public Brain()
/// <param name="context">The current deserialization context.</param>
protected Brain(SerializationInfo info, StreamingContext context)
{
SupplementingNodes = (List<ICanSupplement>)info.GetValue(nameof(SupplementingNodes), typeof(List<ICanSupplement>));
AugmentingNodes = (List<ICanAugment>)info.GetValue(nameof(AugmentingNodes), typeof(List<ICanAugment>));
NeuralConnections = (List<NeuralConnection>)info.GetValue(nameof(NeuralConnections), typeof(List<NeuralConnection>));
SupplementingNodes = (List<ICanSupplement>)(info.GetValue(nameof(SupplementingNodes), typeof(List<ICanSupplement>)) ?? throw new SerializationException());
AugmentingNodes = (List<ICanAugment>)(info.GetValue(nameof(AugmentingNodes), typeof(List<ICanAugment>)) ?? throw new SerializationException());
NeuralConnections = (List<NeuralConnection>)(info.GetValue(nameof(NeuralConnections), typeof(List<NeuralConnection>)) ?? throw new SerializationException());
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Core/NeuralNetwork/HiddenNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ protected HiddenNode(string name, string description) : base(name, description)

protected HiddenNode(SerializationInfo info, StreamingContext context) : base(info, context)
{
Inputs = (List<NeuralConnection>)info.GetValue(nameof(Inputs), typeof(List<NeuralConnection>));
Inputs = (List<NeuralConnection>)(info.GetValue(nameof(Inputs), typeof(List<NeuralConnection>)) ?? throw new SerializationException());
}

public override void GetObjectData(SerializationInfo info, StreamingContext context)
Expand Down
4 changes: 2 additions & 2 deletions src/Core/NeuralNetwork/InputNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public double Output

protected InputNode(SerializationInfo info, StreamingContext context) : base(info, context)
{
output = (double)info.GetValue(nameof(Output), typeof(double));
storedOutput = (double)info.GetValue(nameof(storedOutput), typeof(double));
output = (double)(info.GetValue(nameof(Output), typeof(double)) ?? throw new SerializationException());
storedOutput = (double)(info.GetValue(nameof(storedOutput), typeof(double)) ?? throw new SerializationException());
}

public override void GetObjectData(SerializationInfo info, StreamingContext context)
Expand Down
6 changes: 3 additions & 3 deletions src/Core/NeuralNetwork/NeuralConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ public NeuralConnection(ICanSupplement from, ICanAugment to, double weight)

public NeuralConnection(SerializationInfo info, StreamingContext context)
{
From = (ICanSupplement)info.GetValue(nameof(From), typeof(ICanSupplement));
To = (ICanAugment)info.GetValue(nameof(To), typeof(ICanAugment));
weight = (double)info.GetValue(nameof(Weight), typeof(double));
From = (ICanSupplement)(info.GetValue(nameof(From), typeof(ICanSupplement)) ?? throw new SerializationException());
To = (ICanAugment)(info.GetValue(nameof(To), typeof(ICanAugment)) ?? throw new SerializationException());
weight = (double)(info.GetValue(nameof(Weight), typeof(double)) ?? throw new SerializationException());
}

public void GetObjectData(SerializationInfo info, StreamingContext context)
Expand Down
4 changes: 2 additions & 2 deletions src/Core/NeuralNetwork/Neuron.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ protected Neuron(string name, string description)

protected Neuron(SerializationInfo info, StreamingContext context)
{
_name = (string)info.GetValue(nameof(Name), typeof(string));
_description = (string)info.GetValue(nameof(Description), typeof(string));
_name = (string)(info.GetValue(nameof(Name), typeof(string)) ?? throw new SerializationException());
_description = (string)(info.GetValue(nameof(Description), typeof(string)) ?? throw new SerializationException());
}

public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
Expand Down
2 changes: 1 addition & 1 deletion src/Core/NeuralNetwork/OutputNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public OutputNode(string name, string description) : base(name, description)

protected OutputNode(SerializationInfo info, StreamingContext context) : base(info, context)
{
Inputs = (List<NeuralConnection>)info.GetValue(nameof(Inputs), typeof(List<NeuralConnection>));
Inputs = (List<NeuralConnection>)(info.GetValue(nameof(Inputs), typeof(List<NeuralConnection>)) ?? throw new SerializationException());
}

public override void GetObjectData(SerializationInfo info, StreamingContext context)
Expand Down
14 changes: 7 additions & 7 deletions src/Core/Worlds/World.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ protected World()

internal World(SerializationInfo info, StreamingContext context)
{
_currentStep = (long)info.GetValue(nameof(_currentStep), typeof(long));
_actorsToBeRemoved = (List<Actor>)info.GetValue(nameof(_actorsToBeRemoved), typeof(List<Actor>));
_actors = (List<Actor>)info.GetValue(nameof(_actors), typeof(List<Actor>));
_actorRemoveLock = (object)info.GetValue(nameof(_actorRemoveLock), typeof(object));
_actorLock = (object)info.GetValue(nameof(_actorLock), typeof(object));
_positionsLock = (object)info.GetValue(nameof(_positionsLock), typeof(object));
positions = (Dictionary<Actor, Vector3>)info.GetValue(nameof(positions), typeof(Dictionary<Actor, Vector3>));
_currentStep = (long)(info.GetValue(nameof(_currentStep), typeof(long)) ?? throw new SerializationException());
_actorsToBeRemoved = (List<Actor>)(info.GetValue(nameof(_actorsToBeRemoved), typeof(List<Actor>)) ?? throw new SerializationException());
_actors = (List<Actor>)(info.GetValue(nameof(_actors), typeof(List<Actor>)) ?? throw new SerializationException());
_actorRemoveLock = (object)(info.GetValue(nameof(_actorRemoveLock), typeof(object)) ?? throw new SerializationException());
_actorLock = (object)(info.GetValue(nameof(_actorLock), typeof(object)) ?? throw new SerializationException());
_positionsLock = (object)(info.GetValue(nameof(_positionsLock), typeof(object)) ?? throw new SerializationException());
positions = (Dictionary<Actor, Vector3>)(info.GetValue(nameof(positions), typeof(Dictionary<Actor, Vector3>)) ?? throw new SerializationException());
}

public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
Expand Down

0 comments on commit 8cc6708

Please sign in to comment.