-
Notifications
You must be signed in to change notification settings - Fork 22
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
optimize InterfaceBinderAnalyzer #936
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,21 @@ | |
|
||
namespace D2L.LP.LayeredArch.Data { | ||
|
||
public static class InterfaceBinder<T> { } | ||
public static class InterfaceBinder<T> { | ||
|
||
private void PrivateMethod() { | ||
// This would be an error if the analyzer didn't only consider the public API | ||
PrivateMethod2(); | ||
} | ||
private void PrivateMethod2() { } | ||
|
||
public static object AllFields { get; } = null; | ||
public static object CreateAllFields() => null; | ||
|
||
public static object MatchedFields { get; } = null; | ||
public static object CreateMathedFields() => null; | ||
|
||
} | ||
} | ||
|
||
namespace SpecTests { | ||
|
@@ -23,34 +37,36 @@ public interface InterfaceDto { | |
public class TestCases { | ||
|
||
public void UsedWithClass() { | ||
var type = typeof( InterfaceBinder< /* InterfaceBinder_InterfacesOnly(ClassDto) */ ClassDto /**/ > ); | ||
// This used to be considered an error; however, the updated version of the analyzer | ||
// only looks at member accesses rather than generic type names to be less expensive | ||
_ = typeof( InterfaceBinder<ClassDto> ); | ||
|
||
_ = /* InterfaceBinder_InterfacesOnly(ClassDto) */ InterfaceBinder<ClassDto>.AllFields /**/; | ||
_ = /* InterfaceBinder_InterfacesOnly(ClassDto) */ InterfaceBinder<ClassDto>.CreateAllFields() /**/; | ||
_ = /* InterfaceBinder_InterfacesOnly(ClassDto) */ InterfaceBinder<ClassDto>.MatchedFields /**/; | ||
_ = /* InterfaceBinder_InterfacesOnly(ClassDto) */ InterfaceBinder<ClassDto>.CreateMathedFields() /**/; | ||
} | ||
|
||
public void UsedWithInterface() { | ||
var type = typeof( InterfaceBinder<InterfaceDto> ); | ||
_ = typeof( InterfaceBinder<InterfaceDto> ); | ||
|
||
_ = InterfaceBinder<InterfaceDto>.AllFields; | ||
_ = InterfaceBinder<InterfaceDto>.CreateAllFields; | ||
_ = InterfaceBinder<InterfaceDto>.MatchedFields; | ||
_ = InterfaceBinder<InterfaceDto>.CreateMathedFields; | ||
} | ||
|
||
public void GenericTypeDefinition() { | ||
var type = typeof( InterfaceBinder<> ); | ||
_ = typeof( InterfaceBinder<> ); | ||
} | ||
|
||
public void UnknownGenericTypeArgument() { | ||
var type = typeof( InterfaceBinder< /* InterfaceBinder_InterfacesOnly(Wacky) */ Wacky /**/ > ); | ||
} | ||
} | ||
|
||
public class Unrelated { | ||
|
||
public void UnknownGenericTypeDefinition() { | ||
var type = typeof( Wacky<int> ); | ||
} | ||
|
||
public void NotInterfaceBinder() { | ||
var type = typeof( Action<int> ); | ||
} | ||
_ = typeof( InterfaceBinder<Wacky> ); | ||
|
||
public void TooManyGenericTypeArguments() { | ||
var type = typeof( Action<int, int> ); | ||
_ = /* InterfaceBinder_InterfacesOnly(Wacky) */ InterfaceBinder<Wacky>.AllFields /**/; | ||
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.
|
||
_ = /* InterfaceBinder_InterfacesOnly(Wacky) */ InterfaceBinder<Wacky>.CreateAllFields() /**/; | ||
_ = /* InterfaceBinder_InterfacesOnly(Wacky) */ InterfaceBinder<Wacky>.MatchedFields /**/; | ||
_ = /* InterfaceBinder_InterfacesOnly(Wacky) */ InterfaceBinder<Wacky>.CreateMathedFields() /**/; | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Erroring on a different usage (now just public API usage), but much less work to do so. I don't expect simply referencing the type
InterfaceBinder<ClassDto>
would really lead to any issues (outside of reflection, but that's a general hole regardless).