Skip to content

Commit

Permalink
Merge pull request #88 from delegateas/tst/implicit-conversion-56
Browse files Browse the repository at this point in the history
Tst/implicit conversion 56
  • Loading branch information
thygesteffensen authored Aug 23, 2022
2 parents 942eec5 + bc1d0d0 commit 271a949
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
9 changes: 6 additions & 3 deletions ExpressionEngine/ValueContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public bool IsNumber()
}

/// <summary>
/// Get the value of the ValueContainer has it's respective C# type
/// Get the value of the ValueContainer as its respective C# type
///
/// <code>double</code> and <code>float</code> is converted to <code>decimal</code>.
/// </summary>
Expand All @@ -184,11 +184,14 @@ public T GetValue<T>()
{
case { } iEnumerable when iEnumerable == typeof(IEnumerable<ValueContainer>):
return (T) GetValue<List<ValueContainer>>().AsEnumerable();
// case { } array when array == typeof(ValueContainer[]):
// return GetValue<List<ValueContainer>>().ToArray();
}
}

if (typeof(T) == typeof(object))
{
return (T) _value;
}

throw new ExpressionEngineException(
$"Cannot convert ValueContainer of type {_value.GetType()} to {typeof(T)}");
}
Expand Down
19 changes: 19 additions & 0 deletions Test/ValueContainer/TestGetObject.cs
Original file line number Diff line number Diff line change
@@ -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<object>();

Assert.AreEqual(typeof(string), value.GetType());
}
}
}

0 comments on commit 271a949

Please sign in to comment.