From cb0236f58101e1794cff88ea06ce2fd9f94c26a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Rab=C3=A9rin?= Date: Sun, 10 Jul 2022 15:04:27 +0200 Subject: [PATCH 01/15] Upgrade tests to netcoreapp3.1 (supported framework). --- .../ImmediateReflection.Tests.csproj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/ImmediateReflection.Tests/ImmediateReflection.Tests.csproj b/tests/ImmediateReflection.Tests/ImmediateReflection.Tests.csproj index 546f9ee..4e67a75 100644 --- a/tests/ImmediateReflection.Tests/ImmediateReflection.Tests.csproj +++ b/tests/ImmediateReflection.Tests/ImmediateReflection.Tests.csproj @@ -1,7 +1,7 @@  - net20;net30;net35;net40;net45;net451;net452;net46;net461;net462;net47;net471;net472;netcoreapp2.0 + net20;net30;net35;net40;net45;net451;net452;net46;net461;net462;net47;net471;net472;netcoreapp3.1 ImmediateReflection.Tests @@ -53,8 +53,8 @@ $(DefineConstants);NET472;SUPPORTS_SERIALIZATION;SUPPORTS_CACHING;SUPPORTS_EXTENSIONS;SUPPORTS_SYSTEM_CORE;SUPPORTS_IMMEDIATE_MEMBER_TYPE;$(AdditionalConstants) - - $(DefineConstants);NETCOREAPP2_0;SUPPORTS_SERIALIZATION;SUPPORTS_CACHING;SUPPORTS_EXTENSIONS;SUPPORTS_SYSTEM_CORE;SUPPORTS_IMMEDIATE_MEMBER_TYPE;$(AdditionalConstants) + + $(DefineConstants);NETCOREAPP3_1;SUPPORTS_SERIALIZATION;SUPPORTS_CACHING;SUPPORTS_EXTENSIONS;SUPPORTS_SYSTEM_CORE;SUPPORTS_IMMEDIATE_MEMBER_TYPE;$(AdditionalConstants) From 49edca51a06efff7ab4c86658b809802faba4bdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Rab=C3=A9rin?= Date: Sun, 10 Jul 2022 15:14:33 +0200 Subject: [PATCH 02/15] Add .NET Standard 2.1 target which allows to get rid of external dependencies. --- src/ImmediateReflection/ImmediateReflection.csproj | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/ImmediateReflection/ImmediateReflection.csproj b/src/ImmediateReflection/ImmediateReflection.csproj index 23f1418..2c769e6 100644 --- a/src/ImmediateReflection/ImmediateReflection.csproj +++ b/src/ImmediateReflection/ImmediateReflection.csproj @@ -1,7 +1,7 @@  - net20;net35;net40;net45;netstandard2.0 + net20;net35;net40;net45;netstandard2.0;netstandard2.1 $(Generate_ImmediateReflection) @@ -64,9 +64,13 @@ Misc: ImmediateReflection .NET Standard 2.0 $(DefineConstants);NETSTANDARD2_0;SUPPORTS_SERIALIZATION;SUPPORTS_AGGRESSIVE_INLINING;SUPPORTS_STRING_FULL_FEATURES;SUPPORTS_SYSTEM_CORE;SUPPORTS_CACHING;SUPPORTS_EXTENSIONS;SUPPORTS_LAZY;$(AdditionalConstants) + + ImmediateReflection .NET Standard 2.1 + $(DefineConstants);NETSTANDARD2_1;SUPPORTS_SERIALIZATION;SUPPORTS_AGGRESSIVE_INLINING;SUPPORTS_STRING_FULL_FEATURES;SUPPORTS_SYSTEM_CORE;SUPPORTS_CACHING;SUPPORTS_EXTENSIONS;SUPPORTS_LAZY;$(AdditionalConstants) + - + \ No newline at end of file From fbfcbb7234042071bfb3a174337d73788ced1769 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Rab=C3=A9rin?= Date: Sun, 10 Jul 2022 15:30:47 +0200 Subject: [PATCH 03/15] Update some external dependencies. --- .../ImmediateReflection.Benchmark.csproj | 2 +- src/Directory.Build.props | 2 +- tests/Directory.Build.props | 2 +- .../ImmediateReflection.Tests.csproj | 10 ++++------ 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/benchmarks/ImmediateReflection.Benchmark/ImmediateReflection.Benchmark.csproj b/benchmarks/ImmediateReflection.Benchmark/ImmediateReflection.Benchmark.csproj index 43ee82f..7cc1d10 100644 --- a/benchmarks/ImmediateReflection.Benchmark/ImmediateReflection.Benchmark.csproj +++ b/benchmarks/ImmediateReflection.Benchmark/ImmediateReflection.Benchmark.csproj @@ -29,7 +29,7 @@ - + diff --git a/src/Directory.Build.props b/src/Directory.Build.props index ad8b49f..7e20c9f 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -24,6 +24,6 @@ - + diff --git a/tests/Directory.Build.props b/tests/Directory.Build.props index 1dfd651..92d1a55 100644 --- a/tests/Directory.Build.props +++ b/tests/Directory.Build.props @@ -14,6 +14,6 @@ - + diff --git a/tests/ImmediateReflection.Tests/ImmediateReflection.Tests.csproj b/tests/ImmediateReflection.Tests/ImmediateReflection.Tests.csproj index 4e67a75..8d5ac75 100644 --- a/tests/ImmediateReflection.Tests/ImmediateReflection.Tests.csproj +++ b/tests/ImmediateReflection.Tests/ImmediateReflection.Tests.csproj @@ -58,19 +58,17 @@ - - - - - + + + - + From f86a01acb6fd26c00bd6a6d0ccd2dfde8235177e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Rab=C3=A9rin?= Date: Sun, 10 Jul 2022 16:25:22 +0200 Subject: [PATCH 04/15] DynamicMethod are defined in the ImmediateReflection module all the time. --- .../Delegates/DelegatesFactory.cs | 49 +++++++++---------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/src/ImmediateReflection/Delegates/DelegatesFactory.cs b/src/ImmediateReflection/Delegates/DelegatesFactory.cs index 59d0718..381261a 100644 --- a/src/ImmediateReflection/Delegates/DelegatesFactory.cs +++ b/src/ImmediateReflection/Delegates/DelegatesFactory.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Diagnostics; using System.Reflection; using System.Reflection.Emit; @@ -43,7 +43,7 @@ public static DefaultConstructorDelegate CreateDefaultConstructor([NotNull] Type // ReSharper disable once PossibleNullReferenceException, Justification: Type is an array so it must have an element type. return () => throw new MissingMethodException($"There is no default constructor for array of {type.GetElementType().Name}."); - DynamicMethod dynamicConstructor = CreateDynamicDefaultConstructor(type.Name, type); + DynamicMethod dynamicConstructor = CreateDynamicDefaultConstructor(type.Name); dynamicConstructor.InitLocals = true; ILGenerator generator = dynamicConstructor.GetILGenerator(); @@ -180,7 +180,7 @@ public static CopyConstructorDelegate CreateCopyConstructor([NotNull] Type type, if (constructor is null || constructor.GetParameters()[0].ParameterType != type) return other => throw new MissingMethodException($"Class {type.Name} does not contain any copy constructor."); - DynamicMethod dynamicConstructor = CreateDynamicCopyConstructor(type.Name, type); + DynamicMethod dynamicConstructor = CreateDynamicCopyConstructor(type.Name); dynamicConstructor.InitLocals = true; ILGenerator generator = dynamicConstructor.GetILGenerator(); @@ -354,48 +354,45 @@ public static SetterDelegate CreateSetter([NotNull] PropertyInfo propertyInfo, [ [Pure] [NotNull] - [ContractAnnotation("name:null => halt;owner:null => halt")] - private static DynamicMethod CreateDynamicMethod([NotNull] string name, [CanBeNull] Type returnType, [CanBeNull] Type[] parameterTypes, [NotNull] Type owner) + [ContractAnnotation("name:null => halt")] + private static DynamicMethod CreateDynamicMethod([NotNull] string name, [CanBeNull] Type returnType, [CanBeNull] Type[] parameterTypes) { Debug.Assert(name != null); - Debug.Assert(owner != null); - return owner.IsInterface - ? new DynamicMethod($"{DynamicMethodPrefix}{name}", returnType, parameterTypes, owner.Assembly.ManifestModule, true) - : new DynamicMethod($"{DynamicMethodPrefix}{name}", returnType, parameterTypes, owner, true); + return new DynamicMethod($"{DynamicMethodPrefix}{name}", returnType, parameterTypes, typeof(DelegatesFactory).Module, true); } [Pure] [NotNull] - [ContractAnnotation("name:null => halt;owner:null => halt")] + [ContractAnnotation("name:null => halt")] #if SUPPORTS_AGGRESSIVE_INLINING [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif - private static DynamicMethod CreateDynamicProcedure([NotNull] string name, [CanBeNull] Type[] parameterTypes, [NotNull] Type owner) + private static DynamicMethod CreateDynamicProcedure([NotNull] string name, [CanBeNull] Type[] parameterTypes) { - return CreateDynamicMethod(name, typeof(void), parameterTypes, owner); + return CreateDynamicMethod(name, typeof(void), parameterTypes); } [Pure] [NotNull] - [ContractAnnotation("name:null => halt;owner:null => halt")] + [ContractAnnotation("name:null => halt")] #if SUPPORTS_AGGRESSIVE_INLINING [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif - private static DynamicMethod CreateDynamicDefaultConstructor([NotNull] string name, [NotNull] Type owner) + private static DynamicMethod CreateDynamicDefaultConstructor([NotNull] string name) { - return CreateDynamicMethod($"Constructor_{name}", typeof(object), Type.EmptyTypes, owner); + return CreateDynamicMethod($"Constructor_{name}", typeof(object), Type.EmptyTypes); } [Pure] [NotNull] - [ContractAnnotation("name:null => halt;owner:null => halt")] + [ContractAnnotation("name:null => halt")] #if SUPPORTS_AGGRESSIVE_INLINING [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif - private static DynamicMethod CreateDynamicCopyConstructor([NotNull] string name, [NotNull] Type owner) + private static DynamicMethod CreateDynamicCopyConstructor([NotNull] string name) { - return CreateDynamicMethod($"CopyConstructor_{name}", typeof(object), new[] { typeof(object) }, owner); + return CreateDynamicMethod($"CopyConstructor_{name}", typeof(object), new[] { typeof(object) }); } /// @@ -419,13 +416,13 @@ private static Type GetOwnerType([NotNull] MemberInfo member) [Pure] [NotNull] - [ContractAnnotation("name:null => halt;owner:null => halt")] + [ContractAnnotation("name:null => halt")] #if SUPPORTS_AGGRESSIVE_INLINING [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif - private static DynamicMethod CreateDynamicGetter([NotNull] string name, [NotNull] Type owner) + private static DynamicMethod CreateDynamicGetter([NotNull] string name) { - return CreateDynamicMethod($"Get_{name}", typeof(object), new[] { typeof(object) }, owner); + return CreateDynamicMethod($"Get_{name}", typeof(object), new[] { typeof(object) }); } [Pure] @@ -437,18 +434,18 @@ private static DynamicMethod CreateDynamicGetter([NotNull] string name, [NotNull private static DynamicMethod CreateDynamicGetter([NotNull] MemberInfo member, [NotNull] out Type targetType) { targetType = GetOwnerType(member); - return CreateDynamicGetter(member.Name, targetType); + return CreateDynamicGetter(member.Name); } [Pure] [NotNull] - [ContractAnnotation("name:null => halt;owner:null => halt")] + [ContractAnnotation("name:null => halt")] #if SUPPORTS_AGGRESSIVE_INLINING [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif - private static DynamicMethod CreateDynamicSetter([NotNull] string name, [NotNull] Type owner) + private static DynamicMethod CreateDynamicSetter([NotNull] string name) { - return CreateDynamicProcedure($"Set_{name}", new[] { typeof(object), typeof(object) }, owner); + return CreateDynamicProcedure($"Set_{name}", new[] { typeof(object), typeof(object) }); } [Pure] @@ -460,7 +457,7 @@ private static DynamicMethod CreateDynamicSetter([NotNull] string name, [NotNull private static DynamicMethod CreateDynamicSetter([NotNull] MemberInfo member, [NotNull] out Type targetType) { targetType = GetOwnerType(member); - return CreateDynamicSetter(member.Name, targetType); + return CreateDynamicSetter(member.Name); } #endregion From e33b130069b7b87abd22bb3257af670bc79b8215 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Rab=C3=A9rin?= Date: Sun, 10 Jul 2022 18:51:46 +0200 Subject: [PATCH 05/15] Drop support of targets under .NET Framework 4.0. Those target are affected by inconcistencies compared to more recent ones. --- README.md | 9 +-------- docs/index.md | 7 +------ .../ImmediateReflection.csproj | 12 ++---------- .../ImmediateReflection.Tests.csproj | 19 ++----------------- 4 files changed, 6 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index 2ce141b..39f68af 100644 --- a/README.md +++ b/README.md @@ -297,17 +297,10 @@ ImmediateType myImmediateType = myType.GetImmediateType(); - [![.NET Standard](https://img.shields.io/badge/.NET%20Standard-%3E%3D%202.0-blue.svg)](#) - [![.NET Core](https://img.shields.io/badge/.NET%20Core-%3E%3D%202.0-blue.svg)](#) -- [![.NET Framework](https://img.shields.io/badge/.NET%20Framework-%3E%3D%202.0-blue.svg)](#) +- [![.NET Framework](https://img.shields.io/badge/.NET%20Framework-%3E%3D%204.0-blue.svg)](#) Supports Source Link ---- - -## Dependencies - -For targets higher than .NET Standard 2.0: -- System.Reflection.Emit.LightWeight - ### Notes - It uses NUnit3 for unit testing (not published). diff --git a/docs/index.md b/docs/index.md index 2e1e122..2e81fbc 100644 --- a/docs/index.md +++ b/docs/index.md @@ -27,15 +27,10 @@ You can find library sources on [GitHub](https://github.com/KeRNeLith/ImmediateR - .NET Standard 2.0+ - .NET Core 2.0+ -- .NET Framework 2.0+ +- .NET Framework 4.0+ Supports Source Link -## Dependencies - -For targets higher than .NET Standard 2.0: -- System.Reflection.Emit.LightWeight - ## Installation ImmediateReflection is available on [NuGet](https://www.nuget.org/packages/ImmediateReflection) diff --git a/src/ImmediateReflection/ImmediateReflection.csproj b/src/ImmediateReflection/ImmediateReflection.csproj index 2c769e6..9e6a014 100644 --- a/src/ImmediateReflection/ImmediateReflection.csproj +++ b/src/ImmediateReflection/ImmediateReflection.csproj @@ -1,7 +1,7 @@  - net20;net35;net40;net45;netstandard2.0;netstandard2.1 + net40;net45;netstandard2.0;netstandard2.1 $(Generate_ImmediateReflection) @@ -23,7 +23,7 @@ It provides these features while trying to keep an API as similar as the standar Supported platforms: - .NET Standard 2.0+ - .NET Core 2.0+ -- .NET Framework 2.0+ +- .NET Framework 4.0+ Supports Source Link @@ -44,14 +44,6 @@ Misc: - - ImmediateReflection .NET 2.0 - $(DefineConstants);NET20;SUPPORTS_SERIALIZATION;SUPPORTS_CACHING;$(AdditionalConstants) - - - ImmediateReflection .NET 3.5 - $(DefineConstants);NET35;SUPPORTS_SERIALIZATION;SUPPORTS_SYSTEM_CORE;SUPPORTS_CACHING;SUPPORTS_EXTENSIONS;$(AdditionalConstants) - ImmediateReflection .NET 4.0 $(DefineConstants);NET40;SUPPORTS_SERIALIZATION;SUPPORTS_STRING_FULL_FEATURES;SUPPORTS_SYSTEM_CORE;SUPPORTS_CACHING;SUPPORTS_EXTENSIONS;SUPPORTS_LAZY;$(AdditionalConstants) diff --git a/tests/ImmediateReflection.Tests/ImmediateReflection.Tests.csproj b/tests/ImmediateReflection.Tests/ImmediateReflection.Tests.csproj index 8d5ac75..5e0beee 100644 --- a/tests/ImmediateReflection.Tests/ImmediateReflection.Tests.csproj +++ b/tests/ImmediateReflection.Tests/ImmediateReflection.Tests.csproj @@ -1,7 +1,7 @@  - net20;net30;net35;net40;net45;net451;net452;net46;net461;net462;net47;net471;net472;netcoreapp3.1 + net40;net45;net451;net452;net46;net461;net462;net47;net471;net472;netcoreapp3.1 ImmediateReflection.Tests @@ -14,15 +14,6 @@ - - $(DefineConstants);NET20;SUPPORTS_SERIALIZATION;SUPPORTS_CACHING;$(AdditionalConstants) - - - $(DefineConstants);NET30;SUPPORTS_SERIALIZATION;SUPPORTS_CACHING;$(AdditionalConstants) - - - $(DefineConstants);NET35;SUPPORTS_SERIALIZATION;SUPPORTS_CACHING;SUPPORTS_EXTENSIONS;SUPPORTS_SYSTEM_CORE;$(AdditionalConstants) - $(DefineConstants);NET40;SUPPORTS_SERIALIZATION;SUPPORTS_CACHING;SUPPORTS_EXTENSIONS;SUPPORTS_SYSTEM_CORE;SUPPORTS_IMMEDIATE_MEMBER_TYPE;$(AdditionalConstants) @@ -58,17 +49,11 @@ - + - - - - - - From c8dd8b624065084226fdac3c584bb2c440c3b87e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Rab=C3=A9rin?= Date: Sun, 10 Jul 2022 19:15:09 +0200 Subject: [PATCH 06/15] Clean no more useful compilation defines (and related code). --- .../Cache/AttributesCache.cs | 16 +- .../Cache/CachesHandler.cs | 6 +- .../Cache/ConstructorData.cs | 8 +- src/ImmediateReflection/Cache/MemoryCache.cs | 12 +- .../Compatibility/Delegates.cs | 14 -- .../Compatibility/EnumerableUtils.cs | 200 ------------------ .../Compatibility/StringUtils.cs | 43 ---- .../ImmediateAttributesExtensions.cs | 34 +-- .../Extensions/ImmediateMemberExtensions.cs | 30 +-- .../ImmediateReflectionExtensions.cs | 16 +- .../Extensions/MemberExtensions.cs | 48 +---- .../Extensions/ObjectExtensions.cs | 24 +-- .../Extensions/TypeExtensions.cs | 58 +---- .../Helpers/FieldHelpers.cs | 10 +- src/ImmediateReflection/ImmediateField.cs | 13 +- src/ImmediateReflection/ImmediateFields.cs | 37 +--- src/ImmediateReflection/ImmediateMember.cs | 6 - .../ImmediateProperties.cs | 42 +--- src/ImmediateReflection/ImmediateProperty.cs | 13 +- .../ImmediateReflection.csproj | 8 +- src/ImmediateReflection/ImmediateType.cs | 40 ---- src/ImmediateReflection/TypeAccessor.cs | 65 +----- .../Compatibility/EnumerableUtilsTests.cs | 40 ---- .../ImmediateAttributesExtensionsTests.cs | 6 +- .../ImmediateMemberExtensionsTests.cs | 6 +- .../ImmediateReflectionExtensionsTests.cs | 4 +- .../Extensions/ObjectExtensionsTests.cs | 6 +- .../Extensions/TypeExtensionsTests.cs | 6 +- .../ImmediateFieldTests.cs | 4 +- .../ImmediatePropertyTests.cs | 4 +- .../ImmediateReflection.Tests.csproj | 22 +- .../TypeAccessorTests.cs | 4 +- 32 files changed, 65 insertions(+), 780 deletions(-) delete mode 100644 src/ImmediateReflection/Compatibility/Delegates.cs delete mode 100644 src/ImmediateReflection/Compatibility/EnumerableUtils.cs delete mode 100644 src/ImmediateReflection/Compatibility/StringUtils.cs delete mode 100644 tests/ImmediateReflection.Tests/Compatibility/EnumerableUtilsTests.cs diff --git a/src/ImmediateReflection/Cache/AttributesCache.cs b/src/ImmediateReflection/Cache/AttributesCache.cs index 6b64870..22330b8 100644 --- a/src/ImmediateReflection/Cache/AttributesCache.cs +++ b/src/ImmediateReflection/Cache/AttributesCache.cs @@ -1,11 +1,7 @@ -using System; +using System; using System.Collections.Generic; using System.Diagnostics; -#if SUPPORTS_SYSTEM_CORE using System.Linq; -#else -using static ImmediateReflection.Utils.EnumerableUtils; -#endif using System.Reflection; #if SUPPORTS_AGGRESSIVE_INLINING using System.Runtime.CompilerServices; @@ -17,7 +13,7 @@ namespace ImmediateReflection /// /// Cache storage for attributes. /// - internal class AttributesCache + internal sealed class AttributesCache { [NotNull, ItemNotNull] private readonly Attribute[] _attributesWithInherited; @@ -155,11 +151,7 @@ public IEnumerable GetAttributes(bool inherit) IEnumerable FindAttributes(Attribute[] attributes) { -#if SUPPORTS_SYSTEM_CORE return attributes.OfType(); -#else - return OfType(attributes); -#endif } #endregion @@ -189,11 +181,7 @@ public IEnumerable GetAttributes([NotNull] Type attributeType, bool i IEnumerable FindAttributes(Attribute[] attributes) { -#if SUPPORTS_SYSTEM_CORE return attributes.Where(attributeType.IsInstanceOfType); -#else - return Where(attributes, attributeType.IsInstanceOfType); -#endif } #endregion diff --git a/src/ImmediateReflection/Cache/CachesHandler.cs b/src/ImmediateReflection/Cache/CachesHandler.cs index 17f888d..d844f5e 100644 --- a/src/ImmediateReflection/Cache/CachesHandler.cs +++ b/src/ImmediateReflection/Cache/CachesHandler.cs @@ -1,5 +1,4 @@ -#if SUPPORTS_CACHING -using System; +using System; using System.Diagnostics; using System.Reflection; using JetBrains.Annotations; @@ -180,5 +179,4 @@ public ImmediateProperty GetProperty([NotNull] PropertyInfo property) #endregion } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/ImmediateReflection/Cache/ConstructorData.cs b/src/ImmediateReflection/Cache/ConstructorData.cs index 02ebf1c..82f0f75 100644 --- a/src/ImmediateReflection/Cache/ConstructorData.cs +++ b/src/ImmediateReflection/Cache/ConstructorData.cs @@ -1,5 +1,4 @@ -#if SUPPORTS_CACHING -using System.Diagnostics; +using System.Diagnostics; using JetBrains.Annotations; namespace ImmediateReflection @@ -8,7 +7,7 @@ namespace ImmediateReflection /// Data stored in a constructor cache. /// /// Constructor delegate type. - internal class ConstructorData + internal sealed class ConstructorData { /// /// Indicates if there is a constructor. @@ -29,5 +28,4 @@ public ConstructorData([NotNull] TConstructorDelegate constructor, bool hasConst Constructor = constructor; } } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/ImmediateReflection/Cache/MemoryCache.cs b/src/ImmediateReflection/Cache/MemoryCache.cs index be29e26..f5f2d57 100644 --- a/src/ImmediateReflection/Cache/MemoryCache.cs +++ b/src/ImmediateReflection/Cache/MemoryCache.cs @@ -1,9 +1,4 @@ -#if SUPPORTS_CACHING -#if SUPPORTS_SYSTEM_CORE -using System; -#else -using ImmediateReflection.Utils; -#endif +using System; using System.Collections; using System.Diagnostics; using JetBrains.Annotations; @@ -15,7 +10,7 @@ namespace ImmediateReflection /// /// Cache key type. /// Cache value type. - internal class MemoryCache + internal sealed class MemoryCache where TValue : class { [NotNull] @@ -53,5 +48,4 @@ public TValue GetOrCreate([NotNull] TKey key, [NotNull, InstantHandle] Func - /// Encapsulates a method that has no parameters and returns a value of the - /// type specified by the parameter. - /// - /// The type of the return value of the method that this delegate encapsulates. - /// The return value of the method that this delegate encapsulates. - internal delegate TResult Func(); -} - -#endif \ No newline at end of file diff --git a/src/ImmediateReflection/Compatibility/EnumerableUtils.cs b/src/ImmediateReflection/Compatibility/EnumerableUtils.cs deleted file mode 100644 index c8f9bab..0000000 --- a/src/ImmediateReflection/Compatibility/EnumerableUtils.cs +++ /dev/null @@ -1,200 +0,0 @@ -#if !SUPPORTS_SYSTEM_CORE -using System; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics; -using JetBrains.Annotations; - -namespace ImmediateReflection.Utils -{ - /// - /// Helper to replace Enumerable standard utilities when not available in target version. - /// - internal static class EnumerableUtils - { - // Delegates - internal delegate TOut Func(TIn param); - internal delegate bool Predicate(T param); - - /// - /// Select a set of values from given elements using the given . - /// - /// Element type. - /// Output element type. - /// Source enumerable. - /// Selector applied on each element. - /// Enumerable of selected elements. - [Pure] - [NotNull, ItemNotNull] - public static IEnumerable Select([NotNull, ItemNotNull] IEnumerable source, [NotNull, InstantHandle] Func selector) - { - Debug.Assert(source != null); - Debug.Assert(selector != null); - - foreach (TIn element in source) - { - yield return selector(element); - } - } - - /// - /// Gets a sub set enumerable of elements matching the given . - /// - /// Element type. - /// Source enumerable. - /// Predicate to check on each source element. - /// Enumerable of elements matching . - [Pure] - [NotNull, ItemNotNull] - public static IEnumerable Where([NotNull, ItemNotNull] IEnumerable source, [NotNull, InstantHandle] Predicate predicate) - { - Debug.Assert(source != null); - Debug.Assert(predicate != null); - - foreach (T element in source) - { - if (predicate(element)) - yield return element; - } - } - - /// - /// Gets a sub set enumerable of source elements cast to . - /// - /// Output element type. - /// Source enumerable. - /// Enumerable of elements cast to . - [Pure] - [NotNull, ItemNotNull] - public static IEnumerable OfType([NotNull, ItemNotNull] IEnumerable source) - { - Debug.Assert(source != null); - - foreach (object obj in source) - { - if (obj is TResult element) - yield return element; - } - } - - private static class EmptyEnumerable - { - [NotNull, ItemNotNull] - public static readonly TElement[] Instance = new TElement[0]; - } - - /// - /// Gets an empty enumerable of elements. - /// - /// Element type. - /// Empty enumerable. - [Pure] - [NotNull, ItemNotNull] - public static IEnumerable Empty() - { - return EmptyEnumerable.Instance; - } - - #region Buffer helper - - /// - /// Buffer of elements. - /// - /// Element type. - private struct Buffer - { - private readonly TElement[] _items; - private readonly int _count; - - internal Buffer([NotNull, ItemNotNull] IEnumerable source) - { - TElement[] items = null; - int count = 0; - if (source is ICollection collection) - { - count = collection.Count; - if (count > 0) - { - items = new TElement[count]; - collection.CopyTo(items, 0); - } - } - else - { - foreach (TElement item in source) - { - if (items is null) - { - items = new TElement[4]; - } - else if (items.Length == count) - { - var newItems = new TElement[checked(count * 2)]; - Array.Copy(items, 0, newItems, 0, count); - items = newItems; - } - - items[count] = item; - ++count; - } - } - - _items = items; - _count = count; - } - - internal TElement[] ToArray() - { - if (_count == 0) - return new TElement[0]; - - if (_items.Length == _count) - return _items; - - var result = new TElement[_count]; - Array.Copy(_items, 0, result, 0, _count); - return result; - } - } - - #endregion - - /// - /// Converts the given enumerable to an array. - /// - /// Element type. - /// Source enumerable. - /// Enumerable converted to array. - [Pure] - [NotNull, ItemNotNull] - public static T[] ToArray([NotNull, ItemNotNull] IEnumerable source) - { - Debug.Assert(source != null); - - return new Buffer(source).ToArray(); - } - - /// - /// Gets an enumerable of values excepting those in . - /// - /// Enumerable of values. - /// Enumerable of values to except. - /// Element type. - /// Source element that were not present in . - [Pure] - [NotNull, ItemNotNull] - public static IEnumerable Except([NotNull, ItemNotNull] IEnumerable first, [NotNull, ItemNotNull] IEnumerable second) - { - Debug.Assert(first != null); - Debug.Assert(second != null); - - var list = new List(second); - foreach (T source in first) - { - if (!list.Contains(source)) - yield return source; - } - } - } -} -#endif \ No newline at end of file diff --git a/src/ImmediateReflection/Compatibility/StringUtils.cs b/src/ImmediateReflection/Compatibility/StringUtils.cs deleted file mode 100644 index 5bd0eb7..0000000 --- a/src/ImmediateReflection/Compatibility/StringUtils.cs +++ /dev/null @@ -1,43 +0,0 @@ -#if !SUPPORTS_STRING_FULL_FEATURES -using System.Collections.Generic; -using System.Diagnostics; -using System.Text; -using JetBrains.Annotations; - -namespace ImmediateReflection.Utils -{ - /// - /// Helper to replace string standard utilities when not available in target version. - /// - internal static class StringUtils - { - /// - /// Concatenates collection members using the specified between each member. - /// - /// String to use as separator. It is included only if contains multiple values. - /// Enumerable of values to concatenate. - /// Element type. - /// String composed of elements from separated by . - [Pure] - [NotNull] - public static string Join([NotNull] string separator, [NotNull, ItemNotNull] IEnumerable values) - { - Debug.Assert(separator != null); - Debug.Assert(values != null); - - bool firstValue = true; - var stringBuilder = new StringBuilder(); - foreach (T value in values) - { - if (!firstValue) - stringBuilder.Append(separator); - firstValue = false; - - stringBuilder.Append(value); - } - - return stringBuilder.ToString(); - } - } -} -#endif \ No newline at end of file diff --git a/src/ImmediateReflection/Extensions/ImmediateAttributesExtensions.cs b/src/ImmediateReflection/Extensions/ImmediateAttributesExtensions.cs index 62671ce..32f76c4 100644 --- a/src/ImmediateReflection/Extensions/ImmediateAttributesExtensions.cs +++ b/src/ImmediateReflection/Extensions/ImmediateAttributesExtensions.cs @@ -1,5 +1,4 @@ -#if SUPPORTS_CACHING -using System; +using System; using System.Collections.Generic; using System.Reflection; #if SUPPORTS_AGGRESSIVE_INLINING @@ -29,11 +28,7 @@ public static class ImmediateAttributesExtensions [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif public static bool IsDefinedImmediateAttribute( -#if SUPPORTS_EXTENSIONS [NotNull] this MemberInfo member, -#else - [NotNull] MemberInfo member, -#endif bool inherit = false) where TAttribute : Attribute { @@ -61,11 +56,7 @@ public static bool IsDefinedImmediateAttribute( [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif public static bool IsDefinedImmediateAttribute( -#if SUPPORTS_EXTENSIONS [NotNull] this MemberInfo member, -#else - [NotNull] MemberInfo member, -#endif [NotNull] Type attributeType, bool inherit = false) { @@ -92,11 +83,7 @@ public static bool IsDefinedImmediateAttribute( [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif public static TAttribute GetImmediateAttribute( -#if SUPPORTS_EXTENSIONS [NotNull] this MemberInfo member, -#else - [NotNull] MemberInfo member, -#endif bool inherit = false) where TAttribute : Attribute { @@ -124,11 +111,7 @@ public static TAttribute GetImmediateAttribute( [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif public static Attribute GetImmediateAttribute( -#if SUPPORTS_EXTENSIONS [NotNull] this MemberInfo member, -#else - [NotNull] MemberInfo member, -#endif [NotNull] Type attributeType, bool inherit = false) { @@ -155,11 +138,7 @@ public static Attribute GetImmediateAttribute( [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif public static IEnumerable GetImmediateAttributes( -#if SUPPORTS_EXTENSIONS [NotNull] this MemberInfo member, -#else - [NotNull] MemberInfo member, -#endif bool inherit = false) where TAttribute : Attribute { @@ -186,11 +165,7 @@ public static IEnumerable GetImmediateAttributes( [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif public static IEnumerable GetImmediateAttributes( -#if SUPPORTS_EXTENSIONS [NotNull] this MemberInfo member, -#else - [NotNull] MemberInfo member, -#endif [NotNull] Type attributeType, bool inherit = false) { @@ -216,11 +191,7 @@ public static IEnumerable GetImmediateAttributes( [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif public static IEnumerable GetAllImmediateAttributes( -#if SUPPORTS_EXTENSIONS [NotNull] this MemberInfo member, -#else - [NotNull] MemberInfo member, -# endif bool inherit = false) { if (member is null) @@ -231,5 +202,4 @@ public static IEnumerable GetAllImmediateAttributes( .GetAllAttributes(inherit); } } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/ImmediateReflection/Extensions/ImmediateMemberExtensions.cs b/src/ImmediateReflection/Extensions/ImmediateMemberExtensions.cs index 1104af9..f6769f7 100644 --- a/src/ImmediateReflection/Extensions/ImmediateMemberExtensions.cs +++ b/src/ImmediateReflection/Extensions/ImmediateMemberExtensions.cs @@ -1,5 +1,4 @@ -#if SUPPORTS_EXTENSIONS -using System; +using System; using System.Collections.Generic; using System.Reflection; #if SUPPORTS_AGGRESSIVE_INLINING @@ -25,9 +24,6 @@ public static class ImmediateMemberExtensions /// The corresponding , otherwise null. /// If the given or is null. [PublicAPI] -#if !SUPPORTS_CACHING - [Pure] -#endif [CanBeNull] [ContractAnnotation("type:null => halt;fieldName:null => halt")] #if SUPPORTS_AGGRESSIVE_INLINING @@ -47,9 +43,6 @@ public static ImmediateField GetImmediateField([NotNull] this Type type, [NotNul /// The corresponding , otherwise null. /// If the given or is null. [PublicAPI] -#if !SUPPORTS_CACHING - [Pure] -#endif [CanBeNull] [ContractAnnotation("type:null => halt;fieldName:null => halt")] #if SUPPORTS_AGGRESSIVE_INLINING @@ -67,9 +60,6 @@ public static ImmediateField GetImmediateField([NotNull] this Type type, [NotNul /// All . /// If the given is null. [PublicAPI] -#if !SUPPORTS_CACHING - [Pure] -#endif [NotNull, ItemNotNull] [ContractAnnotation("type:null => halt")] #if SUPPORTS_AGGRESSIVE_INLINING @@ -88,9 +78,6 @@ public static IEnumerable GetImmediateFields([NotNull] this Type /// All . /// If the given is null. [PublicAPI] -#if !SUPPORTS_CACHING - [Pure] -#endif [NotNull, ItemNotNull] [ContractAnnotation("type:null => halt")] #if SUPPORTS_AGGRESSIVE_INLINING @@ -113,9 +100,6 @@ public static IEnumerable GetImmediateFields([NotNull] this Type /// The corresponding , otherwise null. /// If the given or is null. [PublicAPI] -#if !SUPPORTS_CACHING - [Pure] -#endif [CanBeNull] [ContractAnnotation("type:null => halt;propertyName:null => halt")] #if SUPPORTS_AGGRESSIVE_INLINING @@ -135,9 +119,6 @@ public static ImmediateProperty GetImmediateProperty([NotNull] this Type type, [ /// The corresponding , otherwise null. /// If the given or is null. [PublicAPI] -#if !SUPPORTS_CACHING - [Pure] -#endif [CanBeNull] [ContractAnnotation("type:null => halt;propertyName:null => halt")] #if SUPPORTS_AGGRESSIVE_INLINING @@ -155,9 +136,6 @@ public static ImmediateProperty GetImmediateProperty([NotNull] this Type type, [ /// All . /// If the given is null. [PublicAPI] -#if !SUPPORTS_CACHING - [Pure] -#endif [NotNull, ItemNotNull] [ContractAnnotation("type:null => halt")] #if SUPPORTS_AGGRESSIVE_INLINING @@ -176,9 +154,6 @@ public static IEnumerable GetImmediateProperties([NotNull] th /// All . /// If the given is null. [PublicAPI] -#if !SUPPORTS_CACHING - [Pure] -#endif [NotNull, ItemNotNull] [ContractAnnotation("type:null => halt")] #if SUPPORTS_AGGRESSIVE_INLINING @@ -191,5 +166,4 @@ public static IEnumerable GetImmediateProperties([NotNull] th #endregion } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/ImmediateReflection/Extensions/ImmediateReflectionExtensions.cs b/src/ImmediateReflection/Extensions/ImmediateReflectionExtensions.cs index d98d3e2..01ea235 100644 --- a/src/ImmediateReflection/Extensions/ImmediateReflectionExtensions.cs +++ b/src/ImmediateReflection/Extensions/ImmediateReflectionExtensions.cs @@ -20,28 +20,18 @@ public static class ImmediateReflectionExtensions /// The corresponding . /// If the given is null. [PublicAPI] -#if !SUPPORTS_CACHING - [Pure] -#endif [NotNull] [ContractAnnotation("obj:null => halt")] #if SUPPORTS_AGGRESSIVE_INLINING [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif - public static ImmediateType GetImmediateType( -#if SUPPORTS_EXTENSIONS - [NotNull] this T obj -#else - [NotNull] T obj -#endif - ) + public static ImmediateType GetImmediateType([NotNull] this T obj) { if (obj == null) throw new ArgumentNullException(nameof(obj)); return TypeAccessor.Get(obj.GetType()); } -#if SUPPORTS_EXTENSIONS /// /// Gets the corresponding to this . /// @@ -49,9 +39,6 @@ [NotNull] T obj /// The corresponding . /// If the given is null. [PublicAPI] -#if !SUPPORTS_CACHING - [Pure] -#endif [NotNull] [ContractAnnotation("type:null => halt")] #if SUPPORTS_AGGRESSIVE_INLINING @@ -61,6 +48,5 @@ public static ImmediateType GetImmediateType([NotNull] this Type type) { return TypeAccessor.Get(type); } -#endif } } \ No newline at end of file diff --git a/src/ImmediateReflection/Extensions/MemberExtensions.cs b/src/ImmediateReflection/Extensions/MemberExtensions.cs index 9226aa6..a2eb393 100644 --- a/src/ImmediateReflection/Extensions/MemberExtensions.cs +++ b/src/ImmediateReflection/Extensions/MemberExtensions.cs @@ -74,11 +74,7 @@ private static bool TryCreateGetterInternal([NotNull] Propert [Pure] [ContractAnnotation("property:null => halt;=> true, getter:notnull;=> false, getter:null")] public static bool TryCreateGetter( -#if SUPPORTS_EXTENSIONS [NotNull] this PropertyInfo property, -#else - [NotNull] PropertyInfo property, -#endif out GetterDelegate getter) { getter = null; @@ -110,13 +106,7 @@ public static bool TryCreateGetter( [Pure] [NotNull] [ContractAnnotation("property:null => halt")] - public static GetterDelegate CreateGetter( -#if SUPPORTS_EXTENSIONS - [NotNull] this PropertyInfo property -#else - [NotNull] PropertyInfo property -#endif - ) + public static GetterDelegate CreateGetter([NotNull] this PropertyInfo property) { if (TryCreateGetterInternal(property, out GetterDelegate getter)) return getter; @@ -209,11 +199,7 @@ private static bool TryCreateGetterInternal([NotNull] PropertyInfo prope [Pure] [ContractAnnotation("property:null => halt;=> true, getter:notnull;=> false, getter:null")] public static bool TryCreateGetter( -#if SUPPORTS_EXTENSIONS [NotNull] this PropertyInfo property, -#else - [NotNull] PropertyInfo property, -#endif out GetterDelegate getter) { getter = null; @@ -244,13 +230,7 @@ public static bool TryCreateGetter( [Pure] [NotNull] [ContractAnnotation("property:null => halt")] - public static GetterDelegate CreateGetter( -#if SUPPORTS_EXTENSIONS - [NotNull] this PropertyInfo property -#else - [NotNull] PropertyInfo property -#endif - ) + public static GetterDelegate CreateGetter([NotNull] this PropertyInfo property) { if (TryCreateGetterInternal(property, out GetterDelegate getter)) return getter; @@ -316,11 +296,7 @@ private static bool TryCreateSetterInternal([NotNull] Propert [Pure] [ContractAnnotation("property:null => halt;=> true, setter:notnull;=> false, setter:null")] public static bool TryCreateSetter( -#if SUPPORTS_EXTENSIONS [NotNull] this PropertyInfo property, -#else - [NotNull] PropertyInfo property, -#endif out SetterDelegate setter) where TOwner : class { @@ -353,13 +329,7 @@ public static bool TryCreateSetter( [Pure] [NotNull] [ContractAnnotation("property:null => halt")] - public static SetterDelegate CreateSetter( -#if SUPPORTS_EXTENSIONS - [NotNull] this PropertyInfo property -#else - [NotNull] PropertyInfo property -#endif - ) + public static SetterDelegate CreateSetter([NotNull] this PropertyInfo property) where TOwner : class { if (TryCreateSetterInternal(property, out SetterDelegate setter)) @@ -447,11 +417,7 @@ private static bool TryCreateSetterInternal([NotNull] PropertyInfo prope [Pure] [ContractAnnotation("property:null => halt;=> true, setter:notnull;=> false, setter:null")] public static bool TryCreateSetter( -#if SUPPORTS_EXTENSIONS [NotNull] this PropertyInfo property, -#else - [NotNull] PropertyInfo property, -#endif out SetterDelegate setter) where TOwner : class { @@ -483,13 +449,7 @@ public static bool TryCreateSetter( [Pure] [NotNull] [ContractAnnotation("property:null => halt")] - public static SetterDelegate CreateSetter( -#if SUPPORTS_EXTENSIONS - [NotNull] this PropertyInfo property -#else - [NotNull] PropertyInfo property -#endif - ) + public static SetterDelegate CreateSetter([NotNull] this PropertyInfo property) where TOwner : class { if (TryCreateSetterInternal(property, out SetterDelegate setter)) diff --git a/src/ImmediateReflection/Extensions/ObjectExtensions.cs b/src/ImmediateReflection/Extensions/ObjectExtensions.cs index 04603e8..2e37663 100644 --- a/src/ImmediateReflection/Extensions/ObjectExtensions.cs +++ b/src/ImmediateReflection/Extensions/ObjectExtensions.cs @@ -1,5 +1,4 @@ -#if SUPPORTS_CACHING -using System; +using System; using JetBrains.Annotations; namespace ImmediateReflection @@ -19,12 +18,7 @@ public static class ObjectExtensions /// If the given is null. [PublicAPI] [ContractAnnotation("instance:null => halt")] - public static bool HasCopyConstructor( -#if SUPPORTS_EXTENSIONS - [NotNull] this T instance) -#else - [NotNull] T instance) -#endif + public static bool HasCopyConstructor([NotNull] this T instance) { if (instance == null) throw new ArgumentNullException(nameof(instance)); @@ -46,12 +40,7 @@ public static bool HasCopyConstructor( /// [PublicAPI] [ContractAnnotation("instance:null => null;instance:notnull => notnull")] - public static T Copy( -#if SUPPORTS_EXTENSIONS - [CanBeNull] this T instance) -#else - [CanBeNull] T instance) -#endif + public static T Copy([CanBeNull] this T instance) { if (instance == null) return default(T); @@ -76,11 +65,7 @@ public static T Copy( + "instance:null => false, newInstance:null, exception:notnull;" + "instance:notnull => false, newInstance:null, exception:notnull")] public static bool TryCopy( -#if SUPPORTS_EXTENSIONS [CanBeNull] this T instance, -#else - [CanBeNull] T instance, -#endif out T newInstance, out Exception exception) { @@ -98,5 +83,4 @@ public static bool TryCopy( } } } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/ImmediateReflection/Extensions/TypeExtensions.cs b/src/ImmediateReflection/Extensions/TypeExtensions.cs index 19adb8d..6d82b9a 100644 --- a/src/ImmediateReflection/Extensions/TypeExtensions.cs +++ b/src/ImmediateReflection/Extensions/TypeExtensions.cs @@ -1,6 +1,4 @@ -#if SUPPORTS_CACHING -using System; -using System.Reflection; +using System; #if SUPPORTS_AGGRESSIVE_INLINING using System.Runtime.CompilerServices; #endif @@ -22,12 +20,7 @@ public static class TypeExtensions /// If the given is null. [PublicAPI] [ContractAnnotation("type:null => halt")] - public static bool HasDefaultConstructor( -#if SUPPORTS_EXTENSIONS - [NotNull] this Type type) -#else - [NotNull] Type type) -#endif + public static bool HasDefaultConstructor([NotNull] this Type type) { if (type is null) throw new ArgumentNullException(nameof(type)); @@ -46,12 +39,7 @@ public static bool HasDefaultConstructor( [PublicAPI] [NotNull] [ContractAnnotation("type:null => halt")] - public static object New( -#if SUPPORTS_EXTENSIONS - [NotNull] this Type type) -#else - [NotNull] Type type) -#endif + public static object New([NotNull] this Type type) { if (type is null) throw new ArgumentNullException(nameof(type)); @@ -70,12 +58,8 @@ public static object New( [PublicAPI] [ContractAnnotation("=> true, newInstance:notnull, exception:null;=> false, newInstance:null, exception:notnull")] public static bool TryNew( -#if SUPPORTS_EXTENSIONS [NotNull] this Type type, -#else - [NotNull] Type type, -#endif - out object newInstance, + out object newInstance, out Exception exception) { if (type is null) @@ -124,11 +108,7 @@ public static bool TryNew( [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif public static object New( -#if SUPPORTS_EXTENSIONS [NotNull] this Type type, -#else - [NotNull] Type type, -#endif [NotNull, ItemCanBeNull] params object[] args) { if (type is null) @@ -160,13 +140,9 @@ public static object New( [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif public static bool TryNew( -#if SUPPORTS_EXTENSIONS [NotNull] this Type type, -#else - [NotNull] Type type, -#endif - out object newInstance, - out Exception exception, + out object newInstance, + out Exception exception, [NotNull, ItemCanBeNull] params object[] args) { if (type is null) @@ -184,12 +160,7 @@ public static bool TryNew( /// If the given is null. [PublicAPI] [ContractAnnotation("type:null => halt")] - public static bool HasCopyConstructor( -#if SUPPORTS_EXTENSIONS - [NotNull] this Type type) -#else - [NotNull] Type type) -#endif + public static bool HasCopyConstructor([NotNull] this Type type) { if (type is null) throw new ArgumentNullException(nameof(type)); @@ -225,13 +196,7 @@ private static T CopyInternal([NotNull] Type type, [CanBeNull] T instance) /// [PublicAPI] [ContractAnnotation("type:null => halt; other:null => null; other:notnull => notnull")] - public static T Copy( -#if SUPPORTS_EXTENSIONS - [NotNull] this Type type, -#else - [NotNull] Type type, -#endif - [CanBeNull] T other) + public static T Copy([NotNull] this Type type, [CanBeNull] T other) { if (type is null) throw new ArgumentNullException(nameof(type)); @@ -256,11 +221,7 @@ public static T Copy( + "other:null => false, newInstance:null, exception:notnull;" + "other:notnull => false, newInstance:null, exception:notnull")] public static bool TryCopy( -#if SUPPORTS_EXTENSIONS [NotNull] this Type type, -#else - [NotNull] Type type, -#endif [CanBeNull] T other, out T newInstance, out Exception exception) @@ -282,5 +243,4 @@ public static bool TryCopy( } } } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/ImmediateReflection/Helpers/FieldHelpers.cs b/src/ImmediateReflection/Helpers/FieldHelpers.cs index 02eb4a9..954f55b 100644 --- a/src/ImmediateReflection/Helpers/FieldHelpers.cs +++ b/src/ImmediateReflection/Helpers/FieldHelpers.cs @@ -1,10 +1,6 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Diagnostics; -#if SUPPORTS_SYSTEM_CORE using System.Linq; -#else -using static ImmediateReflection.Utils.EnumerableUtils; -#endif using System.Reflection; using JetBrains.Annotations; @@ -44,11 +40,7 @@ internal static IEnumerable IgnoreBackingFields([NotNull, ItemNotNull { Debug.Assert(fields != null); -#if SUPPORTS_SYSTEM_CORE return fields.Where(field => !IsBackingField(field)); -#else - return Where(fields, field => !IsBackingField(field)); -#endif } } } \ No newline at end of file diff --git a/src/ImmediateReflection/ImmediateField.cs b/src/ImmediateReflection/ImmediateField.cs index 2092175..fc0583a 100644 --- a/src/ImmediateReflection/ImmediateField.cs +++ b/src/ImmediateReflection/ImmediateField.cs @@ -1,9 +1,7 @@ using System; using System.Reflection; -#if SUPPORTS_SERIALIZATION using System.Runtime.Serialization; using System.Security.Permissions; -#endif using JetBrains.Annotations; namespace ImmediateReflection @@ -12,15 +10,11 @@ namespace ImmediateReflection /// Represents a field and provides access to its metadata in a faster way. /// [PublicAPI] -#if SUPPORTS_SERIALIZATION [Serializable] -#endif public sealed class ImmediateField : ImmediateMember , IEquatable -#if SUPPORTS_SERIALIZATION , ISerializable -#endif { /// /// Gets the wrapped . @@ -43,7 +37,6 @@ public sealed class ImmediateField [NotNull] public Type FieldType { get; } -#if SUPPORTS_LAZY [NotNull] private readonly Lazy _fieldImmediateType; @@ -53,7 +46,6 @@ public sealed class ImmediateField [PublicAPI] [NotNull] public ImmediateType FieldImmediateType => _fieldImmediateType.Value; -#endif [NotNull] private readonly GetterDelegate _getter; @@ -70,9 +62,8 @@ internal ImmediateField([NotNull] FieldInfo field) { FieldInfo = field; FieldType = field.FieldType; -#if SUPPORTS_LAZY _fieldImmediateType = new Lazy(() => TypeAccessor.Get(FieldType)); -#endif + // ReSharper disable once AssignNullToNotNullAttribute, Justification: A field is always declared inside a type. DeclaringType = field.DeclaringType; @@ -175,7 +166,6 @@ public override int GetHashCode() #endregion -#if SUPPORTS_SERIALIZATION #region ISerializable private ImmediateField(SerializationInfo info, StreamingContext context) @@ -191,7 +181,6 @@ void ISerializable.GetObjectData(SerializationInfo info, StreamingContext contex } #endregion -#endif /// public override string ToString() diff --git a/src/ImmediateReflection/ImmediateFields.cs b/src/ImmediateReflection/ImmediateFields.cs index 1ff073e..15222c7 100644 --- a/src/ImmediateReflection/ImmediateFields.cs +++ b/src/ImmediateReflection/ImmediateFields.cs @@ -1,25 +1,15 @@ -using System; +using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; -#if SUPPORTS_SYSTEM_CORE using System.Linq; -#endif using System.Reflection; #if SUPPORTS_AGGRESSIVE_INLINING using System.Runtime.CompilerServices; #endif -#if SUPPORTS_SERIALIZATION using System.Runtime.Serialization; using System.Security.Permissions; -#endif using JetBrains.Annotations; -#if !SUPPORTS_SYSTEM_CORE -using static ImmediateReflection.Utils.EnumerableUtils; -#endif -#if !SUPPORTS_STRING_FULL_FEATURES -using static ImmediateReflection.Utils.StringUtils; -#endif namespace ImmediateReflection { @@ -27,15 +17,11 @@ namespace ImmediateReflection /// Represents a collection of fields and provides access to its metadata in a faster way. /// [PublicAPI] -#if SUPPORTS_SERIALIZATION [Serializable] -#endif public sealed class ImmediateFields : IEnumerable , IEquatable -#if SUPPORTS_SERIALIZATION , ISerializable -#endif { [NotNull] private readonly Dictionary _fields @@ -58,11 +44,7 @@ private void Init([NotNull, ItemNotNull] IEnumerable fields) { Debug.Assert(field != null); -#if SUPPORTS_CACHING _fields.Add(field.Name, CachesHandler.Instance.GetField(field)); -#else - _fields.Add(field.Name, new ImmediateField(field)); -#endif } } @@ -111,14 +93,7 @@ public bool Equals(ImmediateFields other) return true; if (_fields.Count != other._fields.Count) return false; - -#if SUPPORTS_SYSTEM_CORE return !_fields.Except(other._fields).Any(); -#else - return !Except(_fields, other._fields) - .GetEnumerator() - .MoveNext(); -#endif } /// @@ -156,7 +131,6 @@ public IEnumerator GetEnumerator() #endregion -#if SUPPORTS_SERIALIZATION #region ISerializable private ImmediateFields(SerializationInfo info, StreamingContext context) @@ -184,27 +158,18 @@ void ISerializable.GetObjectData(SerializationInfo info, StreamingContext contex info.AddValue("Count", _fields.Count); int i = -1; -#if SUPPORTS_SYSTEM_CORE foreach (FieldInfo field in _fields.Select(pair => pair.Value.FieldInfo)) -#else - foreach (FieldInfo field in Select(_fields, pair => pair.Value.FieldInfo)) -#endif { info.AddValue($"Field{++i}", field); } } #endregion -#endif /// public override string ToString() { -#if SUPPORTS_STRING_FULL_FEATURES return $"[{string.Join(", ", _fields.Values)}]"; -#else - return $"[{Join(", ", _fields.Values)}]"; -#endif } } } \ No newline at end of file diff --git a/src/ImmediateReflection/ImmediateMember.cs b/src/ImmediateReflection/ImmediateMember.cs index f726ee4..c5acade 100644 --- a/src/ImmediateReflection/ImmediateMember.cs +++ b/src/ImmediateReflection/ImmediateMember.cs @@ -13,9 +13,7 @@ namespace ImmediateReflection /// Represents information about the attributes of a member or and provides access to its metadata in a faster way. /// [PublicAPI] -#if SUPPORTS_SERIALIZATION [Serializable] -#endif public abstract class ImmediateMember { /// @@ -39,11 +37,7 @@ protected ImmediateMember([NotNull] MemberInfo member) Name = member.Name; // Attributes -#if SUPPORTS_CACHING _attributeCache = CachesHandler.Instance.GetAttributesCache(member); -#else - _attributeCache = new AttributesCache(member); -#endif } /// diff --git a/src/ImmediateReflection/ImmediateProperties.cs b/src/ImmediateReflection/ImmediateProperties.cs index 0dedce2..563418e 100644 --- a/src/ImmediateReflection/ImmediateProperties.cs +++ b/src/ImmediateReflection/ImmediateProperties.cs @@ -2,25 +2,15 @@ using System.Collections; using System.Collections.Generic; using System.Diagnostics; -#if SUPPORTS_SYSTEM_CORE using System.Linq; -#endif using System.Reflection; #if SUPPORTS_AGGRESSIVE_INLINING using System.Runtime.CompilerServices; #endif -#if SUPPORTS_SERIALIZATION using System.Runtime.Serialization; using System.Security.Permissions; -#endif using JetBrains.Annotations; -#if !SUPPORTS_SYSTEM_CORE -using static ImmediateReflection.Utils.EnumerableUtils; -#endif using static ImmediateReflection.Utils.ReflectionHelpers; -#if !SUPPORTS_STRING_FULL_FEATURES -using static ImmediateReflection.Utils.StringUtils; -#endif namespace ImmediateReflection { @@ -28,15 +18,11 @@ namespace ImmediateReflection /// Represents a collection of properties and provides access to property metadata in a faster way. /// [PublicAPI] -#if SUPPORTS_SERIALIZATION [Serializable] -#endif public sealed class ImmediateProperties : IEnumerable , IEquatable -#if SUPPORTS_SERIALIZATION , ISerializable -#endif { [NotNull] private readonly Dictionary _properties @@ -55,18 +41,9 @@ private void Init([NotNull, ItemNotNull] IEnumerable properties) { Debug.Assert(properties != null); -#if SUPPORTS_SYSTEM_CORE foreach (PropertyInfo property in properties.Where(IsNotIndexed)) -#else - foreach (PropertyInfo property in Where(properties, IsNotIndexed)) -#endif { - var currentImmediateProperty = -#if SUPPORTS_CACHING - CachesHandler.Instance.GetProperty(property); -#else - new ImmediateProperty(property); -#endif + ImmediateProperty currentImmediateProperty = CachesHandler.Instance.GetProperty(property); if (_properties.TryGetValue(property.Name, out ImmediateProperty immediateProperty)) { @@ -159,14 +136,7 @@ public bool Equals(ImmediateProperties other) return true; if (_properties.Count != other._properties.Count) return false; - -#if SUPPORTS_SYSTEM_CORE return !_properties.Except(other._properties).Any(); -#else - return !Except(_properties, other._properties) - .GetEnumerator() - .MoveNext(); -#endif } /// @@ -204,7 +174,6 @@ public IEnumerator GetEnumerator() #endregion -#if SUPPORTS_SERIALIZATION #region ISerializable private ImmediateProperties(SerializationInfo info, StreamingContext context) @@ -232,27 +201,18 @@ void ISerializable.GetObjectData(SerializationInfo info, StreamingContext contex info.AddValue("Count", _properties.Count); int i = -1; -#if SUPPORTS_SYSTEM_CORE foreach (PropertyInfo property in _properties.Select(pair => pair.Value.PropertyInfo)) -#else - foreach (PropertyInfo property in Select(_properties, pair => pair.Value.PropertyInfo)) -#endif { info.AddValue($"Property{++i}", property); } } #endregion -#endif /// public override string ToString() { -#if SUPPORTS_STRING_FULL_FEATURES return $"[{string.Join(", ", _properties.Values)}]"; -#else - return $"[{Join(", ", _properties.Values)}]"; -#endif } } } \ No newline at end of file diff --git a/src/ImmediateReflection/ImmediateProperty.cs b/src/ImmediateReflection/ImmediateProperty.cs index 5c360a8..a779998 100644 --- a/src/ImmediateReflection/ImmediateProperty.cs +++ b/src/ImmediateReflection/ImmediateProperty.cs @@ -1,10 +1,8 @@ using System; using System.Diagnostics; using System.Reflection; -#if SUPPORTS_SERIALIZATION using System.Runtime.Serialization; using System.Security.Permissions; -#endif using JetBrains.Annotations; using static ImmediateReflection.Utils.ReflectionHelpers; @@ -14,15 +12,11 @@ namespace ImmediateReflection /// Represents a property and provides access to property metadata in a faster way. /// [PublicAPI] -#if SUPPORTS_SERIALIZATION [Serializable] -#endif public sealed class ImmediateProperty : ImmediateMember , IEquatable -#if SUPPORTS_SERIALIZATION , ISerializable -#endif { /// /// Gets the wrapped . @@ -45,7 +39,6 @@ public sealed class ImmediateProperty [NotNull] public Type PropertyType { get; } -#if SUPPORTS_LAZY [NotNull] private readonly Lazy _propertyImmediateType; @@ -55,7 +48,6 @@ public sealed class ImmediateProperty [PublicAPI] [NotNull] public ImmediateType PropertyImmediateType => _propertyImmediateType.Value; -#endif /// /// Gets the readable state of this property. @@ -87,9 +79,8 @@ internal ImmediateProperty([NotNull] PropertyInfo property) // General property info PropertyInfo = property; PropertyType = property.PropertyType; -#if SUPPORTS_LAZY _propertyImmediateType = new Lazy(() => TypeAccessor.Get(PropertyType)); -#endif + // ReSharper disable once AssignNullToNotNullAttribute, Justification: A property is always declared inside a type. DeclaringType = property.DeclaringType; @@ -186,7 +177,6 @@ public override int GetHashCode() #endregion -#if SUPPORTS_SERIALIZATION #region ISerializable private ImmediateProperty(SerializationInfo info, StreamingContext context) @@ -202,7 +192,6 @@ void ISerializable.GetObjectData(SerializationInfo info, StreamingContext contex } #endregion -#endif /// public override string ToString() diff --git a/src/ImmediateReflection/ImmediateReflection.csproj b/src/ImmediateReflection/ImmediateReflection.csproj index 9e6a014..d1dcecf 100644 --- a/src/ImmediateReflection/ImmediateReflection.csproj +++ b/src/ImmediateReflection/ImmediateReflection.csproj @@ -46,19 +46,19 @@ Misc: ImmediateReflection .NET 4.0 - $(DefineConstants);NET40;SUPPORTS_SERIALIZATION;SUPPORTS_STRING_FULL_FEATURES;SUPPORTS_SYSTEM_CORE;SUPPORTS_CACHING;SUPPORTS_EXTENSIONS;SUPPORTS_LAZY;$(AdditionalConstants) + $(DefineConstants);NET40;$(AdditionalConstants) ImmediateReflection .NET 4.5 - $(DefineConstants);NET45;SUPPORTS_SERIALIZATION;SUPPORTS_AGGRESSIVE_INLINING;SUPPORTS_STRING_FULL_FEATURES;SUPPORTS_SYSTEM_CORE;SUPPORTS_CACHING;SUPPORTS_EXTENSIONS;SUPPORTS_LAZY;$(AdditionalConstants) + $(DefineConstants);NET45;SUPPORTS_AGGRESSIVE_INLINING;$(AdditionalConstants) ImmediateReflection .NET Standard 2.0 - $(DefineConstants);NETSTANDARD2_0;SUPPORTS_SERIALIZATION;SUPPORTS_AGGRESSIVE_INLINING;SUPPORTS_STRING_FULL_FEATURES;SUPPORTS_SYSTEM_CORE;SUPPORTS_CACHING;SUPPORTS_EXTENSIONS;SUPPORTS_LAZY;$(AdditionalConstants) + $(DefineConstants);NETSTANDARD2_0;SUPPORTS_AGGRESSIVE_INLINING;$(AdditionalConstants) ImmediateReflection .NET Standard 2.1 - $(DefineConstants);NETSTANDARD2_1;SUPPORTS_SERIALIZATION;SUPPORTS_AGGRESSIVE_INLINING;SUPPORTS_STRING_FULL_FEATURES;SUPPORTS_SYSTEM_CORE;SUPPORTS_CACHING;SUPPORTS_EXTENSIONS;SUPPORTS_LAZY;$(AdditionalConstants) + $(DefineConstants);NETSTANDARD2_1;SUPPORTS_AGGRESSIVE_INLINING;$(AdditionalConstants) diff --git a/src/ImmediateReflection/ImmediateType.cs b/src/ImmediateReflection/ImmediateType.cs index cd2d319..ca9f490 100644 --- a/src/ImmediateReflection/ImmediateType.cs +++ b/src/ImmediateReflection/ImmediateType.cs @@ -1,18 +1,12 @@ using System; using System.Collections.Generic; -#if SUPPORTS_SYSTEM_CORE using System.Linq; -#else -using static ImmediateReflection.Utils.EnumerableUtils; -#endif using System.Reflection; #if SUPPORTS_AGGRESSIVE_INLINING using System.Runtime.CompilerServices; #endif -#if SUPPORTS_SERIALIZATION using System.Runtime.Serialization; using System.Security.Permissions; -#endif using JetBrains.Annotations; using static ImmediateReflection.Utils.FieldHelpers; @@ -23,15 +17,11 @@ namespace ImmediateReflection /// type parameters, generic type definitions, and open or closed constructed generic types) in a faster way. /// [PublicAPI] -#if SUPPORTS_SERIALIZATION [Serializable] -#endif public sealed class ImmediateType : ImmediateMember , IEquatable -#if SUPPORTS_SERIALIZATION , ISerializable -#endif { private BindingFlags _flags; @@ -82,21 +72,15 @@ public IEnumerable Members } } -#if SUPPORTS_LAZY [NotNull] private readonly Lazy _fields; -#endif /// /// Gets all the fields of this . /// [PublicAPI] [NotNull, ItemNotNull] -#if SUPPORTS_LAZY public ImmediateFields Fields => _fields.Value; -#else - public ImmediateFields Fields { get; } -#endif /// /// Gets all the properties of this . @@ -120,46 +104,24 @@ internal ImmediateType([NotNull] Type type, BindingFlags flags = TypeAccessor.De FullName = type.FullName ?? Name; // Default constructor -#if SUPPORTS_CACHING ConstructorData defaultCtorData = CachesHandler.Instance.GetDefaultConstructor(Type); _constructor = defaultCtorData.Constructor; HasDefaultConstructor = defaultCtorData.HasConstructor; -#else - _constructor = DelegatesFactory.CreateDefaultConstructor(Type, out bool hasConstructor); - HasDefaultConstructor = hasConstructor; -#endif // Copy constructor -#if SUPPORTS_CACHING ConstructorData copyCtorData = CachesHandler.Instance.GetCopyConstructor(Type); _copyConstructor = copyCtorData.Constructor; HasCopyConstructor = copyCtorData.HasConstructor; -#else - _copyConstructor = DelegatesFactory.CreateCopyConstructor(Type, out bool hasConstructor); - HasCopyConstructor = hasConstructor; -#endif if (type.IsEnum) { -#if SUPPORTS_LAZY _fields = new Lazy(() => new ImmediateFields(type.GetFields())); -#else - Fields = new ImmediateFields(type.GetFields()); -#endif -#if SUPPORTS_SYSTEM_CORE Properties = new ImmediateProperties(Enumerable.Empty()); -#else - Properties = new ImmediateProperties(Empty()); -#endif } else { -#if SUPPORTS_LAZY _fields = new Lazy(() => new ImmediateFields(IgnoreBackingFields(type.GetFields(_flags)))); -#else - Fields = new ImmediateFields(IgnoreBackingFields(type.GetFields(_flags))); -#endif Properties = new ImmediateProperties(type.GetProperties(_flags)); } @@ -474,7 +436,6 @@ public override int GetHashCode() #endregion -#if SUPPORTS_SERIALIZATION #region ISerializable private ImmediateType(SerializationInfo info, StreamingContext context) @@ -491,7 +452,6 @@ void ISerializable.GetObjectData(SerializationInfo info, StreamingContext contex } #endregion -#endif /// public override string ToString() diff --git a/src/ImmediateReflection/TypeAccessor.cs b/src/ImmediateReflection/TypeAccessor.cs index 6c68318..d394548 100644 --- a/src/ImmediateReflection/TypeAccessor.cs +++ b/src/ImmediateReflection/TypeAccessor.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Reflection; #if SUPPORTS_AGGRESSIVE_INLINING using System.Runtime.CompilerServices; @@ -16,21 +16,12 @@ public static class TypeAccessor { internal const BindingFlags DefaultFlags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static; -#if SUPPORTS_CACHING /// /// Provides an access to a Reflection information via an . /// It gives access to all public instance members. /// /// Returned is cached within the library. /// to get a corresponding . -#else - /// - /// Provides an access to a Reflection information via an . - /// It gives access to all public instance members. - /// - /// to get a corresponding . - [Pure] -#endif [PublicAPI] [NotNull] #if SUPPORTS_AGGRESSIVE_INLINING @@ -41,7 +32,6 @@ public static ImmediateType Get() return Get(typeof(T)); } -#if SUPPORTS_CACHING /// /// Provides an access to a Reflection information via an . /// It gives access to all public instance members. @@ -49,15 +39,6 @@ public static ImmediateType Get() /// Returned is cached within the library. /// to get a corresponding . /// If the given is null. -#else - /// - /// Provides an access to a Reflection information via an . - /// It gives access to all public instance members. - /// - /// to get a corresponding . - /// If the given is null. - [Pure] -#endif [PublicAPI] [NotNull] [ContractAnnotation("type:null => halt")] @@ -69,7 +50,6 @@ public static ImmediateType Get([NotNull] Type type) return Get(type, DefaultFlags); } -#if SUPPORTS_CACHING /// /// Provides an access to a Reflection information via an . /// If is set to true it gives access to all public and not public instance members. @@ -77,15 +57,6 @@ public static ImmediateType Get([NotNull] Type type) /// Returned is cached within the library. /// to get a corresponding . /// Indicates if non public members should be taken into account. -#else - /// - /// Provides an access to a Reflection information via an . - /// If is set to true it gives access to all public and not public instance members. - /// - /// to get a corresponding . - /// Indicates if non public members should be taken into account. - [Pure] -#endif [PublicAPI] [NotNull] #if SUPPORTS_AGGRESSIVE_INLINING @@ -96,7 +67,6 @@ public static ImmediateType Get(bool includeNonPublicMembers) return Get(typeof(T), includeNonPublicMembers); } -#if SUPPORTS_CACHING /// /// Provides an access to a Reflection information via an . /// If is set to true it gives access to all public and not public instance members. @@ -105,16 +75,6 @@ public static ImmediateType Get(bool includeNonPublicMembers) /// to get a corresponding . /// Indicates if non public members should be taken into account. /// If the given is null. -#else - /// - /// Provides an access to a Reflection information via an . - /// If is set to true it gives access to all public and not public instance members. - /// - /// to get a corresponding . - /// Indicates if non public members should be taken into account. - /// If the given is null. - [Pure] -#endif [PublicAPI] [NotNull] [ContractAnnotation("type:null => halt")] @@ -128,21 +88,12 @@ public static ImmediateType Get([NotNull] Type type, bool includeNonPublicMember : Get(type, DefaultFlags | BindingFlags.NonPublic); } -#if SUPPORTS_CACHING /// /// Provides an access to a Reflection information via an . /// /// Returned is cached within the library. /// to get a corresponding . /// Flags that must be taken into account to get members. -#else - /// - /// Provides an access to a Reflection information via an . - /// - /// to get a corresponding . - /// Flags that must be taken into account to get members. - [Pure] -#endif [PublicAPI] [NotNull] #if SUPPORTS_AGGRESSIVE_INLINING @@ -153,7 +104,6 @@ public static ImmediateType Get(BindingFlags flags) return Get(typeof(T), flags); } -#if SUPPORTS_CACHING /// /// Provides an access to a Reflection information via an . /// @@ -161,15 +111,6 @@ public static ImmediateType Get(BindingFlags flags) /// to get a corresponding . /// Flags that must be taken into account to get members. /// If the given is null. -#else - /// - /// Provides an access to a Reflection information via an . - /// - /// to get a corresponding . - /// Flags that must be taken into account to get members. - /// If the given is null. - [Pure] -#endif [PublicAPI] [NotNull] [ContractAnnotation("type:null => halt")] @@ -178,11 +119,7 @@ public static ImmediateType Get([NotNull] Type type, BindingFlags flags) if (type is null) throw new ArgumentNullException(nameof(type)); -#if SUPPORTS_CACHING return CachesHandler.Instance.GetImmediateType(type, flags); -#else - return new ImmediateType(type, flags); -#endif } } } \ No newline at end of file diff --git a/tests/ImmediateReflection.Tests/Compatibility/EnumerableUtilsTests.cs b/tests/ImmediateReflection.Tests/Compatibility/EnumerableUtilsTests.cs deleted file mode 100644 index fc6ed82..0000000 --- a/tests/ImmediateReflection.Tests/Compatibility/EnumerableUtilsTests.cs +++ /dev/null @@ -1,40 +0,0 @@ -#if !SUPPORTS_SYSTEM_CORE -using System.Collections.Generic; -using NUnit.Framework; -using ImmediateReflection.Utils; - -namespace ImmediateReflection.Tests -{ - /// - /// Tests related to . - /// - [TestFixture] - internal class EnumerableUtilsTests - { - private static IEnumerable GetInts() - { - yield return 4; - yield return 5; - yield return 6; - yield return 7; - yield return 8; - yield return 9; - yield return 10; - } - - [Test] - public void ToArray() - { - // ReSharper disable once CollectionNeverUpdated.Local - var emptyList = new List(); - var list = new List { 1, 2, 3, 4 }; - - CollectionAssert.AreEqual(new int[] { }, EnumerableUtils.ToArray(emptyList)); - CollectionAssert.AreEqual(new [] { 1, 2, 3, 4 }, EnumerableUtils.ToArray(list)); - - CollectionAssert.AreEqual(new int[] { }, EnumerableUtils.ToArray(EnumerableUtils.Empty())); - CollectionAssert.AreEqual(new[] { 4, 5, 6, 7, 8, 9, 10 }, EnumerableUtils.ToArray(GetInts())); - } - } -} -#endif \ No newline at end of file diff --git a/tests/ImmediateReflection.Tests/Extensions/ImmediateAttributesExtensionsTests.cs b/tests/ImmediateReflection.Tests/Extensions/ImmediateAttributesExtensionsTests.cs index 9195b5f..c26a7ba 100644 --- a/tests/ImmediateReflection.Tests/Extensions/ImmediateAttributesExtensionsTests.cs +++ b/tests/ImmediateReflection.Tests/Extensions/ImmediateAttributesExtensionsTests.cs @@ -1,5 +1,4 @@ -#if SUPPORTS_CACHING -using System; +using System; using System.Collections.Generic; using System.Reflection; using JetBrains.Annotations; @@ -1434,5 +1433,4 @@ public void GetAllAttributes_Throws_NullMember() // ReSharper restore ReturnValueOfPureMethodIsNotUsed } } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/tests/ImmediateReflection.Tests/Extensions/ImmediateMemberExtensionsTests.cs b/tests/ImmediateReflection.Tests/Extensions/ImmediateMemberExtensionsTests.cs index 75f3856..8816818 100644 --- a/tests/ImmediateReflection.Tests/Extensions/ImmediateMemberExtensionsTests.cs +++ b/tests/ImmediateReflection.Tests/Extensions/ImmediateMemberExtensionsTests.cs @@ -1,5 +1,4 @@ -#if SUPPORTS_EXTENSIONS -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Reflection; @@ -158,5 +157,4 @@ public void GetImmediatePropertyFromType_Throws() // ReSharper restore ReturnValueOfPureMethodIsNotUsed } } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/tests/ImmediateReflection.Tests/Extensions/ImmediateReflectionExtensionsTests.cs b/tests/ImmediateReflection.Tests/Extensions/ImmediateReflectionExtensionsTests.cs index 0f8f0b0..2bbf862 100644 --- a/tests/ImmediateReflection.Tests/Extensions/ImmediateReflectionExtensionsTests.cs +++ b/tests/ImmediateReflection.Tests/Extensions/ImmediateReflectionExtensionsTests.cs @@ -1,4 +1,4 @@ -using System; +using System; using NUnit.Framework; namespace ImmediateReflection.Tests @@ -39,7 +39,6 @@ public void GetImmediateTypeFromObject_Throws() Assert.Throws(() => ImmediateReflectionExtensions.GetImmediateType(testObject)); } -#if SUPPORTS_EXTENSIONS [Test] public void GetImmediateTypeFromType() { @@ -69,6 +68,5 @@ public void GetImmediateTypeFromType_Throws() // ReSharper disable once AssignNullToNotNullAttribute Assert.Throws(() => testType.GetImmediateType()); } -#endif } } \ No newline at end of file diff --git a/tests/ImmediateReflection.Tests/Extensions/ObjectExtensionsTests.cs b/tests/ImmediateReflection.Tests/Extensions/ObjectExtensionsTests.cs index a0769d8..4348ede 100644 --- a/tests/ImmediateReflection.Tests/Extensions/ObjectExtensionsTests.cs +++ b/tests/ImmediateReflection.Tests/Extensions/ObjectExtensionsTests.cs @@ -1,5 +1,4 @@ -#if SUPPORTS_CACHING -using System; +using System; using System.Collections.Generic; using JetBrains.Annotations; using NUnit.Framework; @@ -135,5 +134,4 @@ public void TryCopy([NotNull] Type type, [CanBeNull] object other, bool expectFa #endregion } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/tests/ImmediateReflection.Tests/Extensions/TypeExtensionsTests.cs b/tests/ImmediateReflection.Tests/Extensions/TypeExtensionsTests.cs index 12f30de..094a6fe 100644 --- a/tests/ImmediateReflection.Tests/Extensions/TypeExtensionsTests.cs +++ b/tests/ImmediateReflection.Tests/Extensions/TypeExtensionsTests.cs @@ -1,5 +1,4 @@ -#if SUPPORTS_CACHING -using System; +using System; using System.Collections.Generic; using System.Reflection; using JetBrains.Annotations; @@ -236,5 +235,4 @@ public void TryCopy_Throws() #endregion } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/tests/ImmediateReflection.Tests/ImmediateFieldTests.cs b/tests/ImmediateReflection.Tests/ImmediateFieldTests.cs index d7fd432..095c604 100644 --- a/tests/ImmediateReflection.Tests/ImmediateFieldTests.cs +++ b/tests/ImmediateReflection.Tests/ImmediateFieldTests.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Reflection; using JetBrains.Annotations; @@ -59,7 +59,6 @@ public void ImmediateFieldInfo() Assert.AreEqual(TestEnumULongFieldValueFieldInfo, currentEnumValueImmediateField.FieldInfo); } -#if SUPPORTS_IMMEDIATE_MEMBER_TYPE #region FieldType [Test] @@ -85,7 +84,6 @@ void CheckFieldImmediateType(ImmediateField field) } #endregion -#endif #region GetValue diff --git a/tests/ImmediateReflection.Tests/ImmediatePropertyTests.cs b/tests/ImmediateReflection.Tests/ImmediatePropertyTests.cs index 7cbe398..bfd1312 100644 --- a/tests/ImmediateReflection.Tests/ImmediatePropertyTests.cs +++ b/tests/ImmediateReflection.Tests/ImmediatePropertyTests.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Reflection; using JetBrains.Annotations; @@ -61,7 +61,6 @@ public void ImmediatePropertyInfo() Assert.AreEqual(propertyInfoOfAnonymousType, immediatePropertyOfAnonymousType.PropertyInfo); } -#if SUPPORTS_IMMEDIATE_MEMBER_TYPE #region PropertyImmediateType [Test] @@ -87,7 +86,6 @@ void CheckPropertyImmediateType(ImmediateProperty property) } #endregion -#endif #region CanRead diff --git a/tests/ImmediateReflection.Tests/ImmediateReflection.Tests.csproj b/tests/ImmediateReflection.Tests/ImmediateReflection.Tests.csproj index 5e0beee..c0c1ae3 100644 --- a/tests/ImmediateReflection.Tests/ImmediateReflection.Tests.csproj +++ b/tests/ImmediateReflection.Tests/ImmediateReflection.Tests.csproj @@ -15,37 +15,37 @@ - $(DefineConstants);NET40;SUPPORTS_SERIALIZATION;SUPPORTS_CACHING;SUPPORTS_EXTENSIONS;SUPPORTS_SYSTEM_CORE;SUPPORTS_IMMEDIATE_MEMBER_TYPE;$(AdditionalConstants) + $(DefineConstants);NET40;SUPPORTS_SERIALIZATION;$(AdditionalConstants) - $(DefineConstants);NET45;SUPPORTS_SERIALIZATION;SUPPORTS_CACHING;SUPPORTS_EXTENSIONS;SUPPORTS_SYSTEM_CORE;SUPPORTS_IMMEDIATE_MEMBER_TYPE;$(AdditionalConstants) + $(DefineConstants);NET45;SUPPORTS_SERIALIZATION;$(AdditionalConstants) - $(DefineConstants);NET451;SUPPORTS_SERIALIZATION;SUPPORTS_CACHING;SUPPORTS_EXTENSIONS;SUPPORTS_SYSTEM_CORE;SUPPORTS_IMMEDIATE_MEMBER_TYPE;$(AdditionalConstants) + $(DefineConstants);NET451;SUPPORTS_SERIALIZATION;$(AdditionalConstants) - $(DefineConstants);NET452;SUPPORTS_SERIALIZATION;SUPPORTS_CACHING;SUPPORTS_EXTENSIONS;SUPPORTS_SYSTEM_CORE;SUPPORTS_IMMEDIATE_MEMBER_TYPE;$(AdditionalConstants) + $(DefineConstants);NET452;SUPPORTS_SERIALIZATION;$(AdditionalConstants) - $(DefineConstants);NET46;SUPPORTS_SERIALIZATION;SUPPORTS_CACHING;SUPPORTS_EXTENSIONS;SUPPORTS_SYSTEM_CORE;SUPPORTS_IMMEDIATE_MEMBER_TYPE;$(AdditionalConstants) + $(DefineConstants);NET46;SUPPORTS_SERIALIZATION;$(AdditionalConstants) - $(DefineConstants);NET461;SUPPORTS_SERIALIZATION;SUPPORTS_CACHING;SUPPORTS_EXTENSIONS;SUPPORTS_SYSTEM_CORE;SUPPORTS_IMMEDIATE_MEMBER_TYPE;$(AdditionalConstants) + $(DefineConstants);NET461;SUPPORTS_SERIALIZATION;$(AdditionalConstants) - $(DefineConstants);NET462;SUPPORTS_SERIALIZATION;SUPPORTS_CACHING;SUPPORTS_EXTENSIONS;SUPPORTS_SYSTEM_CORE;SUPPORTS_IMMEDIATE_MEMBER_TYPE;$(AdditionalConstants) + $(DefineConstants);NET462;SUPPORTS_SERIALIZATION;$(AdditionalConstants) - $(DefineConstants);NET47;SUPPORTS_SERIALIZATION;SUPPORTS_CACHING;SUPPORTS_EXTENSIONS;SUPPORTS_SYSTEM_CORE;SUPPORTS_IMMEDIATE_MEMBER_TYPE;$(AdditionalConstants) + $(DefineConstants);NET47;SUPPORTS_SERIALIZATION;$(AdditionalConstants) - $(DefineConstants);NET471;SUPPORTS_SERIALIZATION;SUPPORTS_CACHING;SUPPORTS_EXTENSIONS;SUPPORTS_SYSTEM_CORE;SUPPORTS_IMMEDIATE_MEMBER_TYPE;$(AdditionalConstants) + $(DefineConstants);NET471;SUPPORTS_SERIALIZATION;$(AdditionalConstants) - $(DefineConstants);NET472;SUPPORTS_SERIALIZATION;SUPPORTS_CACHING;SUPPORTS_EXTENSIONS;SUPPORTS_SYSTEM_CORE;SUPPORTS_IMMEDIATE_MEMBER_TYPE;$(AdditionalConstants) + $(DefineConstants);NET472;SUPPORTS_SERIALIZATION;$(AdditionalConstants) - $(DefineConstants);NETCOREAPP3_1;SUPPORTS_SERIALIZATION;SUPPORTS_CACHING;SUPPORTS_EXTENSIONS;SUPPORTS_SYSTEM_CORE;SUPPORTS_IMMEDIATE_MEMBER_TYPE;$(AdditionalConstants) + $(DefineConstants);NETCOREAPP3_1;$(AdditionalConstants) diff --git a/tests/ImmediateReflection.Tests/TypeAccessorTests.cs b/tests/ImmediateReflection.Tests/TypeAccessorTests.cs index 104192e..f644b3d 100644 --- a/tests/ImmediateReflection.Tests/TypeAccessorTests.cs +++ b/tests/ImmediateReflection.Tests/TypeAccessorTests.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Linq; using System.Reflection; using NUnit.Framework; @@ -118,7 +118,6 @@ public void Get_NullType() // ReSharper restore AssignNullToNotNullAttribute } -#if SUPPORTS_CACHING [Test] public void GetCached() { @@ -130,6 +129,5 @@ public void GetCached() Assert.AreSame(immediateType1, immediateType2); } -#endif } } \ No newline at end of file From d9d3e8f91fa3e9ffc528b8926baf40b1e435148e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Rab=C3=A9rin?= Date: Sun, 10 Jul 2022 14:22:32 +0200 Subject: [PATCH 07/15] Update CI packages to latest. --- appveyor.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index c0d2424..1c4ed99 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -27,10 +27,10 @@ skip_commits: environment: SONARQUBE_TOKEN: secure: IDwa0NHtLUrg2jV3JZetUqUCGTgv3/UcZyYtMGvo7Pro1s9OmYTPjGMd6Vmx7Ktx - DocFXVersion: 2.58 - NUnitConsoleVersion: 3.10.0 - OpenCoverVersion: 4.7.922 - CoverallsVersion: 1.0.0 + DocFXVersion: 2.59.2 + NUnitConsoleVersion: 3.15.2 + OpenCoverVersion: 4.7.1221 + CoverallsVersion: 3.0.0 COVERALLS_REPO_TOKEN: secure: +DiJ+F7GIX0MMo/rtIRXO8GSdyYHa1CWKLw4H2Rx3AP27Shr6mZMC6l+muu2H/Dg GITHUB_ACCESS_TOKEN: From 97a329499d98d7267c08fe17ad2ee1ae4a542171 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Rab=C3=A9rin?= Date: Sun, 10 Jul 2022 19:39:29 +0200 Subject: [PATCH 08/15] Fix R# warnings. --- tests/ImmediateReflection.Tests/ConstructorTestHelpers.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ImmediateReflection.Tests/ConstructorTestHelpers.cs b/tests/ImmediateReflection.Tests/ConstructorTestHelpers.cs index e1bc52e..4918955 100644 --- a/tests/ImmediateReflection.Tests/ConstructorTestHelpers.cs +++ b/tests/ImmediateReflection.Tests/ConstructorTestHelpers.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using JetBrains.Annotations; @@ -1226,7 +1226,7 @@ public static IEnumerable CreateCopyConstructorNoThrowTestCases } } - public delegate bool TryCopyCtor(object other, out object instance, out Exception exception); + public delegate bool TryCopyCtor([CanBeNull] object other, [CanBeNull] out object instance, [CanBeNull] out Exception exception); public static void TryCopy([NotNull] Type type, [CanBeNull] object other, bool expectFail, [NotNull, InstantHandle] TryCopyCtor tryCtor) { From 297bb77461acf79fab40508a3b6422c8cac8ad88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Rab=C3=A9rin?= Date: Sun, 10 Jul 2022 21:07:31 +0200 Subject: [PATCH 09/15] Only run tests for .NET Framework 4.6.1 due to timeout on results upload. --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 1c4ed99..c79d2f9 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -119,7 +119,7 @@ test_script: # Directory.Parent.Parent = tests\TestProject.Tests\bin # Directory.Parent.Parent.Parent = tests\TestProject.Tests - $testAssemblies = (ls tests\*.Tests\bin\$env:Configuration\*\*Tests.dll | Where-Object { $_ -Match "net*" -and $_ -NotMatch "netcoreapp*" -and [System.IO.Path]::GetFileNameWithoutExtension($_.FullName) -Match $_.Directory.Parent.Parent.Parent.Name } | % FullName | sort-object -Unique); + $testAssemblies = (ls tests\*.Tests\bin\$env:Configuration\net461\*Tests.dll | Where-Object { $_ -Match "net*" -and $_ -NotMatch "netcoreapp*" -and [System.IO.Path]::GetFileNameWithoutExtension($_.FullName) -Match $_.Directory.Parent.Parent.Parent.Name } | % FullName | sort-object -Unique); $testsPassed = $false; if ($env:IsFullIntegrationBuild -eq $true) From f7e1f997a3b6d1a522a22c29453f6c815d6625ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Rab=C3=A9rin?= Date: Sun, 10 Jul 2022 22:15:26 +0200 Subject: [PATCH 10/15] Fix SonarQube issues. --- .../Delegates/DelegatesFactory.cs | 68 +++++++++---------- .../Extensions/TypeExtensions.cs | 66 +++++++++--------- 2 files changed, 67 insertions(+), 67 deletions(-) diff --git a/src/ImmediateReflection/Delegates/DelegatesFactory.cs b/src/ImmediateReflection/Delegates/DelegatesFactory.cs index 381261a..c525585 100644 --- a/src/ImmediateReflection/Delegates/DelegatesFactory.cs +++ b/src/ImmediateReflection/Delegates/DelegatesFactory.cs @@ -222,7 +222,7 @@ void CheckParameterIsOfRightType() #endregion - #region Field Get/Set + #region Getter [Pure] [NotNull] @@ -251,6 +251,39 @@ public static GetterDelegate CreateGetter([NotNull] FieldInfo fieldInfo) return (GetterDelegate)dynamicGetter.CreateDelegate(typeof(GetterDelegate)); } + [Pure] + [CanBeNull] + [ContractAnnotation("propertyInfo:null => halt;getMethod:null => halt")] + public static GetterDelegate CreateGetter([NotNull] PropertyInfo propertyInfo, [NotNull] MethodInfo getMethod) + { + Debug.Assert(propertyInfo != null); + + if (!propertyInfo.CanRead) + return null; + + Debug.Assert(getMethod != null); + + DynamicMethod dynamicGetter = CreateDynamicGetter(propertyInfo, out Type targetType); + + ILGenerator generator = dynamicGetter.GetILGenerator(); + + if (!getMethod.IsStatic) + RegisterTargetArgument(generator, targetType); + + CallMethod(generator, getMethod); + + // Box the result if needed + BoxIfNeeded(generator, propertyInfo.PropertyType); + + MethodReturn(generator); + + return (GetterDelegate)dynamicGetter.CreateDelegate(typeof(GetterDelegate)); + } + + #endregion + + #region Setter + [Pure] [NotNull] [ContractAnnotation("fieldInfo:null => halt")] @@ -281,39 +314,6 @@ public static SetterDelegate CreateSetter([NotNull] FieldInfo fieldInfo) return (SetterDelegate)dynamicSetter.CreateDelegate(typeof(SetterDelegate)); } - #endregion - - #region Property Get/Set - - [Pure] - [CanBeNull] - [ContractAnnotation("propertyInfo:null => halt;getMethod:null => halt")] - public static GetterDelegate CreateGetter([NotNull] PropertyInfo propertyInfo, [NotNull] MethodInfo getMethod) - { - Debug.Assert(propertyInfo != null); - - if (!propertyInfo.CanRead) - return null; - - Debug.Assert(getMethod != null); - - DynamicMethod dynamicGetter = CreateDynamicGetter(propertyInfo, out Type targetType); - - ILGenerator generator = dynamicGetter.GetILGenerator(); - - if (!getMethod.IsStatic) - RegisterTargetArgument(generator, targetType); - - CallMethod(generator, getMethod); - - // Box the result if needed - BoxIfNeeded(generator, propertyInfo.PropertyType); - - MethodReturn(generator); - - return (GetterDelegate)dynamicGetter.CreateDelegate(typeof(GetterDelegate)); - } - [Pure] [CanBeNull] [ContractAnnotation("propertyInfo:null => halt;setMethod:null => halt")] diff --git a/src/ImmediateReflection/Extensions/TypeExtensions.cs b/src/ImmediateReflection/Extensions/TypeExtensions.cs index 6d82b9a..bd5f9b0 100644 --- a/src/ImmediateReflection/Extensions/TypeExtensions.cs +++ b/src/ImmediateReflection/Extensions/TypeExtensions.cs @@ -46,39 +46,6 @@ public static object New([NotNull] this Type type) return CachesHandler.Instance.GetDefaultConstructor(type).Constructor(); } - /// - /// Tries to create an instance of this with that type's default constructor. - /// - /// This method will not throw if instantiation failed. - /// to instantiate. - /// A reference to the newly created object, otherwise null. - /// Caught exception if the instantiation failed, otherwise null. - /// True if the new instance was successfully created, false otherwise. - /// If the given is null. - [PublicAPI] - [ContractAnnotation("=> true, newInstance:notnull, exception:null;=> false, newInstance:null, exception:notnull")] - public static bool TryNew( - [NotNull] this Type type, - out object newInstance, - out Exception exception) - { - if (type is null) - throw new ArgumentNullException(nameof(type)); - - try - { - exception = null; - newInstance = CachesHandler.Instance.GetDefaultConstructor(type).Constructor(); - return true; - } - catch (Exception ex) - { - newInstance = null; - exception = ex; - return false; - } - } - /// /// Creates an instance of this using the constructor that best matches the specified parameters. /// @@ -118,6 +85,39 @@ public static object New( return TypeAccessor.Get(type).New(args); } + /// + /// Tries to create an instance of this with that type's default constructor. + /// + /// This method will not throw if instantiation failed. + /// to instantiate. + /// A reference to the newly created object, otherwise null. + /// Caught exception if the instantiation failed, otherwise null. + /// True if the new instance was successfully created, false otherwise. + /// If the given is null. + [PublicAPI] + [ContractAnnotation("=> true, newInstance:notnull, exception:null;=> false, newInstance:null, exception:notnull")] + public static bool TryNew( + [NotNull] this Type type, + out object newInstance, + out Exception exception) + { + if (type is null) + throw new ArgumentNullException(nameof(type)); + + try + { + exception = null; + newInstance = CachesHandler.Instance.GetDefaultConstructor(type).Constructor(); + return true; + } + catch (Exception ex) + { + newInstance = null; + exception = ex; + return false; + } + } + /// /// Tries to create an instance of this with the best matching constructor. /// From 919a92b04006033402beaaefb7e9b574a93f23f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Rab=C3=A9rin?= Date: Mon, 11 Jul 2022 00:50:18 +0200 Subject: [PATCH 11/15] Update CI to use Visual Studio 2022 image. --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index c79d2f9..0ecd33c 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,5 +1,5 @@ version: '0.0.{build}' -image: Visual Studio 2019 +image: Visual Studio 2022 # Setup environment nuget: From b08a6a38ed432c41e2a19a5193d335ac6bfe517a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Rab=C3=A9rin?= Date: Mon, 11 Jul 2022 01:02:20 +0200 Subject: [PATCH 12/15] Add new targets for unit tests. NET Framework 4.8 and NET 5.0 --- .../ImmediateReflection.Tests.csproj | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/ImmediateReflection.Tests/ImmediateReflection.Tests.csproj b/tests/ImmediateReflection.Tests/ImmediateReflection.Tests.csproj index c0c1ae3..070b2f0 100644 --- a/tests/ImmediateReflection.Tests/ImmediateReflection.Tests.csproj +++ b/tests/ImmediateReflection.Tests/ImmediateReflection.Tests.csproj @@ -1,7 +1,7 @@  - net40;net45;net451;net452;net46;net461;net462;net47;net471;net472;netcoreapp3.1 + net40;net45;net451;net452;net46;net461;net462;net47;net471;net472;net48;netcoreapp3.1;net5.0 ImmediateReflection.Tests @@ -44,9 +44,15 @@ $(DefineConstants);NET472;SUPPORTS_SERIALIZATION;$(AdditionalConstants) + + $(DefineConstants);NET48;SUPPORTS_SERIALIZATION;$(AdditionalConstants) + $(DefineConstants);NETCOREAPP3_1;$(AdditionalConstants) + + $(DefineConstants);NET5_0;$(AdditionalConstants) + From bb3aadc7ec8047fe606ac4c6fce4893ef2673d22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Rab=C3=A9rin?= Date: Thu, 14 Jul 2022 16:26:26 +0200 Subject: [PATCH 13/15] Make project CLS Compliant. --- src/ImmediateReflection/Properties/AssemblyInfo.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ImmediateReflection/Properties/AssemblyInfo.cs b/src/ImmediateReflection/Properties/AssemblyInfo.cs index cbe8c58..3b7703a 100644 --- a/src/ImmediateReflection/Properties/AssemblyInfo.cs +++ b/src/ImmediateReflection/Properties/AssemblyInfo.cs @@ -1,5 +1,7 @@ +using System; using System.Runtime.CompilerServices; using ImmediateReflection; -[assembly:InternalsVisibleTo("ImmediateReflection.Benchmark" + PublicKey.Key)] -[assembly:InternalsVisibleTo("ImmediateReflection.Tests" + PublicKey.Key)] \ No newline at end of file +[assembly: CLSCompliant(true)] +[assembly: InternalsVisibleTo("ImmediateReflection.Benchmark" + PublicKey.Key)] +[assembly: InternalsVisibleTo("ImmediateReflection.Tests" + PublicKey.Key)] \ No newline at end of file From 79802f7e9f42a712923e6b7dab59539df033ec73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Rab=C3=A9rin?= Date: Sun, 4 Sep 2022 22:04:47 +0200 Subject: [PATCH 14/15] Fix CI by updating coveralls. --- ImmediateReflection.sln | 4 ++-- appveyor.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ImmediateReflection.sln b/ImmediateReflection.sln index 513e020..2e597a1 100644 --- a/ImmediateReflection.sln +++ b/ImmediateReflection.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.27428.2043 +# Visual Studio Version 17 +VisualStudioVersion = 17.2.32526.322 MinimumVisualStudioVersion = 10.0.40219.1 Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "ImmediateReflection.CommonInternals", "src\ImmediateReflection.CommonInternals\ImmediateReflection.CommonInternals.shproj", "{CE984360-54F0-406F-B8A9-E75897DAED3B}" EndProject diff --git a/appveyor.yml b/appveyor.yml index 0ecd33c..64c39f0 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -30,7 +30,7 @@ environment: DocFXVersion: 2.59.2 NUnitConsoleVersion: 3.15.2 OpenCoverVersion: 4.7.1221 - CoverallsVersion: 3.0.0 + CoverallsVersion: 4.0.1 COVERALLS_REPO_TOKEN: secure: +DiJ+F7GIX0MMo/rtIRXO8GSdyYHa1CWKLw4H2Rx3AP27Shr6mZMC6l+muu2H/Dg GITHUB_ACCESS_TOKEN: From c52146e102dc7dd6effec47473f75745b8dcb053 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Rab=C3=A9rin?= Date: Mon, 5 Sep 2022 00:04:34 +0200 Subject: [PATCH 15/15] Write release notes. --- RELEASE_NOTES.md | 22 ++++++++++++++----- .../ImmediateReflection.csproj | 12 +++++++--- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 7ad6f9e..0935a00 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,5 +1,15 @@ # Release notes +## What's new in 2.0.0 September 5 2022 +### Updates: +* Update some serialization implementations for ImmediateReflection core types. +* Dynamic methods generated by ImmediateReflection always use the ImmediateReflection module. + +### Misc: +* Get rid of targets anterior to .NET Framework 4.0. +* Add target .NET Standard 2.1 to simplify dependency tree when used. +* Assembly is CLS compliant (Common Language Specification). + ## What's new in 1.6.1 September 4 2022 ### Fixes: * Fix wrong generated IL code for copy constructor under .NET5+ target. @@ -29,7 +39,7 @@ ### Fixes: * Properly handle null parameter for Copy and TryCopy (return null). -### Changes: +### Updates: * Copy and TryCopy consider string and Type as copyable types and return themselves if asked. ## What's new in 1.4.0 September 1 2019 @@ -42,7 +52,7 @@ * Add type extensions to check if a type has a copy constructor and to directly call it. * Add object extensions to check if an instance can be copied by a copy constructor and to directly call it. -### Changes: +### Updates: * Globally optimize the library by reducing the number of redundant null checks. * Slightly optimize the branching in generated code. @@ -56,7 +66,7 @@ ### Fixes: * ImmediateType properly handle arrays which were crashing before. -### Changes: +### Updates: * Default constructor delegates available via ImmediateType are now cached and shared across several instance of ImmediateType. * ImmediateProperty are now cached and shared across several instance of ImmediateType. * ImmediateField are now cached and shared across several instance of ImmediateType. @@ -70,13 +80,13 @@ ### Fixes: * Classes with indexed properties does not crash anymore. -### Changes: +### Updates: * Lazily initialize fields property of ImmediateType. --- ## What's new in 1.1.0 June 24 2019 -### Changes: +### Updates: * Improve performances of memory caching within the library. * Extend support of built-in cache to every target. * Make some methods only available as extensions accessible as normal methods on targets not supporting extensions. @@ -92,7 +102,7 @@ * Properly supports static readonly and constant fields. * Properly handle reflection on enumeration types. -### Changes: +### Updates: * Default flags taken into account when getting an ImmediateType are Public | Instance | Static * Get rid of cache system references replaced by a simpler internal caching system. * Extend caching support to target .NET Framework 4.0. diff --git a/src/ImmediateReflection/ImmediateReflection.csproj b/src/ImmediateReflection/ImmediateReflection.csproj index 7a7c98e..b9c947e 100644 --- a/src/ImmediateReflection/ImmediateReflection.csproj +++ b/src/ImmediateReflection/ImmediateReflection.csproj @@ -31,9 +31,15 @@ See benchmarks here: https://kernelith.github.io/ImmediateReflection/documentati true ImmediateReflection - ➟ Release 1.6.1 -Fixes: -- Fix wrong generated IL code for copy constructor under .NET5+ target. + ➟ Release 2.0.0 +Updates: +- Update some serialization implementations for ImmediateReflection core types. +- Dynamic methods generated by ImmediateReflection always use the ImmediateReflection module. + +Misc: +- Get rid of targets anterior to .NET Framework 4.0. +- Add target .NET Standard 2.1 to simplify dependency tree when used. +- Assembly is CLS compliant (Common Language Specification). C# Reflection Fast Immediate Performance Delegate Dynamic