-
Notifications
You must be signed in to change notification settings - Fork 292
Cache reflection lookups in DynamicDataOperations #7535
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -5,7 +5,7 @@ namespace Microsoft.VisualStudio.TestTools.UnitTesting; | |||
|
|
||||
| internal static class DynamicDataOperations | ||||
| { | ||||
| private const BindingFlags DeclaredOnlyLookup = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly; | ||||
| private const BindingFlags MemberLookup = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy; | ||||
|
||||
|
|
||||
| public static IEnumerable<object[]> GetData(Type? dynamicDataDeclaringType, DynamicDataSourceType dynamicDataSourceType, string dynamicDataSourceName, object?[] dynamicDataSourceArguments, MethodInfo methodInfo) | ||||
| { | ||||
|
|
@@ -167,56 +167,11 @@ private static bool TryGetData(object dataSource, [NotNullWhen(true)] out IEnume | |||
| } | ||||
|
|
||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
| private static FieldInfo? GetFieldConsideringInheritance(Type type, string fieldName) | ||||
Evangelink marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||
| { | ||||
| // NOTE: Don't use GetRuntimeField. It considers inheritance only for instance fields. | ||||
| Type? currentType = type; | ||||
| while (currentType is not null) | ||||
| { | ||||
| FieldInfo? field = currentType.GetField(fieldName, DeclaredOnlyLookup); | ||||
| if (field is not null) | ||||
| { | ||||
| return field; | ||||
| } | ||||
|
|
||||
| currentType = currentType.BaseType; | ||||
| } | ||||
|
|
||||
| return null; | ||||
| } | ||||
| => type.GetField(fieldName, MemberLookup); | ||||
|
|
||||
| private static PropertyInfo? GetPropertyConsideringInheritance(Type type, string propertyName) | ||||
| { | ||||
| // NOTE: Don't use GetRuntimeProperty. It considers inheritance only for instance properties. | ||||
| Type? currentType = type; | ||||
| while (currentType is not null) | ||||
| { | ||||
| PropertyInfo? property = currentType.GetProperty(propertyName, DeclaredOnlyLookup); | ||||
| if (property is not null) | ||||
| { | ||||
| return property; | ||||
| } | ||||
|
|
||||
| currentType = currentType.BaseType; | ||||
| } | ||||
|
|
||||
| return null; | ||||
| } | ||||
| => type.GetProperty(propertyName, MemberLookup); | ||||
|
|
||||
| private static MethodInfo? GetMethodConsideringInheritance(Type type, string methodName) | ||||
| { | ||||
| // NOTE: Don't use GetRuntimeMethod. It considers inheritance only for instance methods. | ||||
| Type? currentType = type; | ||||
| while (currentType is not null) | ||||
| { | ||||
| MethodInfo? method = currentType.GetMethod(methodName, DeclaredOnlyLookup); | ||||
| if (method is not null) | ||||
| { | ||||
| return method; | ||||
| } | ||||
|
|
||||
| currentType = currentType.BaseType; | ||||
| } | ||||
|
|
||||
| return null; | ||||
| } | ||||
| => type.GetMethod(methodName, MemberLookup); | ||||
| } | ||||
Uh oh!
There was an error while loading. Please reload this page.