hidden facts of .net language gems

Post on 26-Aug-2014

1.037 Views

Category:

Technology

15 Downloads

Preview:

Click to see full reader

DESCRIPTION

Helloworldgeeks organized event on Language internals.

TRANSCRIPT

Hidden facts of .NET 4.5 language gems

By Abhishek Sur

Website: www.abhisheksur.comEmail : contact@abhisheksur.com

.NET Infrastructure

User InterfaceASP.NET

(Web Forms, MVC,

Dynamic Data)

Windows Presentation Foundation

Win Forms

Core

Services

Base Class Library

Common Language Runtime

Windows Workflow

Foundation

Windows Communicati

on Foundation

Data Access

Entity Framework

LINQ

ADO.NET

LINQ to SQL

Dynamic Async

Data Services (ODATA)

Generics

Cloud

Objects

Agenda

Language GEMS

Iterators

Delegates

Events

Generics

Extension Methods

LINQ

Dynamic Types

Async

What are loops ? A repetition of instructions ? A logical jump in code Or a representation of GoTo with a

condition…Types of Loops While do-while for goto ?... Lets take an example

Iterators in .NET Represented by IEnumerable and

IEnumerator (which is not a collection) Ability to Pause – Resume a method. foreach is a syntactic sugar to iterate over

an iterator. Yield is used to generate an iterator

Iterators

Demo

Delegates Delegates are special types Delegate points to Methods MulticastDelegates maintains an Invocation

List

Events Events are Wrappers to Delegates Cleaner pattern to handle Delegates Allows components to subscribe to it by

passing event handlers.

Delegates & Events

Demo

Generics Type as Template Constraint on Generic Types It can be applied on Types, Method,

Delegates etc. Variance is supportedExtension Methods Extend your predefined Types without

inheritance Uses ExtensionAttribute to identify extension

method.

Generics & Extension Methods

Demo

Anonymous Language Object

LINQ

Object can exist in language without name Cleaner codebase. Anonymous methods are used as Closures. We use delegate to refer anonymous

methods and var for types.

Search inside Managed objects Simple projection, selection, grouping, joins

and many more…

Anonymous Types & LINQ

Demo

Dynamic in .NET 4.0 CLR is mostly static type

◦ Compile time type checking DLR added dynamism to .NET

◦ Run time type checking Object – Static type, base class var – is ALSO static type, compiler inferred dynamic – Evaluation deferred Expandable objects

Dynamic

Demo

New Asynchronous Pattern

Contextual async & await pattern simplifies complex Threading model or existing pattern of coding

Async is not about Concurrency but rather it is truly asynchrony.

It can easily plugged in without changing the logic.

Compiler generates state machine to resume methods

Async & Await

Demo

Exposing the Compiler Ability to run compiler as a service. Syntax tree, Binder, Expression all are

available through code.

Thank you.Twitter : @abhi2434Email: contact@abhisheksur.comwww.abhisheksur.com

Abhishek Sur, MVP (Client App Dev)

top related