From c0cef57e767f2e080ff2be8482c250fa39eeafcc Mon Sep 17 00:00:00 2001 From: Sparkrai <10998731+Sparkrai@users.noreply.github.com> Date: Mon, 1 Jul 2019 11:06:55 +0100 Subject: [PATCH 1/3] Add easier way to add DateTime values Added an easier way to add DateTime(through DateTimeValueSyntax) using the list initialization syntax --- src/Tomlyn/Syntax/SyntaxNodeExtensions.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Tomlyn/Syntax/SyntaxNodeExtensions.cs b/src/Tomlyn/Syntax/SyntaxNodeExtensions.cs index 56c3d28..406347a 100644 --- a/src/Tomlyn/Syntax/SyntaxNodeExtensions.cs +++ b/src/Tomlyn/Syntax/SyntaxNodeExtensions.cs @@ -44,12 +44,20 @@ public static void Add(this SyntaxList list, string name, int[] list.Add(new KeyValueSyntax(name, new ArraySyntax(values))); } - public static void Add(this SyntaxList list, string name, string[] values) + public static void Add(this SyntaxList list, string name, DateTimeValueSyntax value) + { + if (list == null) throw new ArgumentNullException(nameof(list)); + list.Add(new KeyValueSyntax(name, value)); + } + + public static KeyValueSyntax AddComment(this KeyValueSyntax keyValue, string comment) { - if (list == null) throw new ArgumentNullException(nameof(list)); - list.Add(new KeyValueSyntax(name, new ArraySyntax(values))); + if (keyValue == null) throw new ArgumentNullException(nameof(keyValue)); + if (keyValue.Value == null) throw new InvalidOperationException("The Value must not be null on the KeyValueSyntax"); + keyValue.Value.AddTrailingWhitespace().AddComment(comment); + return keyValue; } - + public static KeyValueSyntax AddComment(this KeyValueSyntax keyValue, string comment) { if (keyValue == null) throw new ArgumentNullException(nameof(keyValue)); @@ -96,4 +104,4 @@ public static T AddComment(this T node, string comment) where T : SyntaxNode return node; } } -} \ No newline at end of file +} From 69d24acc7581180a4786aa10af433d317afb7195 Mon Sep 17 00:00:00 2001 From: Sparkrai <10998731+Sparkrai@users.noreply.github.com> Date: Mon, 1 Jul 2019 11:13:38 +0100 Subject: [PATCH 2/3] Re-added string[] extension method Re-added the string array Add() extension method that was involuntarily deleted --- src/Tomlyn/Syntax/SyntaxNodeExtensions.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Tomlyn/Syntax/SyntaxNodeExtensions.cs b/src/Tomlyn/Syntax/SyntaxNodeExtensions.cs index 406347a..99915f0 100644 --- a/src/Tomlyn/Syntax/SyntaxNodeExtensions.cs +++ b/src/Tomlyn/Syntax/SyntaxNodeExtensions.cs @@ -43,6 +43,12 @@ public static void Add(this SyntaxList list, string name, int[] if (list == null) throw new ArgumentNullException(nameof(list)); list.Add(new KeyValueSyntax(name, new ArraySyntax(values))); } + + public static void Add(this SyntaxList list, string name, string[] values) + { + if (list == null) throw new ArgumentNullException(nameof(list)); + list.Add(new KeyValueSyntax(name, new ArraySyntax(values))); + } public static void Add(this SyntaxList list, string name, DateTimeValueSyntax value) { From 536e474722d025376bab8b0b764e35a399f95fb0 Mon Sep 17 00:00:00 2001 From: Sparkrai <10998731+Sparkrai@users.noreply.github.com> Date: Mon, 1 Jul 2019 11:21:09 +0100 Subject: [PATCH 3/3] Deleted duplicated AddComment function Deleted involuntarily duplicated AddComment function --- src/Tomlyn/Syntax/SyntaxNodeExtensions.cs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/Tomlyn/Syntax/SyntaxNodeExtensions.cs b/src/Tomlyn/Syntax/SyntaxNodeExtensions.cs index 99915f0..5fa9dc6 100644 --- a/src/Tomlyn/Syntax/SyntaxNodeExtensions.cs +++ b/src/Tomlyn/Syntax/SyntaxNodeExtensions.cs @@ -63,14 +63,6 @@ public static KeyValueSyntax AddComment(this KeyValueSyntax keyValue, string com keyValue.Value.AddTrailingWhitespace().AddComment(comment); return keyValue; } - - public static KeyValueSyntax AddComment(this KeyValueSyntax keyValue, string comment) - { - if (keyValue == null) throw new ArgumentNullException(nameof(keyValue)); - if (keyValue.Value == null) throw new InvalidOperationException("The Value must not be null on the KeyValueSyntax"); - keyValue.Value.AddTrailingWhitespace().AddComment(comment); - return keyValue; - } public static T AddLeadingWhitespace(this T node) where T : SyntaxNode {