44using System ;
55using System . Collections . Concurrent ;
66using System . Collections . Generic ;
7+ using System . Diagnostics . CodeAnalysis ;
78using System . Linq ;
89using System . Reflection ;
910using JetBrains . Annotations ;
@@ -42,9 +43,10 @@ public class SettingSourceAttribute : Attribute, IComparable<SettingSourceAttrib
4243 /// <remarks>
4344 /// Must be a type deriving <see cref="SettingsItem{T}"/> with a public parameterless constructor.
4445 /// </remarks>
46+ [ DynamicallyAccessedMembers ( DynamicallyAccessedMemberTypes . PublicProperties | DynamicallyAccessedMemberTypes . PublicParameterlessConstructor ) ]
4547 public Type ? SettingControlType { get ; set ; }
4648
47- public SettingSourceAttribute ( Type declaringType , string label , string ? description = null )
49+ public SettingSourceAttribute ( [ DynamicallyAccessedMembers ( DynamicallyAccessedMemberTypes . All ) ] Type declaringType , string label , string ? description = null )
4850 {
4951 Label = getLocalisableStringFromMember ( label ) ?? string . Empty ;
5052 Description = getLocalisableStringFromMember ( description ) ?? string . Empty ;
@@ -109,6 +111,7 @@ public int CompareTo(SettingSourceAttribute? other)
109111
110112 public static partial class SettingSourceExtensions
111113 {
114+ [ RequiresUnreferencedCode ( "SettingSourceAttribute uses reflection to instantiate settings controls and may not be compatible with trimming." ) ]
112115 public static IEnumerable < Drawable > CreateSettingsControls ( this object obj )
113116 {
114117 foreach ( var ( attr , property ) in obj . GetOrderedSettingsSourceProperties ( ) )
@@ -222,6 +225,7 @@ public static IEnumerable<Drawable> CreateSettingsControls(this object obj)
222225 /// Can be used for serialization and equality comparison purposes.
223226 /// </summary>
224227 /// <param name="setting">A <see cref="SettingSourceAttribute"/> bindable.</param>
228+ [ RequiresUnreferencedCode ( "Uses BindableValueAccessor which relies on reflection and may not be compatible with trimming." ) ]
225229 public static object GetUnderlyingSettingValue ( this object setting )
226230 {
227231 switch ( setting )
@@ -250,6 +254,7 @@ public static object GetUnderlyingSettingValue(this object setting)
250254 }
251255 }
252256
257+ [ RequiresUnreferencedCode ( "SettingSourceAttribute uses reflection to retrieve properties and may not be compatible with trimming." ) ]
253258 public static IEnumerable < ( SettingSourceAttribute , PropertyInfo ) > GetSettingsSourceProperties ( this object obj )
254259 {
255260 var type = obj . GetType ( ) ;
@@ -260,7 +265,7 @@ public static object GetUnderlyingSettingValue(this object setting)
260265 return properties ;
261266 }
262267
263- private static IEnumerable < ( SettingSourceAttribute , PropertyInfo ) > getSettingsSourceProperties ( Type type )
268+ private static IEnumerable < ( SettingSourceAttribute , PropertyInfo ) > getSettingsSourceProperties ( [ DynamicallyAccessedMembers ( DynamicallyAccessedMemberTypes . PublicProperties ) ] Type type )
264269 {
265270 foreach ( var property in type . GetProperties ( BindingFlags . GetProperty | BindingFlags . Public | BindingFlags . Instance ) )
266271 {
@@ -273,6 +278,7 @@ public static object GetUnderlyingSettingValue(this object setting)
273278 }
274279 }
275280
281+ [ RequiresUnreferencedCode ( "SettingSourceAttribute uses reflection to retrieve properties and may not be compatible with trimming." ) ]
276282 public static ICollection < ( SettingSourceAttribute , PropertyInfo ) > GetOrderedSettingsSourceProperties ( this object obj )
277283 => obj . GetSettingsSourceProperties ( )
278284 . OrderBy ( attr => attr . Item1 )
0 commit comments