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

Auto Implementing Generic Methods #3

Merged
merged 15 commits into from Oct 13, 2018
Merged

Auto Implementing Generic Methods #3

merged 15 commits into from Oct 13, 2018

Conversation

haven1433
Copy link
Owner

@haven1433 haven1433 commented Oct 6, 2018

  • update version to 1.0.1
  • include xml documentation with System.Delegation
  • don't include generated code in the source control. Use AutoImplement to generate during build.
  • add implementations for generic methods.
  • changed Indent() method to Scope property, since the fact that it's creating a scope is more important and the indent is just a side effect.

…t package from a release. Note that the first NuGet package (1.0.0) will include everything that was in the 1.0.0 release, and in the future the .nuspec needed for a nuget package will actually be included in that release.
…it. This is meant to be used

updating version numbers 1.0.0 -> 1.0.1
using AutoImplement to generate the Event-using class that we want for functional testing, to verify that the event works as expected.
…, this is basically just adding the list of generic parameters where it is needed. For Stubs, generic methods had to be implemented in a special way, because you cannot have generic lambda expressions. So for Stubs, every generic method Foo<> gets a matching ImplementFoo<>(Foo<>) method, that takes a delegate. Those delegates are added to a dictionary, and calling Foo<> looks for a matching dictionary entry to call. If it doesn't find one, just do nothing (return default). If you want to create a single method that implements arbitrary generics instead of adding specific implementations one at a time, you can wrap your stub with a decorator and put the general implementation in the decorator.
added information about the new features being added in this pull request
… creates a scope. Changed from a method to a property and renamed to be more clear.
@@ -17,7 +17,7 @@ public class StringWriter {
}
}

public IDisposable Indent() => new IndentationScope(this);
public IDisposable Scope => new IndentationScope(this);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this being a property cause any weird behavior? I would think that weird scoping would occur if a breakpoint was tripped and the StringWriter was expanded in Visual Studio.

Since it has side effects, it should probably be a method.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel that using (writer.Scope) is clear enough for a user to understand what's going on. However, I did rename the class to make it more clear that this is specifically generating C# source files, making the renamed behavior a bit more obvious.

It does have side effects (indenting), but it being a property causes no weird behavior and helps the usage read easier. Otherwise, as a method, it would probably need to be called something like CreateScope() (verb/noun pattern). As a property that returns an IDisposable, I feel that this is clear enough.

Refactoring the code to make it make a bit more sense.
Also handling the leading 'I' on interfaces a little better, so it's less likely to do something weird if the leading 'I' isn't there.
@@ -46,9 +46,9 @@ public static class Program {
var mainName = type.Name.Split('`')[0];
if (mainName.StartsWith("I")) mainName = mainName.Substring(1); // strip leading 'I' from interface name
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the logic to remove a leading "I" when it makes sense need to be single sourced? It seems inconsistent between different call sites.

int skipFirstCharacter = originalName.StartsWith("I") && char.IsUpper(originalName[1]) ? 1 : 0;

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I went ahead and single-sourced all the places that were trying to remove the leading 'I'.

While looking for other things that didn't make sense, I also moved the code that adds the using statements into the builders, to decrease how much the overall program needs to know about the code that's being generated.

…nse.

Single-sourced the code for removing the leading 'I' from interfaces.
Since Stubs include the System namespace for System.Type, clean up the generated code to take advantage of the System namespace for other classes.
  (EventHandler, Func, Action)
@haven1433 haven1433 merged commit 01e9db7 into master Oct 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants