From db70f356e03098bb039668aa0b1674a224d06f08 Mon Sep 17 00:00:00 2001 From: "Thyge S. Steffensen" Date: Tue, 23 Aug 2022 20:07:49 +0200 Subject: [PATCH 1/3] test: Add test for getting plain object from ValueContainer --- Test/ValueContainer/TestGetObject.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Test/ValueContainer/TestGetObject.cs diff --git a/Test/ValueContainer/TestGetObject.cs b/Test/ValueContainer/TestGetObject.cs new file mode 100644 index 0000000..34e5df1 --- /dev/null +++ b/Test/ValueContainer/TestGetObject.cs @@ -0,0 +1,19 @@ +using ExpressionEngine; +using NUnit.Framework; + +namespace Test +{ + [TestFixture] + public class TestGetObject + { + [TestCase] + public void TestImplicitConversionThingy() + { + var valueContainer = new ValueContainer("Hello CLR Type!"); + + var value = valueContainer.GetValue(); + + Assert.AreEqual(typeof(string), value.GetType()); + } + } +} \ No newline at end of file From cc231dd56b9f39ee0aeedd453de37710456a5704 Mon Sep 17 00:00:00 2001 From: "Thyge S. Steffensen" Date: Tue, 23 Aug 2022 20:08:14 +0200 Subject: [PATCH 2/3] docs: Fix type on XML comment --- ExpressionEngine/ValueContainer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ExpressionEngine/ValueContainer.cs b/ExpressionEngine/ValueContainer.cs index 1afe27e..69f0ef8 100644 --- a/ExpressionEngine/ValueContainer.cs +++ b/ExpressionEngine/ValueContainer.cs @@ -158,7 +158,7 @@ public bool IsNumber() } /// - /// Get the value of the ValueContainer has it's respective C# type + /// Get the value of the ValueContainer as its respective C# type /// /// double and float is converted to decimal. /// From bc1d0d02cf6cbbe5316fc5b44c4dbe9c744d00fd Mon Sep 17 00:00:00 2001 From: "Thyge S. Steffensen" Date: Tue, 23 Aug 2022 20:08:33 +0200 Subject: [PATCH 3/3] fix: Add option for getting plain object from .GetValue<> --- ExpressionEngine/ValueContainer.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ExpressionEngine/ValueContainer.cs b/ExpressionEngine/ValueContainer.cs index 69f0ef8..bf151f2 100644 --- a/ExpressionEngine/ValueContainer.cs +++ b/ExpressionEngine/ValueContainer.cs @@ -184,11 +184,14 @@ public T GetValue() { case { } iEnumerable when iEnumerable == typeof(IEnumerable): return (T) GetValue>().AsEnumerable(); - // case { } array when array == typeof(ValueContainer[]): - // return GetValue>().ToArray(); } } + if (typeof(T) == typeof(object)) + { + return (T) _value; + } + throw new ExpressionEngineException( $"Cannot convert ValueContainer of type {_value.GetType()} to {typeof(T)}"); }