Lo Mejor Del Pdc2008 El Futrode C#

33
Juan Pablo Schmiede C# MVP [email protected] http://jschmiede.space s.live.com Juan Pablo García Solution Architect MVP http://liarjo.spaces.l ive.com juanpablo.garcia@datco .cl Datco

description

Presentación del Futuro del lenguaje C#

Transcript of Lo Mejor Del Pdc2008 El Futrode C#

Page 1: Lo Mejor Del Pdc2008 El Futrode C#

Juan Pablo SchmiedeC# [email protected]://jschmiede.spaces.live.comHBH Sistemas Ltda.

Juan Pablo GarcíaSolution Architect MVPhttp://[email protected]

Page 2: Lo Mejor Del Pdc2008 El Futrode C#

C# 1.0

C# 2.0

Código manejado

Generics

Page 3: Lo Mejor Del Pdc2008 El Futrode C#
Page 4: Lo Mejor Del Pdc2008 El Futrode C#
Page 5: Lo Mejor Del Pdc2008 El Futrode C#

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

Page 6: Lo Mejor Del Pdc2008 El Futrode C#

C# 1.0

C# 2.0

C# 3.0

Código manejado

Generics

Language Integrated Query (Linq)

Page 7: Lo Mejor Del Pdc2008 El Futrode C#
Page 8: Lo Mejor Del Pdc2008 El Futrode C#

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

Page 9: Lo Mejor Del Pdc2008 El Futrode C#
Page 10: Lo Mejor Del Pdc2008 El Futrode C#
Page 11: Lo Mejor Del Pdc2008 El Futrode C#

Qué

Cómo

Imperativo Declarativo

Page 12: Lo Mejor Del Pdc2008 El Futrode C#
Page 13: Lo Mejor Del Pdc2008 El Futrode C#
Page 14: Lo Mejor Del Pdc2008 El Futrode C#
Page 15: Lo Mejor Del Pdc2008 El Futrode C#

C# 1.0

C# 2.0

C# 3.0

Código manejado

Generics

Language Integrated Query

C# 4.0Programación dinámica

Page 16: Lo Mejor Del Pdc2008 El Futrode C#
Page 17: Lo Mejor Del Pdc2008 El Futrode C#

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…

Page 18: Lo Mejor Del Pdc2008 El Futrode C#

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

Page 19: Lo Mejor Del Pdc2008 El Futrode C#

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

Page 20: Lo Mejor Del Pdc2008 El Futrode C#

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)

Page 21: Lo Mejor Del Pdc2008 El Futrode C#
Page 22: Lo Mejor Del Pdc2008 El Futrode C#

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

Page 23: Lo Mejor Del Pdc2008 El Futrode C#

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

Page 24: Lo Mejor Del Pdc2008 El Futrode C#

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

Page 25: Lo Mejor Del Pdc2008 El Futrode C#
Page 26: Lo Mejor Del Pdc2008 El Futrode C#

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

Page 27: Lo Mejor Del Pdc2008 El Futrode C#
Page 28: Lo Mejor Del Pdc2008 El Futrode C#

C# 1.0

C# 2.0

C# 3.0

Managed Code

Generics

Language Integrated Query

C# 4.0Dynamic Programming

Page 29: Lo Mejor Del Pdc2008 El Futrode C#
Page 30: Lo Mejor Del Pdc2008 El Futrode C#
Page 31: Lo Mejor Del Pdc2008 El Futrode C#
Page 32: Lo Mejor Del Pdc2008 El Futrode C#

© 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.

Page 33: Lo Mejor Del Pdc2008 El Futrode C#