Favorite Tech Features of 2015

Looking back, there have been several enhancements in C# 6.0 and Xamarin 4.0 in 2015. Here my favorite ones.
C#
Auto property initializer
This had been a long awaited feature. Developer can initialize auto properties in place instead of writing extra line in the constructor.
Pre 6.0

public string SeletedType { get; set; }
public DeviceVM()
{
    SeletedType = "iPhone";
}

6.0

 public string SeletedType { get; set; } = "iPhone";


Null propagation operator
Another feature that makes code more pleasing to read and maintain. It avoids hassle of multiple if checks to see, if an instance is null.
Pre 6.0

       void Clear()
       {
          if (Users != null)
          {
             Users.Clear();
          }
       }

      6.0

       void Clear()
       {
          Users?.Clear();
       }

Await in catch and finally
It required an extra flag to check operation was successful or not and then perform another await operation in catch based on the flag. With 6.0, await can be done in catch and also in finally.
Pre 6.0

       async Task FooAsync()
       {
           bool step1Succeeded = false;
           try
           {
              await Step1Async();
              step1Succeeded = true;
           }
           catch (Exception )
           {
              ...
           }

           if (!step1Succeeded)
           {
                 await Step1ExceptionCleanAsync();
           }
       }

6.0

       async Task FooAsync()
       {
          try
          {
              await Step1Async();
          }
          catch (Exception)
          {
              await Step1ExceptionCleanAsync ();
          }
       }

nameof operator
This feature is the gift of the year for those who use MVVM design pattern extensively. When an operation has effect on a property, it needed a navigation of expression tree (or hardcoded property name string) to send the right name to  a “PropertyChanged” event.
Pre 6.0

          private int _subTotal;
          public int SubTotal
          {
              get { return _subTotal; }
              set
              {
                 if (_subTotal != value)
                 {
                     _subTotal = value;
                    NotifyPropertyChanged();
                    NotifyPropertyChanged((DeviceVM vm) => vm.Total);
// Less desired
// NotifyPropertyChanged("Total");
                 }
               }
          }
          private void NotifyPropertyChanged<T, U>(Expression<Func<T, U>> expression)
          {
             var memberExpression = expression.Body as MemberExpression;
             if (memberExpression == null)
             {
                 throw new ArgumentException("Invalid argument");
             }
             NotifyPropertyChanged(memberExpression.Member.Name);
          }

          private void NotifyPropertyChanged([CallerMemberName]string propName = "")
          {
              ...
          }

6.0

          private int _subTotal;
          public int SubTotal
          {
              get { return _subTotal; }
              set
              {
                  if (_subTotal != value)
                  {
                      _subTotal = value;
                      NotifyPropertyChanged();
                      NotifyPropertyChanged(nameof(Total));
                  }
              }
          }
          private void NotifyPropertyChanged([CallerMemberName]string propName = "")
          {
              ...
          }

Xamarin
Ability to edit xib in designer
Editing a custom cell would require one to use Xcode designer. Providing ability to edit it in Xamarin designer saves the effort to deal with one more tool.
Pre-compiled XAML
Who likes runtime surprises because of a typo in the Xaml? Adding a declaration in assembly can catch XAML errors during compilation. This makes life easy.

using Xamarin.Forms.Xaml;
...
[assembly: XamlCompilation (XamlCompilationOptions.Compile)]

These are my favorites from 2015. Thanks all those who made it happen.

What are your favorite features?

Published by: Sameer Khandekar

I am a passionate software engineer who loves to work on Azure microservices, REST API, SDKs, and .NET apps using WPF, Xamarin, and MAUI. The work includes highly scalable geo-distributed services and an authentication library with nearly 500 million downloads. I also had fun integrating with hardware using Bluetooth (BLE). More here: https://www.sameer.blog/about/

Categories UncategorizedLeave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s