Friday, March 28, 2014

Pasting Code In Blogger - Online Formatting Helper

Pasting code in blogger needs to be done through the HTML markup in blogger. To maintain formatting, code must be placed inside these HTML tags as follows...

<blockquote> - Quoted from another source
    <pre> - pre-formatted text
            CODE
    </pre>
</blockquote>

Then of course < and > characters need to be replaced with &lt; and &gt;

Thankfully I ran across this online tool, which automates the process.  

INotifyPropertyChanged in .Net 4.5 - CallerMemberName

We are all pretty used to writing our property changed notification something like this.
   public bool IsBusy
        {
            get { return _isBusy; }
            set
            {
                if (value.Equals(_isBusy)) return;
                _isBusy = value;
                RaisePropertyChanged("IsBusy");
            }
        }
   private bool _isBusy;
or better yet, make it re-factor friendly using Linq
   public bool IsBusy
        {
            get { return _isBusy; }
            set
            {
                if (value.Equals(_isBusy)) return;
                _isBusy = value;
                RaisePropertyChanged(() => IsBusy);
            }
        }
   private bool _isBusy;

What if we could just do something like this...
   public bool IsBusy
        {
            get { return _isBusy; }
            set
            {
                if (value.Equals(_isBusy)) return;
                _isBusy = value;
                NotifyChanged();
            }
        }
   private bool _isBusy;
Now with .Net 4.5 the above is possible.  Here is a basic implementation of ObservableObject with the new .Net 4.5 CallerMemberName attribute.
    /// <summary> Base observable object class. </summary>
    public abstract class ObservableObject : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
        public delegate void PropertyChangedEventHandler(object sender, PropertyChangedEventArgs e);

        /// <summary> Notify property has changed </summary>
        /// <param name="propertyName">String property name, if not provided, will be picked up from calling member</param>
        protected void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        #endregion
    }

NuGet - Update Process for Package Restore

Recently I discovered that NuGet has dramatically simplified package restore, but no one told me.  

The NuGet team has provided the following document Migrating to Automatic Package Restore.

I'll provide the abbreviated document here.

The Previous Method
Right right click on your solution in visual studio choosing >> Enable package restore. This created a .nuget folder containing the nuget.exe etc. Your .csproj or .vbproj files were modified with an <import /> tag containing a NuGet path.

This triggered automatic package restore upon a build of your solution. Thankfully, this is no longer necessary!


The New way to do package restore 
You do nothing. Unless you’re building from the command line, in which case you run 'nuget restore' before msbuild.

Using this method with SVN Externals 
When using SVN externals, often you may only want to pull one project from a solution, into another solution as an external. Unfortunately, this breaks the NuGet package restore system, as package restore is based at the solution level.

Currently I’ve only come up with one simple method. In your SVN externals, reference the entire solution from which you only want one project. Open the solution that is downloaded as your external reference and build it. Now packages are restored, and you may use the one project you actually want to reference externally. Seems quite wrong doesn't it?  Hope the NuGet team keeps working on finding better ways for scenarios such as the above...