Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unity fixes for 16.1.3 #996

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions YamlDotNet/Core/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ namespace YamlDotNet.Core
/// </summary>
public static class Constants
{
public static readonly TagDirective[] DefaultTagDirectives =
[
public static readonly TagDirective[] DefaultTagDirectives = new []
{
new TagDirective("!", "!"),
new TagDirective("!!", "tag:yaml.org,2002:")
];
};

public const int MajorVersion = 1;
public const int MinorVersion = 3;
Expand Down
4 changes: 2 additions & 2 deletions YamlDotNet/Core/Emitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class Emitter : IEmitter
private static readonly Regex UriReplacer = new Regex(@"[^0-9A-Za-z_\-;?@=$~\\\)\]/:&+,\.\*\(\[!]",
StandardRegexOptions.Compiled | RegexOptions.Singleline);

private static readonly string[] NewLineSeparators = ["\r\n", "\r", "\n"];
private static readonly string[] NewLineSeparators = new []{"\r\n", "\r", "\n"};

private readonly TextWriter output;
private readonly bool outputUsesUnicodeEncoding;
Expand All @@ -56,7 +56,7 @@ public class Emitter : IEmitter
private readonly Stack<EmitterState> states = new Stack<EmitterState>();
private readonly Queue<ParsingEvent> events = new Queue<ParsingEvent>();
private readonly Stack<int> indents = new Stack<int>();
private readonly TagDirectiveCollection tagDirectives = [];
private readonly TagDirectiveCollection tagDirectives = new ();
private int indent;
private int flowLevel;
private bool isMappingContext;
Expand Down
6 changes: 3 additions & 3 deletions YamlDotNet/Core/MergingParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ private sealed class ParsingEventCollection : IEnumerable<LinkedListNode<Parsing

public ParsingEventCollection()
{
events = [];
deleted = [];
references = [];
events = new ();
deleted = new ();
references = new ();
}

public void AddAfter(LinkedListNode<ParsingEvent> node, IEnumerable<ParsingEvent> items)
Expand Down
2 changes: 1 addition & 1 deletion YamlDotNet/Core/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace YamlDotNet.Core
public class Parser : IParser
{
private readonly Stack<ParserState> states = new Stack<ParserState>();
private readonly TagDirectiveCollection tagDirectives = [];
private readonly TagDirectiveCollection tagDirectives = new ();
private ParserState state;

private readonly IScanner scanner;
Expand Down
2 changes: 1 addition & 1 deletion YamlDotNet/Core/Scanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2518,7 +2518,7 @@ private string ScanTagUri(string? head, Mark start)
return result;
}

private static readonly byte[] EmptyBytes = [];
private static readonly byte[] EmptyBytes = new byte[]{};

/// <summary>
/// Decode an URI-escape sequence corresponding to a single UTF-8 character.
Expand Down
2 changes: 1 addition & 1 deletion YamlDotNet/Helpers/FsharpHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static bool IsFsharpListType(Type t)
.GetType("Microsoft.FSharp.Collections.ListModule")
.GetMethod("OfArray")
.MakeGenericMethod(itemsType)
.Invoke(null, [arr]);
.Invoke(null, new []{ arr });

return fsharpList;
}
Expand Down
4 changes: 2 additions & 2 deletions YamlDotNet/Helpers/OrderedDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public OrderedDictionary() : this(EqualityComparer<TKey>.Default)

