Skip to content
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

"use base type whenever possible" refactoring #11

Open
tugberkugurlu opened this issue Nov 17, 2014 · 2 comments
Open

"use base type whenever possible" refactoring #11

tugberkugurlu opened this issue Nov 17, 2014 · 2 comments

Comments

@tugberkugurlu
Copy link

This is more for a discussion than a proposal as I'm not sure how this can be done and handled because I assume there are lots of legit and corner cases to cover here even if I was able to only come up with one below.

For the below case for example, it would be possible to use Stream instead of FileStream:

using (FileStream stream = File.Open(@"c:\dev\foo.txt", FileMode.Open))

Cases to cover:

  • We need to make sure that any members that are specific to FileStream is not used inside the code block.
  • return signature might be FileStream for the method and the stream could be instance which is being returned.
@BillWagner
Copy link
Contributor

@tugberkugurlu I'm really concerned about this idea. I think there are very common cases where this could cause wrong effects, especially where interfaces are concerned.

Consider if this refactoring were to replace an IQueryable with its base, IEnumerable. That would change the processing of that query from being remoted to data storage engine, and make all processing happen locally, using LINQ to Objects.

This is less of an issue with classes than interfaces, but I think we need to be very careful here.

@tugberkugurlu
Copy link
Author

@BillWagner I agree. I just wanted to put it here to see what others think. I'm nowhere near to attempt to implement this at this stage as it looks really complicated to get it right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants