Skip to content

Instantly share code, notes, and snippets.

@ChaseFlorell
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChaseFlorell/9648056 to your computer and use it in GitHub Desktop.
Save ChaseFlorell/9648056 to your computer and use it in GitHub Desktop.
Place this file beside the `Cirrious.MvvmCross.dll` file in each of the `lib` directories. Doing so will enable you to [alt] + [enter] (resharper) on an AutoProperty, and get the additional option "To property with change notification".
<?xml version="1.0" encoding="utf-8"?>
<assembly name="Cirrious.MvvmCross">
<member name="M:Cirrious.MvvmCross.ViewModels.MvxNotifyPropertyChanged.RaisePropertyChanged``1(System.Linq.Expressions.Expression{System.Func{``0}})">
<attribute ctor="M:JetBrains.Annotations.NotifyPropertyChangedInvocatorAttribute.#ctor" />
</member>
</assembly>
<!-- https://github.com/MvvmCross/MvvmCross/blob/v3.1/Cirrious/Cirrious.MvvmCross/ViewModels/MvxNotifyPropertyChanged.cs#L40 -->
public class Foo : MvxViewModel
{
// before
public string Bar { get; set; }
// after [alt] + [enter]
private string _bar;
public string Bar
{
get { return _bar; }
set
{
if (value == _bar) return;
_bar = value;
RaisePropertyChanged(() => Bar);
}
}
}
@ChaseFlorell
Copy link
Author

FIXED

This is not working... not sure where I'm going wrong.

@hmemcpy
Copy link

hmemcpy commented Mar 19, 2014

Try placing it next to the assembly (I assume it's a nuget package), so place it in lib, named Cirrious.MvvmCross.ExternalAnnotations.xml. OR in the ExternalAnnotations dir, under, say Cirrious.MvvmCross dir, named Attributes.xml

Then reload your solution. Go to the RaisePropertyChanged method in question, then press the QuickDoc shortcut (either Ctrl-Q with IntelliJ keybindings, or Ctrl-Shift-F1 with VS). You should see the attribute applied on the method...

@ChaseFlorell
Copy link
Author

Do I need to add the name "ExternalAnnotations" to the end of the xml? It is in my lib dir beside the mvvmcross dll.

Current Setup

\packages\MvvmCross.HotTuna.MvvmCrossLibraries.3.1.1\lib\portable-win+net45+sl50+wp8+MonoAndroid+MonoTouch

  • Cirrious.MvvmCross.dll
  • Cirrious.MvvmCross.xml

I do want to keep it in the packages folder so that it can be shared with the team via git.

@hmemcpy
Copy link

hmemcpy commented Mar 19, 2014

Yeah, the .ExternalAnnotations.xml suffix is needed only if the xml is placed next to the assembly. I just want to try it, to see if ReSharper picks it up in general. After that you could move it to ExternalAnnotations\Cirrious.MvvmCross\Attributes.xml.

If you were on ReSharper 8, this could be packaged as a plugin, but for now it's either those two locations.

@ChaseFlorell
Copy link
Author

So in that Nuget package directory I have the following two items.

  • Cirrious.MvvmCross.dll
  • Cirrious.MvvmCross.ExternalAnnotations.xml

The contents of the XML is what's posted above.
I re-launch Visual Studio, create a property

public string Foo {get; set;}

then I alt + enter

but unfortunately the option still doesn't exist.

@hmemcpy
Copy link

hmemcpy commented Mar 19, 2014

Took me a second to realize but I got it! There's a small issue with the xml - there should be 2 backticks (``), not just one!

Here's the "fixed" version:

<?xml version="1.0" encoding="utf-8"?>
<assembly name="Cirrious.MvvmCross">

  <member name="M:Cirrious.MvvmCross.ViewModels.MvxNotifyPropertyChanged.RaisePropertyChanged``1(System.Linq.Expressions.Expression{System.Func{``0}})">
    <attribute ctor="M:JetBrains.Annotations.NotifyPropertyChangedInvocatorAttribute.#ctor" />
  </member>

</assembly>

<!-- https://github.com/MvvmCross/MvvmCross/blob/v3.1/Cirrious/Cirrious.MvvmCross/ViewModels/MvxNotifyPropertyChanged.cs#L40 -->

woot!

@ChaseFlorell
Copy link
Author

Working now - Thanks!

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