Skip to content

Commit

Permalink
Merge branch 'upstream/dev' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Toxantron committed Apr 30, 2021
2 parents cc7ae1b + 63d5b04 commit fc59cbd
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .build/BuildToolkit.ps1
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Tool Versions
$NunitVersion = "3.11.1";
$NunitVersion = "3.12.0";
$OpenCoverVersion = "4.7.922";
$DocFxVersion = "2.56.2";
$ReportGeneratorVersion = "4.6.7";
$ReportGeneratorVersion = "4.8.7";

# Folder Pathes
$RootPath = $MyInvocation.PSScriptRoot;
Expand Down
4 changes: 2 additions & 2 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<ItemGroup>
<!--3rd party dependencies-->
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="16.8.0" />
<PackageReference Update="Moq" Version="4.15.1" />
<PackageReference Update="NUnit" Version="3.12.0" />
<PackageReference Update="Moq" Version="4.16.1" />
<PackageReference Update="NUnit" Version="3.13.1" />
<PackageReference Update="NUnit3TestAdapter" Version="3.17.0" />

<PackageReference Update="System.ComponentModel.Annotations" Version="4.7.0" />
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.3
3.0.4
2 changes: 1 addition & 1 deletion docs/articles/Platform/Bindings.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class Foo
}

var foo = new Foo();
resolver = new ReflectionResolver("Name");
IBindingResolver resolver = new ReflectionResolver("Name");
resolver.Update(foo, "Bob");
````

Expand Down
7 changes: 6 additions & 1 deletion src/Moryx/Bindings/ReflectionResolver.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// Copyright (c) 2020, Phoenix Contact GmbH & Co. KG
// Licensed under the Apache License, Version 2.0

using System;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;

namespace Moryx.Bindings
{
Expand Down Expand Up @@ -38,7 +40,10 @@ protected sealed override bool Update(object source, object value)
if (property == null || !property.CanWrite)
return false;

property.SetValue(source, value);
if (value is IConvertible && typeof(IConvertible).IsAssignableFrom(property.PropertyType))
property.SetValue(source, Convert.ChangeType(value, property.PropertyType));
else
property.SetValue(source, value);
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Moryx/StateMachines/StateDefinitionAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public StateDefinitionAttribute(Type type)
public Type Type { get; }

/// <summary>
/// Defines weather the state is the initial state of the machine or not.
/// Defines whether the state is the initial state of the machine or not.
/// </summary>
public bool IsInitial { get; set; }
}
Expand Down
3 changes: 3 additions & 0 deletions src/Tests/Moryx.Tests/Bindings/Dummies/SomeClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ public class SomeClass
{
public string SimpleString { get; set; }

public int SimpleInt { get; set; }

public ISomeInterface SomeObject { get; set; }

}
}
37 changes: 35 additions & 2 deletions src/Tests/Moryx.Tests/Bindings/ReflectionResolverTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) 2020, Phoenix Contact GmbH & Co. KG
// Licensed under the Apache License, Version 2.0

using System;
using System.Reflection;
using Moryx.Bindings;
using NUnit.Framework;
Expand Down Expand Up @@ -46,6 +47,40 @@ public void SimpleAssign()
Assert.AreEqual(str, obj.SimpleString);
}

[Test]
public void AssignStringToInt()
{
const string number = "5";

// Arrange
var obj = new SomeHiddenPropertyClass();
IBindingResolver reflectionResolver = new ReflectionResolver(nameof(SomeClass.SimpleInt));

// Act
var result = reflectionResolver.Update(obj, number);

// Assert
Assert.IsTrue(result);
Assert.AreEqual(int.Parse(number), obj.SimpleInt);
}

[Test]
public void AssignDoubleToString()
{
const double value = 7.78;

// Arrange
var obj = new SomeHiddenPropertyClass();
IBindingResolver reflectionResolver = new ReflectionResolver(nameof(SomeClass.SimpleString));

// Act
var result = reflectionResolver.Update(obj, value);

// Assert
Assert.IsTrue(result);
Assert.AreEqual(value, Convert.ToDouble(obj.SimpleString));
}

[Test(Description = "Checks if the reflection resolver returns null by resolving an unknown property")]
public void NullByUnknownProperty()
{
Expand Down Expand Up @@ -82,7 +117,5 @@ public void HiddenPropertyByNewKeyword()
// Assert
Assert.NotNull(result);
}


}
}

0 comments on commit fc59cbd

Please sign in to comment.