@@ -64,13 +64,15 @@ internal ConstructedEqualityComparer(Func<T?, T?, bool> equality, Func<T, int> h
6464 }
6565
6666 [ RequiresUnreferencedCode ( "Dynamic code generation may be incompatible with IL trimming" ) ]
67+ [ RequiresDynamicCode ( "Dynamic code generation may be incompatible with AOT" ) ]
6768 private static PropertyInfo ? GetDefaultEqualityComparer ( Type target )
6869 => typeof ( EqualityComparer < > )
6970 . MakeGenericType ( target )
7071 . GetProperty ( nameof ( EqualityComparer < int > . Default ) , PublicStaticFlags ) ;
7172
7273 private static FieldInfo ? HashSaltField => typeof ( RandomExtensions ) . GetField ( nameof ( RandomExtensions . BitwiseHashSalt ) , BindingFlags . NonPublic | BindingFlags . Static | BindingFlags . DeclaredOnly ) ;
7374
75+ [ RequiresDynamicCode ( "Runtime binding requires dynamic code compilation" ) ]
7476 [ RequiresUnreferencedCode ( "Dynamic code generation may be incompatible with IL trimming" ) ]
7577 private static MethodCallExpression EqualsMethodForValueType ( MemberExpression first , MemberExpression second )
7678 {
@@ -97,6 +99,7 @@ private static MethodCallExpression EqualsMethodForValueType(MemberExpression fi
9799 return Expression . Call ( Expression . Property ( null , defaultProperty ) , method , first , second ) ;
98100 }
99101
102+ [ RequiresDynamicCode ( "Runtime binding requires dynamic code compilation" ) ]
100103 [ RequiresUnreferencedCode ( "Dynamic code generation may be incompatible with IL trimming" ) ]
101104 private static Expression HashCodeMethodForValueType ( Expression expr , ConstantExpression salted )
102105 {
@@ -130,6 +133,7 @@ private static Expression HashCodeMethodForValueType(Expression expr, ConstantEx
130133 return expr ;
131134 }
132135
136+ [ RequiresDynamicCode ( "Runtime binding requires dynamic code compilation" ) ]
133137 [ RequiresUnreferencedCode ( "Dynamic code generation may be incompatible with IL trimming" ) ]
134138 private static MethodInfo EqualsMethodForArrayElementType ( Type itemType )
135139 {
@@ -151,6 +155,7 @@ private static MethodInfo EqualsMethodForArrayElementType(Type itemType)
151155 return new Func < IEnumerable < object > ? , IEnumerable < object > ? , bool > ( Collection . SequenceEqual ) . Method ;
152156 }
153157
158+ [ RequiresDynamicCode ( "Runtime binding requires dynamic code compilation" ) ]
154159 [ RequiresUnreferencedCode ( "Dynamic code generation may be incompatible with IL trimming" ) ]
155160 private static MethodCallExpression EqualsMethodForArrayElementType ( MemberExpression fieldX , MemberExpression fieldY )
156161 {
@@ -159,6 +164,7 @@ private static MethodCallExpression EqualsMethodForArrayElementType(MemberExpres
159164 return Expression . Call ( method , fieldX , fieldY ) ;
160165 }
161166
167+ [ RequiresDynamicCode ( "Runtime binding requires dynamic code compilation" ) ]
162168 [ RequiresUnreferencedCode ( "Dynamic code generation may be incompatible with IL trimming" ) ]
163169 private static MethodInfo HashCodeMethodForArrayElementType ( Type itemType )
164170 {
@@ -174,6 +180,7 @@ private static MethodInfo HashCodeMethodForArrayElementType(Type itemType)
174180 . MakeGenericMethod ( itemType ) ;
175181 }
176182
183+ [ RequiresDynamicCode ( "Runtime binding requires dynamic code compilation" ) ]
177184 [ RequiresUnreferencedCode ( "Dynamic code generation may be incompatible with IL trimming" ) ]
178185 private static MethodCallExpression HashCodeMethodForArrayElementType ( Expression expr , ConstantExpression salted )
179186 {
@@ -192,11 +199,10 @@ private static IEnumerable<FieldInfo> GetAllFields(Type type)
192199 }
193200 }
194201
202+ [ RequiresDynamicCode ( "Runtime binding requires dynamic code compilation" ) ]
195203 [ RequiresUnreferencedCode ( "Dynamic code generation may be incompatible with IL trimming" ) ]
196204 private Func < T ? , T ? , bool > BuildEquals ( )
197205 {
198- if ( ! RuntimeFeature . IsDynamicCodeSupported )
199- throw new PlatformNotSupportedException ( ) ;
200206 var x = Expression . Parameter ( typeof ( T ) ) ;
201207 if ( x . Type . IsPrimitive )
202208 return EqualityComparer < T ? > . Default . Equals ;
@@ -238,11 +244,10 @@ private static IEnumerable<FieldInfo> GetAllFields(Type type)
238244 return Expression . Lambda < Func < T ? , T ? , bool > > ( expr , false , x , y ) . Compile ( ) ;
239245 }
240246
247+ [ RequiresDynamicCode ( "Runtime binding requires dynamic code compilation" ) ]
241248 [ RequiresUnreferencedCode ( "Dynamic code generation may be incompatible with IL trimming" ) ]
242249 private Func < T , int > BuildGetHashCode ( )
243250 {
244- if ( ! RuntimeFeature . IsDynamicCodeSupported )
245- throw new PlatformNotSupportedException ( ) ;
246251 Expression expr ;
247252 var inputParam = Expression . Parameter ( typeof ( T ) ) ;
248253 if ( inputParam . Type . IsPrimitive )
@@ -291,6 +296,7 @@ private Func<T, int> BuildGetHashCode()
291296 /// <param name="equals">The implementation of equality check.</param>
292297 /// <param name="hashCode">The implementation of hash code.</param>
293298 /// <exception cref="PlatformNotSupportedException">Dynamic code generation is not supported by underlying CLR implementation.</exception>
299+ [ RequiresDynamicCode ( "Runtime binding requires dynamic code compilation" ) ]
294300 [ RequiresUnreferencedCode ( "Dynamic code generation may be incompatible with IL trimming" ) ]
295301 public void Build ( out Func < T ? , T ? , bool > equals , out Func < T , int > hashCode )
296302 {
@@ -303,6 +309,7 @@ public void Build(out Func<T?, T?, bool> equals, out Func<T, int> hashCode)
303309 /// </summary>
304310 /// <returns>The generated equality comparer.</returns>
305311 /// <exception cref="PlatformNotSupportedException">Dynamic code generation is not supported by underlying CLR implementation.</exception>
312+ [ RequiresDynamicCode ( "Runtime binding requires dynamic code compilation" ) ]
306313 [ RequiresUnreferencedCode ( "Dynamic code generation may be incompatible with IL trimming" ) ]
307314 public IEqualityComparer < T > Build ( )
308315 {
0 commit comments