Skip to content

Commit c6bb730

Browse files
committed
Exclude members of Object from TypeAccessor
A number of members from `Object` were being added to every `TypeAccessor.Members` list, such as `ToString()`. These don't serve a purpose in terms of our mapping libraries, and just add a lot of clutter to the cache. These can be removed. This also allows us to fix a unit test which, previously, had to account for these items being inherited from object.
1 parent 5310655 commit c6bb730

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

OnTopic.Tests/TypeAccessorTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void GetMembers_MixedValidity_ReturnsValidMembers() {
6565

6666
var members = _typeAccessor.GetMembers();
6767

68-
Assert.Equal(7+4, members.Count); // Includes four compliant members inherited from object
68+
Assert.Equal(7, members.Count);
6969

7070
}
7171

OnTopic/Internal/Reflection/MemberAccessor.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,11 @@ internal void Validate(object target) {
246246
/// </remarks>
247247
internal static Func<MemberInfo, bool> IsValid => memberInfo => {
248248

249+
/*------------------------------------------------------------------------------------------------------------------------
250+
| Skip members inherited from object
251+
\-----------------------------------------------------------------------------------------------------------------------*/
252+
if (memberInfo.DeclaringType == typeof(object)) return false;
253+
249254
/*------------------------------------------------------------------------------------------------------------------------
250255
| Ensure type is property or method
251256
\-----------------------------------------------------------------------------------------------------------------------*/
@@ -254,8 +259,8 @@ internal void Validate(object target) {
254259
/*------------------------------------------------------------------------------------------------------------------------
255260
| Validate properties
256261
\-----------------------------------------------------------------------------------------------------------------------*/
257-
if (memberInfo is PropertyInfo) return true;
258262
if (memberInfo.Name.Contains("et_", StringComparison.Ordinal)) return false;
263+
if (memberInfo is PropertyInfo) return true;
259264

260265
/*------------------------------------------------------------------------------------------------------------------------
261266
| Validate methods

0 commit comments

Comments
 (0)