-
Notifications
You must be signed in to change notification settings - Fork 652
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
Add GitVersionInformationAttribute to make reflection easier #526
Conversation
…o make reflection of the contained version information easier.
…y attributes so they are easier to find.
…ationAttribute and that it has the correct values.
…null`, since that would make the verification kind of pointless.
{ | ||
var emitResult = compilation.Emit(stream); | ||
|
||
Assert.IsTrue(emitResult.Success, string.Join(Environment.NewLine, emitResult.Diagnostics.Select(x => x.Descriptor))); |
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.
FYI shouldly would give much better error messages:
Current: false should be true (some descriptor)
Shouldly: emitResult.Success should be true. Additional Context: some descriptor
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.
Yea, it's not my assert. I thought I'd just leave as much code I didn't write untouched to focus the PR on one thing so it would be easier to review. 😄
#525 puts the different classes into namespaces which prevents conflicts when using |
using GitVersion; | ||
|
||
public class AssemblyInfoBuilder | ||
{ | ||
public string GetAssemblyInfoText(VersionVariables vars) | ||
{ | ||
var v = vars.ToArray(); |
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.
FYI, .ToList()
is actually more efficient because an IEnumerable length is not fixed the array buffer has to be expanded multiple times, lists have that functionality built in. Not that it really matters in most code but just a FYI :)
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.
Ah yes. I just like arrays better due to the built in syntactic sugar. Not that I used that here, but habits die hard. :)
Nice addition, have rebased and pushed to #531 so it can be merged |
@JakeGinnivan Awesome! 😄 |
Right now, it's a bit hard to do reflection on an assembly to dig out all of the juicy GitVersion data, since the data is embedded within the static class
GitVersionInformation
. To get to this class, you'd have to doAssembly.GetTypes()
, which is prone to throwing exceptions. It would be more reflection-friendly to have the information inside an[assembly: Attribute]
.So I've created a
GitVersionInformationAttribute
that should remedy this. I've not removed any of the previously generated data, but I've taken the liberty of removing extraneous whitespace in the generated.cs
file. I've also expanded on theAssemblyInfoBuilderTests.VerifyCreatedCode()
test to verify the contents of the generated assembly and assert whether or not theGitVersionInformationAttribute
actually contains the information we want to or not.