Lo Mejor Del Pdc2008 El Futrode C#

Post on 26-Aug-2014

1.557 views 32 download

Tags:

description

Presentación del Futuro del lenguaje C#

Transcript of Lo Mejor Del Pdc2008 El Futrode C#

Juan Pablo SchmiedeC# MVPjschmiede@hotmail.comhttp://jschmiede.spaces.live.comHBH Sistemas Ltda.

Juan Pablo GarcíaSolution Architect MVPhttp://liarjo.spaces.live.comjuanpablo.garcia@datco.clDatco

C# 1.0

C# 2.0

Código manejado

Generics

class Programclass Program{{ static IEnumerable<int> Range(int start, int count) {static IEnumerable<int> Range(int start, int count) { for (int i = 0; i < count; i++) for (int i = 0; i < count; i++) yield returnyield return start + i; start + i; }}

static IEnumerable<int> Squares(IEnumerable<int> source) {static IEnumerable<int> Squares(IEnumerable<int> source) { foreach (int x in source) foreach (int x in source) yield returnyield return x * x; x * x; }}

static void Main() {static void Main() { foreach (int i in Squares(Range(0, 10))) Console.WriteLine(i);foreach (int i in Squares(Range(0, 10))) Console.WriteLine(i); }}}}

00114499161625253636494964648181

C# 1.0

C# 2.0

C# 3.0

Código manejado

Generics

Language Integrated Query (Linq)

var contacts = from c in customers where c.State == "WA" select new { c.Name, c.Phone };

var contacts = customers .Where(c => c.State == "WA") .Select(c => new { c.Name, c.Phone });

Métodos de Extención

Expreciones Lambda

Query expressions

Inicializadores de Objetos

Tipos Anónimos

Inferencia de tipos en

variables locales

Expression Trees

Propiedades Automáticas

Métodos Parciales

Qué

Cómo

Imperativo Declarativo

C# 1.0

C# 2.0

C# 3.0

Código manejado

Generics

Language Integrated Query

C# 4.0Programación dinámica

PythonPythonBinderBinder

RubyRubyBinderBinder

COMCOMBinderBinder

JavaScriptJavaScriptBinderBinder

ObjectObjectBinderBinder

Dynamic Language Runtime

Expression TreesExpression Trees Dynamic DispatchDynamic Dispatch Call Site CachingCall Site Caching

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

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);

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

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

Estáticamente tipado para ser

dinámico

Invocación dinámica de

métodos

Conversión dinámica

dynamic x = 1;dynamic y = "Hello";dynamic z = new List<int> { 1, 2, 3 };

En tiempo de compilación

dynamic

En Tiempo de ejecución

System.Int32

Cuando los operandos son dynamic…• La selección de miembros es diferida al timepo de ejecución• En tiempo de ejecución, los tipos reales son sustituidos por dynamic• El resultado estático de la operación es dynamic

public static class Math{ public static decimal Abs(decimal value); public static double Abs(double value); public static float Abs(float value); public static int Abs(int value); public static long Abs(long value); public static sbyte Abs(sbyte value); public static short Abs(short value); ...}

double x = 1.75;double y = Math.Abs(x);

dynamic x = 1.75;dynamic y = Math.Abs(x);

Método elegido en tiempo de

compilación:double Abs(double x)

Método elegido en tiempo de ejecución: double Abs(double

x)

dynamic x = 2;dynamic y = Math.Abs(x);

Método elegido en tiempo de ejecución:

int Abs(int x)

public StreamReader OpenTextFile( string path, Encoding encoding, bool detectEncoding, int bufferSize);

public StreamReader OpenTextFile( string path, Encoding encoding, bool detectEncoding);

public StreamReader OpenTextFile( string path, Encoding encoding);

public StreamReader OpenTextFile( string path);

Método primario

Sobrecarga secundaria

Llama al primario con valores por defecto

public StreamReader OpenTextFile( string path, Encoding encoding, bool detectEncoding, int bufferSize);

public StreamReader OpenTextFile( string path, Encoding encoding = null, bool detectEncoding = true, int bufferSize = 1024);

Parámetros opcionales

OpenTextFile("foo.txt", Encoding.UTF8);OpenTextFile("foo.txt", Encoding.UTF8, bufferSize: 4096);

Argumentos por nombre

OpenTextFile( bufferSize: 4096, path: "foo.txt", detectEncoding: false);

Argumentos por nombre al final

Los no opcionales deben ser

especificados

Los Argumentos son evaluados en el

orden que se escriben

Argumentos por nombre pueden

aparecer desorden

object fileName = "Test.docx";object missing = System.Reflection.Missing.Value;

doc.SaveAs(ref fileName, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);

doc.SaveAs("Test.docx");

public abstract class DynamicObject : IDynamicObject{ public virtual object GetMember(GetMemberBinder info); public virtual object SetMember(SetMemberBinder info, object value); public virtual object DeleteMember(DeleteMemberBinder info);  public virtual object UnaryOperation(UnaryOperationBinder info); public virtual object BinaryOperation(BinaryOperationBinder info, object arg); public virtual object Convert(ConvertBinder info);  public virtual object Invoke(InvokeBinder info, object[] args); public virtual object InvokeMember(InvokeMemberBinder info, object[] args); public virtual object CreateInstance(CreateInstanceBinder info, object[] args);  public virtual object GetIndex(GetIndexBinder info, object[] indices); public virtual object SetIndex(SetIndexBinder info, object[] indices, object value); public virtual object DeleteIndex(DeleteIndexBinder info, object[] indices);  public MetaObject IDynamicObject.GetMetaObject();}

C# 1.0

C# 2.0

C# 3.0

Managed Code

Generics

Language Integrated Query

C# 4.0Dynamic Programming

© 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market

conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.