From 024484c44772514d5a2e8a2f2df231948c5b6398 Mon Sep 17 00:00:00 2001 From: Dennis Beuchler Date: Fri, 12 Feb 2021 10:55:05 +0100 Subject: [PATCH 1/6] Bumped version to 3.0.4 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 282895a8f..b38ebbfce 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.0.3 \ No newline at end of file +3.0.4 \ No newline at end of file From 638d068a740ac0bdf85237abd25c66b62ae01c45 Mon Sep 17 00:00:00 2001 From: leopoldHatFertig <49842684+leopoldHatFertig@users.noreply.github.com> Date: Fri, 19 Mar 2021 02:42:18 +0100 Subject: [PATCH 2/6] Update StateDefinitionAttribute.cs fixed typo in XML comment --- src/Moryx/StateMachines/StateDefinitionAttribute.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Moryx/StateMachines/StateDefinitionAttribute.cs b/src/Moryx/StateMachines/StateDefinitionAttribute.cs index 46d25af1c..8db6eaa52 100644 --- a/src/Moryx/StateMachines/StateDefinitionAttribute.cs +++ b/src/Moryx/StateMachines/StateDefinitionAttribute.cs @@ -26,7 +26,7 @@ public StateDefinitionAttribute(Type type) public Type Type { get; } /// - /// 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. /// public bool IsInitial { get; set; } } From 728f94a3d9d8f6b5a6865f947c5fe795e906dc0b Mon Sep 17 00:00:00 2001 From: Dennis Beuchler Date: Wed, 21 Apr 2021 13:17:08 +0200 Subject: [PATCH 3/6] Updated tools and references for unit tests and report generation --- .build/BuildToolkit.ps1 | 4 ++-- Directory.Build.targets | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.build/BuildToolkit.ps1 b/.build/BuildToolkit.ps1 index 3cfa8883d..20fcab0cc 100644 --- a/.build/BuildToolkit.ps1 +++ b/.build/BuildToolkit.ps1 @@ -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; diff --git a/Directory.Build.targets b/Directory.Build.targets index f91d1089e..4f39d1cb5 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -12,8 +12,8 @@ - - + + From f92d552a00a41f5533800c40327247528df2d771 Mon Sep 17 00:00:00 2001 From: Marisa Goergen Date: Wed, 28 Apr 2021 10:17:13 +0200 Subject: [PATCH 4/6] ReflectionResolver can map strings on properties with primitive datatypes --- docs/articles/Platform/Bindings.md | 2 +- src/Moryx/Bindings/ReflectionResolver.cs | 7 ++++++- .../Moryx.Tests/Bindings/Dummies/SomeClass.cs | 3 +++ .../Bindings/ReflectionResolverTests.cs | 19 +++++++++++++++++-- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/docs/articles/Platform/Bindings.md b/docs/articles/Platform/Bindings.md index 648d1652c..dfc121e93 100644 --- a/docs/articles/Platform/Bindings.md +++ b/docs/articles/Platform/Bindings.md @@ -105,7 +105,7 @@ class Foo } var foo = new Foo(); -resolver = new ReflectionResolver("Name"); +IBindingResolver resolver = new ReflectionResolver("Name"); resolver.Update(foo, "Bob"); ```` diff --git a/src/Moryx/Bindings/ReflectionResolver.cs b/src/Moryx/Bindings/ReflectionResolver.cs index c9e5d75c7..7b64d35a2 100644 --- a/src/Moryx/Bindings/ReflectionResolver.cs +++ b/src/Moryx/Bindings/ReflectionResolver.cs @@ -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 { @@ -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 string && property.PropertyType.IsPrimitive) + property.SetValue(source, Convert.ChangeType(value, property.PropertyType)); + else + property.SetValue(source, value); return true; } diff --git a/src/Tests/Moryx.Tests/Bindings/Dummies/SomeClass.cs b/src/Tests/Moryx.Tests/Bindings/Dummies/SomeClass.cs index 631b3e566..c027a7249 100644 --- a/src/Tests/Moryx.Tests/Bindings/Dummies/SomeClass.cs +++ b/src/Tests/Moryx.Tests/Bindings/Dummies/SomeClass.cs @@ -7,6 +7,9 @@ public class SomeClass { public string SimpleString { get; set; } + public int SimpleInt { get; set; } + public ISomeInterface SomeObject { get; set; } + } } diff --git a/src/Tests/Moryx.Tests/Bindings/ReflectionResolverTests.cs b/src/Tests/Moryx.Tests/Bindings/ReflectionResolverTests.cs index 28062d9a2..85e965da9 100644 --- a/src/Tests/Moryx.Tests/Bindings/ReflectionResolverTests.cs +++ b/src/Tests/Moryx.Tests/Bindings/ReflectionResolverTests.cs @@ -46,6 +46,23 @@ 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(Description = "Checks if the reflection resolver returns null by resolving an unknown property")] public void NullByUnknownProperty() { @@ -82,7 +99,5 @@ public void HiddenPropertyByNewKeyword() // Assert Assert.NotNull(result); } - - } } From 1acc0aa87465a66d99594defde85b8620bfabf94 Mon Sep 17 00:00:00 2001 From: Marisa Goergen Date: Wed, 28 Apr 2021 12:19:25 +0200 Subject: [PATCH 5/6] ReflectionResolver.Update automatically casts IConvertible-objects --- src/Moryx/Bindings/ReflectionResolver.cs | 2 +- .../Bindings/ReflectionResolverTests.cs | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Moryx/Bindings/ReflectionResolver.cs b/src/Moryx/Bindings/ReflectionResolver.cs index 7b64d35a2..e45ebb8e7 100644 --- a/src/Moryx/Bindings/ReflectionResolver.cs +++ b/src/Moryx/Bindings/ReflectionResolver.cs @@ -40,7 +40,7 @@ protected sealed override bool Update(object source, object value) if (property == null || !property.CanWrite) return false; - if (value is string && property.PropertyType.IsPrimitive) + if (value is IConvertible && property.PropertyType.GetInterfaces().Contains(typeof(IConvertible)) ) property.SetValue(source, Convert.ChangeType(value, property.PropertyType)); else property.SetValue(source, value); diff --git a/src/Tests/Moryx.Tests/Bindings/ReflectionResolverTests.cs b/src/Tests/Moryx.Tests/Bindings/ReflectionResolverTests.cs index 85e965da9..791c627a4 100644 --- a/src/Tests/Moryx.Tests/Bindings/ReflectionResolverTests.cs +++ b/src/Tests/Moryx.Tests/Bindings/ReflectionResolverTests.cs @@ -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; @@ -63,6 +64,23 @@ public void AssignStringToInt() 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() { From 6a11af365133abdba8924bfa1b96e2fcbe00b539 Mon Sep 17 00:00:00 2001 From: Marisa Goergen Date: Thu, 29 Apr 2021 08:19:15 +0200 Subject: [PATCH 6/6] Adjust typecheck in ReflectionResolver --- src/Moryx/Bindings/ReflectionResolver.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Moryx/Bindings/ReflectionResolver.cs b/src/Moryx/Bindings/ReflectionResolver.cs index e45ebb8e7..441eb06f1 100644 --- a/src/Moryx/Bindings/ReflectionResolver.cs +++ b/src/Moryx/Bindings/ReflectionResolver.cs @@ -40,7 +40,7 @@ protected sealed override bool Update(object source, object value) if (property == null || !property.CanWrite) return false; - if (value is IConvertible && property.PropertyType.GetInterfaces().Contains(typeof(IConvertible)) ) + if (value is IConvertible && typeof(IConvertible).IsAssignableFrom(property.PropertyType)) property.SetValue(source, Convert.ChangeType(value, property.PropertyType)); else property.SetValue(source, value);