[CLPE] Novidades do .net Framework 4.0

Preview:

DESCRIPTION

 

Citation preview

Novidades do .NET Framework 4e C# 4.0

“Keep it simple”

Quem sou?

• Felipe Pimentel• MCP, MCTS e MCPD• Sócio e fundador da Ificomm Tecnologia • Arquiteto e consultor.• Líder do DotNetArchitects PE

Contatos

• Twitter: http://twitter.com/felipe_pimentel• Email: felipe.pimentel@ificomm.com• Blog: http://blog.ificomm.com• Grupo: http://pe.dotnetarchitects.net

Novidades não faltam

• ASP.NET WebForm• ASP.NET MVC• Mudanças na CLR, C# e VB • Data Access• Serviços • WorkFlows• WPF• MEF• ...

Agenda

• Code Contract• MEF – Managed Extensibily Framework• DLR – Dynamic Language Runtime• Parallel Extension• Principais novidades no C# 4.0

A Look Back…

.NET 1.0.NET 1.0 .NET 1.1.NET 1.1 .NET 2.0.NET 2.0

3.03.03.53.5

.NET 4.NET 4

2002 2003 2008 CTP2005-08

CLR 1.0CLR 1.0 CLR 1.1CLR 1.1 CLR 2.0CLR 2.0 CLR 4CLR 4

SP1SP1

The .NET Framework

Base Class LibrariesBase Class Libraries

The CLRJIT & NGENJIT & NGEN

Garbage CollectorGarbage Collector

Security Model

Security Model

Exception HandlingException Handling

Loader & Binder

Loader & Binder

WPFWPF Win FormsWin

Forms DLRDLR ASP.NET

ASP.NET WCFWCF And

more!And

more!LINQLINQ

Code Contract

• O que é garantido? (Pré-condição)• O que é esperado? (Pós-condição)• O que muda? (Invariante)

Code Contract

Code Contract

Managed Extensibility Framework?

Framework de extensibilidade – para criação de um sistema de plugins. Plugins que podem ser usados em qualquer aplicação.

The Problem…

Original SoftwareDevelopment

SoftwareMaintenance

Open/Closed Principle

Aberto para extensões e fechados para modificações.

Dinamicamente composta ao invés de ser estaticamente compilada

The Parallel Computing Initiative

Resolvendo problemas de maneira concorrente

“Concurrency for the masses”

Parallel Computing with .NET 4

1. Task Parallel Library (TPL)

2. Parallel LINQ (PLINQ)

3. Coordination Data Structures (CDS)

4. System.Threading Improvements

Parallel LINQ

Parallel LINQ (PLINQ) enables developers to easily leverage manycore with a minimal impact to existing LINQ programming model

var q = from p in people        where p.Name == queryInfo.Name && p.State == queryInfo.State && p.Year >= yearStart && p.Year <= yearEnd        orderby p.Year ascending        select p;

var q = from p in people        where p.Name == queryInfo.Name && p.State == queryInfo.State && p.Year >= yearStart && p.Year <= yearEnd        orderby p.Year ascending        select p;

Parallel Static Class

Parallel Static Class

Threading Task

Why the DLR?

Common Language RuntimeCommon Language Runtime

Statically-Typed

C#C#VBVB

RubyRubyPythonPython

Dynamically-Typed

Why the DLR?

Common Language RuntimeCommon Language Runtime

Statically-Typed

C#C#VBVB

RubyRubyPythonPython

Dynamically-Typed

Dynamic Language RuntimeDynamic Language Runtime

.NET Dynamic Programming

PythonBinderPythonBinder

RubyBinderRuby

BinderCOM

BinderCOM

BinderJScriptBinderJScriptBinder

ObjectBinderObjectBinder

Dynamic Language RuntimeDynamic Language Runtime

Expression TreesExpression TreesExpression TreesExpression Trees Dynamic DispatchDynamic DispatchDynamic DispatchDynamic Dispatch Call Site CachingCall Site CachingCall Site CachingCall Site Caching

IronPythonIronPython IronRubyIronRuby C#C# VB.NETVB.NET Others…Others…

Dynamically Typed Objects

Calculator calc = GetCalculator();int sum = calc.Add(10, 20);Calculator calc = GetCalculator();int sum = calc.Add(10, 20);

object calc = GetCalculator();Type calcType = calc.GetType();object res = calcType.InvokeMember("Add", BindingFlags.InvokeMethod, null, new object[] { 10, 20 });int sum = Convert.ToInt32(res);

object calc = GetCalculator();Type calcType = calc.GetType();object res = calcType.InvokeMember("Add", BindingFlags.InvokeMethod, null, new object[] { 10, 20 });int sum = Convert.ToInt32(res);

ScriptObject calc = GetCalculator();object res = calc.Invoke("Add", 10, 20);int sum = Convert.ToInt32(res);

ScriptObject calc = GetCalculator();object res = calc.Invoke("Add", 10, 20);int sum = Convert.ToInt32(res);

dynamic calc = GetCalculator();int sum = calc.Add(10, 20);

dynamic calc = GetCalculator();int sum = calc.Add(10, 20);

Statically typed to be dynamic

Statically typed to be dynamic

Dynamic method invocation

Dynamic method invocation

Dynamic conversion

Dynamic conversion

.NET Framework Compatibility

.NET Framework Compatibility

• .NET 4.0 is a highly compatible release• .NET 4.0 does not auto–roll forward

– You must add a configuration file with a specific switch to get 3.5 apps to run on 4.0

.NET Framework Compatibility

Hang on… if 4.0 is compatible, why not run 3.5 apps automatically on 4.0?–The BEST thing is always to prefer running on the version of the framework you built against

• Contact netfxcf@microsoft.com and submit your app for testing!

CLR 2 - Existing Side-By-Side

Host Process (i.e. Outlook)Host Process (i.e. Outlook)

.NET 2.0.NET 2.0

2.0 add-in

2.0 add-in

3.03.0

3.53.5

3.0 add-in

3.0 add-in

3.5 add-in

3.5 add-in

1.1 add-in

1.1 add-in

.NET 1.1.NET 1.1

CLR 4 - In-Process Side-By-Side

.NET 2.0.NET 2.0.NET 4.0.NET 4.0

2.0 add-in

2.0 add-in

3.03.0

3.53.5

Host Process (i.e. Outlook)Host Process (i.e. Outlook)

3.0 add-in

3.0 add-in

3.5 add-in

3.5 add-in

4.0 add-in

4.0 add-in

NOVIDADES DO C# 4.0

The Evolution of C#

C# 1.0C# 1.0

C# 2.0C# 2.0

C# 3.0C# 3.0

Managed Code

Generics

LINQ

C# 4.0C# 4.0

Dynamic

New C# 4.0 Features

1. Named and Optional Parameters

New C# 4.0 Features

• Covariance and Contravariance

Covariance

Contravariance

Dinamismo em C#

Tipo dynamic

• Resolução dinâmica de métodos, propriedades e eventos (em tempo de execução)

• Não efetua validação estática

ExpandoObject

• Permite criar novos objetos em tempo de execução

DynamicObject

• Facilita criação de classes dinâmicas

Contatos

• Twitter: http://twitter.com/felipe_pimentel• Email: felipe.pimentel@ificomm.com• Blog: http://blog.ificomm.com• Grupo: http://pe.dotnetarchitects.net

Dúvidas?

Obrigado!!!