Skip to content

Commit

Permalink
some code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
grahamboree committed Feb 4, 2024
1 parent 76a809d commit 7727e5d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/DarkConfig/DocNode/DocNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public class DocNodeAccessException : Exception {
public DocNodeAccessException(string message) : base(message) { }
}

/// DocNode represents a node of a parsed document.
/// DocNode is a union type, requiring no casting but behaving differently
/// DocNode represents a node of a parsed document.
/// DocNode is a union type, requiring no casting but behaving differently
/// depending on the underlying value.
/// DocNode also assumes that all Dictionaries have strings as keys.
public abstract class DocNode : IEquatable<DocNode> {
Expand Down Expand Up @@ -50,7 +50,7 @@ public abstract class DocNode : IEquatable<DocNode> {
/// Iterates over the values of the list
public abstract IEnumerable<DocNode> Values { get; }

/// Iterates over a dictionary
/// Iterates over a dictionary
public abstract IEnumerable<KeyValuePair<string, DocNode>> Pairs { get; }

/// String describing the position and context in the source format (e.g. line number).
Expand All @@ -63,7 +63,7 @@ public T As<T>(ReificationOptions? options = null) {
}

/// <summary>
/// Only works on lists. Checks for the given doc node StringValue in the list.
/// Only works on lists. Checks for the given doc node StringValue in the list.
/// </summary>
/// <param name="item">String to search for</param>
/// <returns>True if the string exists in this list</returns>
Expand Down Expand Up @@ -164,7 +164,7 @@ public int GetDeepHashCode() {

/// <summary>
/// Generates a new DocNode that is the result of merging two other DocNodes.
///
///
/// lists are concatenated.
/// Dictionaries are merged and values recursively DeepMerged.
/// Favors rhs in the event of any unresolvable conflict.
Expand Down
7 changes: 4 additions & 3 deletions src/DarkConfig/Internal/TypeReifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,11 @@ public object ReadValueOfType(Type targetType, object existing, DocNode doc, Rei
if (targetType == typeof(string)) { return doc.StringValue; }
#endregion

bool ignoreCase = (options & ReificationOptions.CaseSensitive) == 0;

// Enums
if (targetType.IsEnum) {
return Enum.Parse(targetType, doc.StringValue, (options & ReificationOptions.CaseSensitive) == 0);
return Enum.Parse(targetType, doc.StringValue, ignoreCase);
}

// DocNode
Expand Down Expand Up @@ -413,7 +415,7 @@ void ReadArray(DocNode current, int currentRank) {

// Nullable<T>
if (genericTypeDef == typeof(Nullable<>)) {
var comparisonOptions = (options & ReificationOptions.CaseSensitive) == 0 ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase;
var comparisonOptions = ignoreCase ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase;
if (doc.Type == DocNodeType.Scalar && string.Equals(doc.StringValue, "null", comparisonOptions)) {
return null;
}
Expand Down Expand Up @@ -708,7 +710,6 @@ bool SetMember(Type type, ref object obj, string memberName, DocNode doc, Reific
if (!allowExtra) {
throw new ExtraFieldsException(doc, $"Could not find a member named {memberName} on type {type.Name}");
}

return false;
}
}
Expand Down

0 comments on commit 7727e5d

Please sign in to comment.