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 CodeAnalysis Project with Roslyn Code Analyzer #1117

Merged
merged 5 commits into from Aug 27, 2015

Conversation

Projects
None yet
3 participants
@Stephanvs
Copy link
Member

Stephanvs commented Aug 26, 2015

Background

With the release of C# version 6 Microsoft has rewritten their C# and VB compilers from the ground up. They are known as the Microsoft .NET Compiler Platform (aka Roslyn). These compilers provide library builders to provide the compiler with a set of so-called Analyzers and CodeFixes. These can be shipped through a nuget package, and will light up in an IDE with support for these Roslyn based compilers.

What is this (aka TLDR)?

This pull-request is the first attempt to introduce such analyzers and code fix providers for the MvvmCross library. This fixes #1040.

What does it do?

In short it helps developers use the MvvmCross library the way it was intended to be used.

This first analyzer will identify the following code:

[Activity(...)]
class FirstView : MvxActivity
{
    public new FirstViewModel ViewModel => base.ViewModel as FirstViewModel;
}

and provide you with a IDE tooltip to transform the code into:

[Activity(...)]
class FirstView : MvxActivity<FirstViewModel> { ... }

What's in it?

  • A new project type under the CodeAnalysis solution folder named MvvmCrossCodeAnalysis (there's no . in the name for reasons - no tooling support) I'm wondering what you guys think about that?
  • A Vsix package to enable easy debugging of Code Analyzers/Fixes.

What's still needed?

  • The .nuspec file is a default generated one. It should probably be updated and moved into the root nuspec folder.

I'm very curious what you guys think about it, and I'm looking forward to some feedback!

Stephanvs added some commits Aug 26, 2015

Add initial roslyn analyzer
First analyzer which looks for classes that ultimately derive from
`IMvxView` and declare a property with a name of `ViewModel` whose
return type is either derived from `INotifyPropertyChanged` or
`IMvxViewModel` and informs users to use the generic variant of that
class.

@martijn00 martijn00 added this to the 4.0.0 milestone Aug 26, 2015

@martijn00

This comment has been minimized.

Copy link
Member

martijn00 commented Aug 26, 2015

Looking good! I can fix the nuspecs if you want.

@Stephanvs

This comment has been minimized.

Copy link
Member

Stephanvs commented Aug 26, 2015

That'd be great! Thanks

@azchohfi

This comment has been minimized.

Copy link

azchohfi commented Aug 26, 2015

Loved this!
I think there are many little but useful things that could be done, things like good practices with MVVMCross (checking if public properties are re-setted (after constructor/Start) but does not have a set with a NotifyProperty (Set(ref x, value)), which will cause the property to not update the View, or validations for namespace/folder for View/ViewModels.
Roslyn is amazing and we should definitely use it!

Fixed issue when class is already derived from generic base
If `IMvxView` derived class is already using the generic base, but still
exposes a `ViewModel` property it will no longer show the
diagnostic/fix.

martijn00 added a commit that referenced this pull request Aug 27, 2015

Merge pull request #1117 from Stephanvs/4.0
Add CodeAnalysis Project with Roslyn Code Analyzer

@martijn00 martijn00 merged commit 2b4b978 into MvvmCross:4.0 Aug 27, 2015

@Stephanvs

This comment has been minimized.

Copy link
Member

Stephanvs commented Aug 27, 2015

Superb! Thanks for merging!

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