public OrderedDictionary(IEqualityComparer<TKey> comparer)
{
list = [];
list = new ();
dictionary = new Dictionary<TKey, TValue>(comparer);
this.comparer = comparer;
}
Expand Down Expand Up @@ -192,7 +192,7 @@ public bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value) =>
internal void OnDeserializedMethod(StreamingContext context)
{
// Reconstruct the dictionary from the serialized list
dictionary = [];
dictionary = new ();
foreach (var kvp in list)
{
dictionary[kvp.Key] = kvp.Value;
Expand Down
2 changes: 1 addition & 1 deletion YamlDotNet/ReflectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static bool IsGenericTypeDefinition(this Type type)

static bool IsGenericDefinitionOfType(Type t, object? context)
{
return t.IsGenericType && t.GetGenericTypeDefinition() == (Type)context;
return t.IsGenericType && context is Type type && t.GetGenericTypeDefinition() == type;
}
}

Expand Down
4 changes: 2 additions & 2 deletions YamlDotNet/RepresentationModel/DocumentLoadingState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ namespace YamlDotNet.RepresentationModel
/// </summary>
internal class DocumentLoadingState
{
private readonly Dictionary<AnchorName, YamlNode> anchors = [];
private readonly List<YamlNode> nodesWithUnresolvedAliases = [];
private readonly Dictionary<AnchorName, YamlNode> anchors = new ();
private readonly List<YamlNode> nodesWithUnresolvedAliases = new ();

/// <summary>
/// Adds the specified node to the anchor list.
Expand Down
2 changes: 1 addition & 1 deletion YamlDotNet/RepresentationModel/EmitterState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ internal class EmitterState
/// Gets the already emitted anchors.
/// </summary>
/// <value>The emitted anchors.</value>
public HashSet<AnchorName> EmittedAnchors { get; } = [];
public HashSet<AnchorName> EmittedAnchors { get; } = new ();
}
}
4 changes: 2 additions & 2 deletions YamlDotNet/RepresentationModel/YamlDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ internal YamlDocument(IParser parser)
/// </summary>
private class AnchorAssigningVisitor : YamlVisitorBase
{
private readonly HashSet<AnchorName> existingAnchors = [];
private readonly HashSet<AnchorName> existingAnchors = new ();
/// <summary>
/// Key: Node, Value: IsDuplicate
/// </summary>
private readonly Dictionary<YamlNode, bool> visitedNodes = [];
private readonly Dictionary<YamlNode, bool> visitedNodes = new ();

public void AssignAnchors(YamlDocument document)
{
Expand Down
6 changes: 3 additions & 3 deletions YamlDotNet/RepresentationModel/YamlMappingNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace YamlDotNet.RepresentationModel
/// </summary>
public sealed class YamlMappingNode : YamlNode, IEnumerable<KeyValuePair<YamlNode, YamlNode>>, IYamlConvertible
{
private readonly OrderedDictionary<YamlNode, YamlNode> children = [];
private readonly OrderedDictionary<YamlNode, YamlNode> children = new();

/// <summary>
/// Gets the children of the current node.
Expand Down Expand Up @@ -196,13 +196,13 @@ internal override void ResolveAliases(DocumentLoadingState state)
{
if (entry.Key is YamlAliasNode)
{
keysToUpdate ??= [];
keysToUpdate ??= new ();
// TODO: The representation model should be redesigned, because here the anchor could be null but that would be invalid YAML
keysToUpdate.Add(entry.Key, state.GetNode(entry.Key.Anchor!, entry.Key.Start, entry.Key.End));
}
if (entry.Value is YamlAliasNode)
{
valuesToUpdate ??= [];
valuesToUpdate ??= new ();
// TODO: The representation model should be redesigned, because here the anchor could be null but that would be invalid YAML
valuesToUpdate.Add(entry.Key, state.GetNode(entry.Value.Anchor!, entry.Value.Start, entry.Value.End));
}
Expand Down
2 changes: 1 addition & 1 deletion YamlDotNet/RepresentationModel/YamlSequenceNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace YamlDotNet.RepresentationModel
[DebuggerDisplay("Count = {children.Count}")]
public sealed class YamlSequenceNode : YamlNode, IEnumerable<YamlNode>, IYamlConvertible
{
private readonly List<YamlNode> children = [];
private readonly List<YamlNode> children = new ();

/// <summary>
/// Gets the collection of child nodes.
Expand Down
2 changes: 1 addition & 1 deletion YamlDotNet/RepresentationModel/YamlStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace YamlDotNet.RepresentationModel
/// </summary>
public class YamlStream : IEnumerable<YamlDocument>
{
private readonly List<YamlDocument> documents = [];
private readonly List<YamlDocument> documents = new ();

/// <summary>
/// Gets the documents inside the stream.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace YamlDotNet.Serialization.BufferedDeserialization
{
public class TypeDiscriminatingNodeDeserializerOptions : ITypeDiscriminatingNodeDeserializerOptions
{
internal readonly List<ITypeDiscriminator> discriminators = [];
internal readonly List<ITypeDiscriminator> discriminators = new ();

/// <summary>
/// Adds an <see cref="ITypeDiscriminator" /> to be checked by the TypeDiscriminatingNodeDeserializer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public bool TryDiscriminate(IParser parser, out Type? suggestedType)
scalar => this.typeMapping.ContainsKey(scalar.Value),
out var key,
out var _))
if (key != null) // Sorry, Unity's compiler didn't figure this one out on its own. Yes this statement shouldn't ever be false.
{
suggestedType = this.typeMapping[key.Value];
return true;
Expand Down
2 changes: 1 addition & 1 deletion YamlDotNet/Serialization/BuilderSkeleton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ internal BuilderSkeleton(ITypeResolver typeResolver)
{ typeof(SystemTypeConverter), _ => new SystemTypeConverter() }
};

typeInspectorFactories = [];
typeInspectorFactories = new ();
this.typeResolver = typeResolver ?? throw new ArgumentNullException(nameof(typeResolver));
settings = new Settings();
}
Expand Down
6 changes: 3 additions & 3 deletions YamlDotNet/Serialization/DeserializerBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public sealed class DeserializerBuilder : BuilderSkeleton<DeserializerBuilder>
public DeserializerBuilder()
: base(new StaticTypeResolver())
{
typeMappings = [];
typeMappings = new ();
objectFactory = new Lazy<IObjectFactory>(() => new DefaultObjectFactory(typeMappings, settings), true);

tagMappings = new Dictionary<TagName, Type>
Expand All @@ -90,6 +90,8 @@ public DeserializerBuilder()
typeInspectorFactories.Add(typeof(YamlAttributeOverridesInspector), inner => overrides != null ? new YamlAttributeOverridesInspector(inner, overrides.Clone()) : inner);
typeInspectorFactories.Add(typeof(ReadableAndWritablePropertiesTypeInspector), inner => new ReadableAndWritablePropertiesTypeInspector(inner));

typeConverter = new ReflectionTypeConverter();

nodeDeserializerFactories = new LazyComponentRegistrationList<Nothing, INodeDeserializer>
{
{ typeof(YamlConvertibleNodeDeserializer), _ => new YamlConvertibleNodeDeserializer(objectFactory.Value) },
Expand Down Expand Up @@ -125,8 +127,6 @@ public DeserializerBuilder()
{ typeof(PreventUnknownTagsNodeTypeResolver), _ => new PreventUnknownTagsNodeTypeResolver() },
{ typeof(DefaultContainersNodeTypeResolver), _ => new DefaultContainersNodeTypeResolver() }
};

typeConverter = new ReflectionTypeConverter();
}

protected override DeserializerBuilder Self { get { return this; } }
Expand Down
4 changes: 2 additions & 2 deletions YamlDotNet/Serialization/IObjectFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ public interface IObjectFactory
/// Executes the methods on the object that has the <seealso cref="Callbacks.OnSerializingAttribute"/> attribute
/// </summary>
/// <param name="value"></param>
void ExecuteOnSerializing(object value);
void ExecuteOnSerializing(object? value);

/// <summary>
/// Executes the methods on the object that has the <seealso cref="Callbacks.OnSerializedAttribute"/> attribute
/// </summary>
/// <param name="value"></param>
void ExecuteOnSerialized(object value);
void ExecuteOnSerialized(object? value);
}
}
2 changes: 1 addition & 1 deletion YamlDotNet/Serialization/IObjectGraphTraversalStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ public interface IObjectGraphTraversalStrategy
/// <param name="visitor">An <see cref="IObjectGraphVisitor{TContext}"/> that is to be notified during the traversal.</param>
/// <param name="context">A <typeparamref name="TContext" /> that will be passed to the <paramref name="visitor" />.</param>
/// <param name="serializer">The serializer to use to serialize complex objects.</param>
void Traverse<TContext>(IObjectDescriptor graph, IObjectGraphVisitor<TContext> visitor, TContext context, ObjectSerializer serializer);
void Traverse<TContext>(IObjectDescriptor graph, IObjectGraphVisitor<TContext> visitor, TContext context, ObjectSerializer serializer) where TContext : notnull;
}
}
2 changes: 1 addition & 1 deletion YamlDotNet/Serialization/LazyComponentRegistrationList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace YamlDotNet.Serialization
{
internal sealed class LazyComponentRegistrationList<TArgument, TComponent> : IEnumerable<Func<TArgument, TComponent>>
{
private readonly List<LazyComponentRegistration> entries = [];
private readonly List<LazyComponentRegistration> entries = new ();

public LazyComponentRegistrationList<TArgument, TComponent> Clone()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public bool Deserialize(IParser parser, Type expectedType, Func<IParser, Type, o
return true;
}

public void NullCheck(object value, IPropertyDescriptor property, Scalar propertyName)
public void NullCheck(object? value, IPropertyDescriptor property, Scalar propertyName)
{
if (enforceNullability &&
value == null &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ public override void ExecuteOnDeserialized(object value) =>
public override void ExecuteOnDeserializing(object value) =>
ExecuteState(typeof(OnDeserializingAttribute), value);

public override void ExecuteOnSerialized(object value) =>
public override void ExecuteOnSerialized(object? value) =>
ExecuteState(typeof(OnSerializedAttribute), value);

public override void ExecuteOnSerializing(object value) =>
public override void ExecuteOnSerializing(object? value) =>
ExecuteState(typeof(OnSerializingAttribute), value);

private void ExecuteState(Type attributeType, object value)
private void ExecuteState(Type attributeType, object? value)
{
if (value == null)
{
Expand Down
4 changes: 2 additions & 2 deletions YamlDotNet/Serialization/ObjectFactories/ObjectFactoryBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ public virtual void ExecuteOnDeserializing(object value)
}

/// <inheritdoc />
public virtual void ExecuteOnSerialized(object value)
public virtual void ExecuteOnSerialized(object? value)
{
}

/// <inheritdoc />
public virtual void ExecuteOnSerializing(object value)
public virtual void ExecuteOnSerializing(object? value)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ public bool GetDictionary(IObjectDescriptor descriptor, out IDictionary? diction

public abstract void ExecuteOnDeserialized(object value);

public abstract void ExecuteOnSerializing(object value);
public abstract void ExecuteOnSerializing(object? value);

public abstract void ExecuteOnSerialized(object value);
public abstract void ExecuteOnSerialized(object? value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public ObjectPathSegment(object name, IObjectDescriptor value)
}
}

protected virtual void Traverse<TContext>(IPropertyDescriptor? propertyDescriptor, object name, IObjectDescriptor value, IObjectGraphVisitor<TContext> visitor, TContext context, Stack<ObjectPathSegment> path, ObjectSerializer serializer)
protected virtual void Traverse<TContext>(IPropertyDescriptor? propertyDescriptor, object name, IObjectDescriptor value, IObjectGraphVisitor<TContext> visitor, TContext context, Stack<ObjectPathSegment> path, ObjectSerializer serializer) where TContext : notnull
{
if (path.Count >= maxRecursion)
{
Expand Down Expand Up @@ -192,7 +192,7 @@ protected virtual void Traverse<TContext>(IPropertyDescriptor? propertyDescripto
}
}

protected virtual void TraverseObject<TContext>(IPropertyDescriptor? propertyDescriptor, IObjectDescriptor value, IObjectGraphVisitor<TContext> visitor, TContext context, Stack<ObjectPathSegment> path, ObjectSerializer serializer)
protected virtual void TraverseObject<TContext>(IPropertyDescriptor? propertyDescriptor, IObjectDescriptor value, IObjectGraphVisitor<TContext> visitor, TContext context, Stack<ObjectPathSegment> path, ObjectSerializer serializer) where TContext : notnull
{
if (typeof(IDictionary).IsAssignableFrom(value.Type))
{
Expand All @@ -201,6 +201,7 @@ protected virtual void TraverseObject<TContext>(IPropertyDescriptor? propertyDes
}

if (objectFactory.GetDictionary(value, out var adaptedDictionary, out var genericArguments))
if (genericArguments != null)
{
TraverseDictionary(propertyDescriptor, new ObjectDescriptor(adaptedDictionary, value.Type, value.StaticType, value.ScalarStyle), visitor, genericArguments[0], genericArguments[1], context, path, serializer);
return;
Expand All @@ -215,7 +216,7 @@ protected virtual void TraverseObject<TContext>(IPropertyDescriptor? propertyDes
TraverseProperties(value, visitor, context, path, serializer);
}

protected virtual void TraverseDictionary<TContext>(IPropertyDescriptor? propertyDescriptor, IObjectDescriptor dictionary, IObjectGraphVisitor<TContext> visitor, Type keyType, Type valueType, TContext context, Stack<ObjectPathSegment> path, ObjectSerializer serializer)
protected virtual void TraverseDictionary<TContext>(IPropertyDescriptor? propertyDescriptor, IObjectDescriptor dictionary, IObjectGraphVisitor<TContext> visitor, Type keyType, Type valueType, TContext context, Stack<ObjectPathSegment> path, ObjectSerializer serializer) where TContext : notnull
{
visitor.VisitMappingStart(dictionary, keyType, valueType, context, serializer);

Expand All @@ -237,7 +238,7 @@ protected virtual void TraverseDictionary<TContext>(IPropertyDescriptor? propert
visitor.VisitMappingEnd(dictionary, context, serializer);
}

private void TraverseList<TContext>(IPropertyDescriptor propertyDescriptor, IObjectDescriptor value, IObjectGraphVisitor<TContext> visitor, TContext context, Stack<ObjectPathSegment> path, ObjectSerializer serializer)
private void TraverseList<TContext>(IPropertyDescriptor? propertyDescriptor, IObjectDescriptor value, IObjectGraphVisitor<TContext> visitor, TContext context, Stack<ObjectPathSegment> path, ObjectSerializer serializer) where TContext : notnull
{
var itemType = objectFactory.GetValueType(value.Type);

Expand All @@ -254,7 +255,7 @@ private void TraverseList<TContext>(IPropertyDescriptor propertyDescriptor, IObj
visitor.VisitSequenceEnd(value, context, serializer);
}

protected virtual void TraverseProperties<TContext>(IObjectDescriptor value, IObjectGraphVisitor<TContext> visitor, TContext context, Stack<ObjectPathSegment> path, ObjectSerializer serializer)
protected virtual void TraverseProperties<TContext>(IObjectDescriptor value, IObjectGraphVisitor<TContext> visitor, TContext context, Stack<ObjectPathSegment> path, ObjectSerializer serializer) where TContext : notnull
{
if (context.GetType() != typeof(Nothing))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private class AnchorAssignment
public AnchorName Anchor;
}

private readonly Dictionary<object, AnchorAssignment> assignments = [];
private readonly Dictionary<object, AnchorAssignment> assignments = new ();
private uint nextId;

public AnchorAssigner(IEnumerable<IYamlTypeConverter> typeConverters)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public sealed class AnchorAssigningObjectGraphVisitor : ChainedObjectGraphVisito
{
private readonly IEventEmitter eventEmitter;
private readonly IAliasProvider aliasProvider;
private readonly HashSet<AnchorName> emittedAliases = [];
private readonly HashSet<AnchorName> emittedAliases = new ();

public AnchorAssigningObjectGraphVisitor(IObjectGraphVisitor<IEmitter> nextVisitor, IEventEmitter eventEmitter, IAliasProvider aliasProvider)
: base(nextVisitor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public abstract class PreProcessingPhaseObjectGraphVisitorSkeleton : IObjectGrap

public PreProcessingPhaseObjectGraphVisitorSkeleton(IEnumerable<IYamlTypeConverter> typeConverters)
{
var tcs = typeConverters?.ToArray() ?? [];
var tcs = typeConverters?.ToArray() ?? new IYamlTypeConverter[]{};

this.typeConverters = tcs;
this.typeConverterCache = new TypeConverterCache(tcs);
Expand Down
Loading