Dynamic C# Fundamentals

Take advantage of dynamic C# to reduce the amount of code that needs to be written, meaning more time to deliver more features to the customer. You'll learn how dynamic C# can make many programming tasks easier.
Course info
Rating
(101)
Level
Intermediate
Updated
Jun 7, 2016
Duration
2h 50m
Table of contents
Course Overview
Introducing Dynamic C#
Simplifying Code with Dynamic C#
Creating Custom Dynamic Classes
Interoperating with Dynamic Languages
Description
Course info
Rating
(101)
Level
Intermediate
Updated
Jun 7, 2016
Duration
2h 50m
Description

While C# is a statically typed language, it also has (often overlooked) dynamic features. For example, using the dynamic keyword allows the instantiation of dynamic objects whose structure is not known by the compiler at compile time. In this course, Dynamic C# Fundamentals, you'll learn how the use of dynamic C# makes some difficult and cumbersome programming tasks easier to write and work with. You'll learn how dynamic C# can make COM interop easier, enable adding of arbitrary properties at runtime, and simplify working with JSON and SQL data. You'll also discover how the dynamic keyword can reduce XAML boilerplate binding code and even enable interoperation with other dynamic languages such as Python. By the end of this course, you'll know how to take advantage of dynamic C# in order to reduce the amount of code that needs to be written, make it more readable, and give yourself more time to deliver more features to the customer.

About the author
About the author

With over 15 years experience, Jason Roberts is a Microsoft .NET MVP, freelance developer, and author.

More from the author
Mocking with Moq and NUnit
Intermediate
1h 53m
Feb 22, 2019
Introduction to .NET Testing with NUnit 3
Intermediate
2h 6m
Dec 17, 2018
More courses by Jason Roberts
Section Introduction Transcripts
Section Introduction Transcripts

Course Overview
Hi everyone! My name is Jason Roberts. Welcome to my course, Dynamic C# Fundamentals. I'm a Microsoft. NET MVP, freelance developer, and author. In this course, we're going to learn about the often-underutilized dynamic features of C#. We'll learn how dynamic C# fits together with regular C# code, how its use can improve developer productivity, and also increase the readability and simplicity of our code. Some of the major topics that we'll cover in this course include why we might want to use dynamic C#, some examples of its use in various different types of. NET applications, how to create our own custom dynamic classes, and even how to leverage features of other dynamic languages from our C# code. By the end of this course, you'll understand how dynamic C# is implemented and how to interoperate with other dynamic languages such as Python. Before beginning this course, you should be familiar with using Visual Studio to write C# code. I hope you'll enjoy me on this journey with the Dynamic C# Fundamentals course at Pluralsight.

Creating Custom Dynamic Classes
Hi! Welcome back. Using dynamic classes that other people have written may look like magic, but in reality, we can create our own dynamic classes like we would any other class. We just need to inherit the right base class or implement the necessary interfaces so our class works nicely with the dynamic language at runtime. In this module, we're going to start off by looking at some of the reasons why we might want to write our own custom dynamic classes. We're then going to learn about one of the key interfaces involved in dynamic C# code, and that's the IDynamicMetaObjectProvider interface. Rather than implementing this interface ourselves, we're going to learn that we can instead inherit from the DynamicObject base class, and this is going to be a lot more convenient because we can simply override the virtual methods of the DynamicObject class. So there're a number of these virtual methods that we can override from the DynamicObject base class, and we're going to learn about some of these key ones and how they map to C# programming constructs. We're then going to jump into Visual Studio, and we're going to start building our own custom class. So we're going to be building a class to represent an HtmlElement. When we create an instance of our HtmlElement class, we can give it a tag name, and we can also assign it to a dynamic variable. We can then make use of dynamic C# to add arbitrary attributes to our HtmlElement, such as setting the source for an image. We'll also be able to get the rendered HTML for the element, and we'll see a number of ways we can do this including overriding the ToString method. So let's kick off this module by looking at some of the reasons why we might want to write our own custom dynamic classes.

Interoperating with Dynamic Languages
Hi! Welcome back. One of the benefits of the dynamic language runtime is the ability for our C# code to interoperate with other languages build on top of it such as IronPython and IronRuby. Whilst making use of something like IronPython is not an everyday occurrence for. NET developers, this module will show the power of the DLR in action. We'll even see that we can pass our custom dynamic HtmlElement objects to Python code. In this module, we're going to start off by looking at some of the reasons why we might want to consider dynamic language interop. We'll then jump into Visual Studio, and we'll see how we can get started with IronPython in our C# code. We'll then see how we can allow the end user to add scripting content that gets executed in our application. We'll also learn how we can execute Python statements in our C# application and get access to the result value of the statement. We'll learn that we can create Python objects and then access them dynamically from our C# code. And, finally, we'll see how we can create an instance of our HtmlElement class that we created in the last module and pass it to a Python script, which will add some attributes, return it to our C# code, and then we can see that our C# code can access these attributes that were added in Python. So let's kick off this module by looking at some of the reasons why we might want to consider dynamic interop.