Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Dynamic import | Get Ready For C# 4.0

Many COM methods accept and return “variant” types, which are Represented in the PIAs as Object. In the vast majority of cases, a programmer calling these methods already knows the static type of a Returned Object from context, but explicitly has to perform a cast on the returned value to make use of that knowledge. These casts are so common that they constitute a major nuisance.
In order to facilitate a smoother experience, if you choose to import these COM APIs with PIA-embedding, variants are instead represented using the type dynamic. In other words, from your point of view, COM signatures now have occurrences of dynamic instead of object in them.
This means that you can easily access members directly off a returned object, or you can assign it to a strongly typed local variable without having to cast. To illustrate, you can now say


instead of


and


instead of



This post first appeared on Code Snippets, please read the originial post: here

Share the post

Dynamic import | Get Ready For C# 4.0

×

Subscribe to Code Snippets

Get updates delivered right to your inbox!

Thank you for your subscription

×