diff --git a/ImpromptuInterface/src/EmitProxy/ActLikeMaker.cs b/ImpromptuInterface/src/EmitProxy/ActLikeMaker.cs index 3e0f5f6..f985351 100644 --- a/ImpromptuInterface/src/EmitProxy/ActLikeMaker.cs +++ b/ImpromptuInterface/src/EmitProxy/ActLikeMaker.cs @@ -1433,11 +1433,36 @@ public static CustomAttributeBuilder ToCustomAttributeBuilder(CustomAttributeDat { return new CustomAttributeBuilder( customAttributeData.Constructor, - customAttributeData.ConstructorArguments.Select(arg => arg.Value).ToArray(), - customAttributeData.NamedArguments.Where(arg => arg.MemberInfo.MemberType == MemberTypes.Property).Select(arg => arg.MemberInfo).Cast().ToArray(), - customAttributeData.NamedArguments.Where(arg => arg.MemberInfo.MemberType == MemberTypes.Property).Select(arg => arg.TypedValue.Value).ToArray(), - customAttributeData.NamedArguments.Where(arg => arg.MemberInfo.MemberType == MemberTypes.Field).Select(arg => arg.MemberInfo).Cast().ToArray(), - customAttributeData.NamedArguments.Where(arg => arg.MemberInfo.MemberType == MemberTypes.Field).Select(arg => arg.TypedValue.Value).ToArray()); + customAttributeData.ConstructorArguments + .Select( + arg => + arg.Value?.GetType() + == typeof(ReadOnlyCollection) + ? ((ReadOnlyCollection)arg.Value) + .Select(arrayArg => arrayArg.Value) + .ToArray() + : arg.Value + ) + .ToArray(), + customAttributeData.NamedArguments + .Where(arg => arg.MemberInfo.MemberType == MemberTypes.Property) + .Select(arg => arg.MemberInfo) + .Cast() + .ToArray(), + customAttributeData.NamedArguments + .Where(arg => arg.MemberInfo.MemberType == MemberTypes.Property) + .Select(arg => arg.TypedValue.Value) + .ToArray(), + customAttributeData.NamedArguments + .Where(arg => arg.MemberInfo.MemberType == MemberTypes.Field) + .Select(arg => arg.MemberInfo) + .Cast() + .ToArray(), + customAttributeData.NamedArguments + .Where(arg => arg.MemberInfo.MemberType == MemberTypes.Field) + .Select(arg => arg.TypedValue.Value) + .ToArray() + ); } diff --git a/Tests/UnitTestImpromptuInterface/Basic.cs b/Tests/UnitTestImpromptuInterface/Basic.cs index d05d172..c72ac49 100644 --- a/Tests/UnitTestImpromptuInterface/Basic.cs +++ b/Tests/UnitTestImpromptuInterface/Basic.cs @@ -444,11 +444,30 @@ public void PropertyAttributeTest() { dynamic tNew = new ExpandoObject(); ISimpeleSetClassProps tActsLike = Impromptu.ActLike(tNew); - var attribute = (DisplayNameAttribute)tActsLike.GetType().GetProperty(nameof(ISimpeleSetClassProps.Prop1)).GetCustomAttribute(typeof(DisplayNameAttribute), true); + var attribute = (DisplayNameAttribute) + tActsLike + .GetType() + .GetProperty(nameof(ISimpeleSetClassProps.Prop1)) + .GetCustomAttribute(typeof(DisplayNameAttribute), true); Assert.NotNull(attribute); Assert.AreEqual("testDisplayName", attribute.DisplayName); } + [Test] + public void PropertyAttributeWithArrayArgumentTest() + { + dynamic tNew = new ExpandoObject(); + ISimpeleSetClassProps tActsLike = Impromptu.ActLike(tNew); + var attribute = (DisplayNamesAttribute) + tActsLike + .GetType() + .GetProperty(nameof(ISimpeleSetClassProps.Prop2)) + .GetCustomAttribute(typeof(DisplayNamesAttribute), true); + Assert.NotNull(attribute); + Assert.AreEqual("testDisplayName1", attribute.DisplayNames[0]); + Assert.AreEqual("testDisplayName2", attribute.DisplayNames[1]); + } + [Test] public void EventDynamicPropertyTest() { @@ -654,6 +673,15 @@ public void RefMethodTest() Assert.AreEqual(true, tOut); Assert.AreEqual(4, tResult2); } + + [Test] + public void GenericStructInNullableContextTest() + { + var result = new + { + SomeOtherProperty = "test" + }.ActLike(); + } } } diff --git a/Tests/UnitTestImpromptuInterface/Support/SupportDefinitions.cs b/Tests/UnitTestImpromptuInterface/Support/SupportDefinitions.cs index 1dc5873..1db5fcd 100644 --- a/Tests/UnitTestImpromptuInterface/Support/SupportDefinitions.cs +++ b/Tests/UnitTestImpromptuInterface/Support/SupportDefinitions.cs @@ -102,11 +102,22 @@ public interface ISimpeleClassProps Guid Prop3 { get; } } + public class DisplayNamesAttribute : Attribute + { + public string[] DisplayNames { get; } + + public DisplayNamesAttribute(params string[] displayNames) + { + DisplayNames = displayNames; + } + } + public interface ISimpeleSetClassProps { [DisplayName("testDisplayName")] string Prop1 { set ; } + [DisplayNames("testDisplayName1", "testDisplayName2")] long Prop2 { set; } Guid Prop3 { set; } @@ -577,4 +588,27 @@ public bool IsFixedSize } } +#if NET6_0_OR_GREATER +#nullable enable +#endif + public struct GenericStruct + { + public string Something { get; } + + public GenericStruct(string something) + { + Something = something; + } + } + + public interface IInterfaceWithGenericStructProperty + { + GenericStruct StructProperty { get; } + + string SomeOtherProperty { get; } + } +#if NET6_0_OR_GREATER +#nullable restore +#endif + }