Mixing early-binding and late-binding with nameof operator in C# [CRM]

nameof expression in C#6.0

Bernado Nguyen-Hoan's Blog - Coding Stories from an IT Mercenary

There are many benefits of using early-binding when coding against CRM. There are times however when you need to fall back to late-binding, for example when you need to query relationships, or when you need to call Retrieve to optimise performance (as this service call allows you to load only selected fields of a record).

Rather than using literal string, you can use the nameof operator in C# 6 to get the attributes and relationship names. This works because the properties of the early-binding classes are generated based on the attributes and relationship names in CRM.

For example, to get the AccountNumber field of an Account record:

And there you have it: late-binding with all the early-binding zen!

View original post

Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

1 thought on “Mixing early-binding and late-binding with nameof operator in C# [CRM]”

Share your thoughts

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s