lo mejor del pdc2008 el futrode c#

Download Lo Mejor Del Pdc2008 El Futrode C#

If you can't read please download the document

Post on 26-Aug-2014

1.555 views

Category:

Technology

32 download

Embed Size (px)

DESCRIPTION

Presentación del Futuro del lenguaje C#

TRANSCRIPT

    • Juan Pablo Schmiede
    • C# MVP
    • [email_address]
    • http://jschmiede.spaces.live.com
    • HBH Sistemas Ltda.
    • Juan Pablo Garca
    • Solution Architect MVP
    • http://liarjo.spaces.live.com
    • [email_address]
    • Datco
  • C# 1.0 C# 2.0 Cdigo manejado Generics
  • class Program { static IEnumerable Range(int start, int count) { for (int i = 0; i < count; i++) yield return start + i; } static IEnumerable Squares(IEnumerable source) { foreach (int x in source) yield return x * x; } static void Main() { foreach (int i in Squares(Range(0, 10))) Console.WriteLine(i); } } 0 1 4 9 16 25 36 49 64 81
  • C# 1.0 C# 2.0 C# 3.0 Cdigo 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 }); Mtodos de Extencin Expreciones Lambda Query expressions Inicializadores de Objetos Tipos Annimos Inferencia de tipos en variables locales Expression Trees Propiedades Automticas Mtodos Parciales
  • Qu Cmo Imperativo Declarativo
  • C# 1.0 C# 2.0 C# 3.0 Cdigo manejado Generics Language Integrated Query C# 4.0 Programacin dinmica
  • Python Binder Ruby Binder COM Binder JavaScript Binder Object Binder Dynamic Language Runtime Expression Trees Dynamic Dispatch Call Site Caching IronPython IronRuby C# VB.NET 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); Estticamente tipado para ser dinmico Invocacin dinmica de mtodos Conversin dinmica
  • dynamic x = 1; dynamic y = "Hello" ; dynamic z = new List < int > { 1, 2, 3 }; En tiempo de compilacin dynamic En Tiempo de ejecucin System.Int32
    • Cuando los operandos son dynamic
    • La seleccin de miembros es diferida al timepo de ejecucin
    • En tiempo de ejecucin, los tipos reales son sustituidos por dynamic
    • El resultado esttico de la operacin 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); Mtodo elegido en tiempo de compilacin: double Abs(double x) Mtodo elegido en tiempo de ejecucin : double Abs(double x) dynamic x = 2; dynamic y = Math .Abs(x); Mtodo elegido en tiempo de ejecucin : 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); Mtodo 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); Parmetros 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(); }
  • void Process( object [] objects) { } string [] strings = GetStringArray(); Process(strings); void Process( object [] objects) { objects[0] = "Hello" ; // Ok objects[1] = new Button (); // Exception! } List < string > strings = GetStringList(); Process(strings); void Process( IEnumerable < object > objects) { } .NET arrays are co-variant but not safely co-variant Until now, C# generics have been invariant void Process( IEnumerable < object > objects) { // IEnumerable is read-only and // therefore safely co-variant } C# 4.0 supports safe co- and contra-variance
  • public interface IEnumerable { IEnumerator GetEnumerator(); } public interface IEnumerator { T Current { get ; } bool MoveNext(); } public interface IEnumerable < out T> { IEnumerator GetEnumerator(); } public interface IEnumerator < out T> { T Current { get ; } bool MoveNext(); } out = Co-variant Output positions only IEnumerable < string > strings = GetStrings(); IEnumerable < object > objects = strings; Can be treated as less derived public interface IComparer { int Compare(T x, T y); } public interface IComparer < in T> { int Compare(T x, T y); } IComparer < object > objComp = GetComparer(); IComparer < string > strComp = objComp; in = Contra-variant Input positions only Can be treated as more derived
      • System.Collections.Generic.IEnumerable
      • System.Collections.Generic.IEnumerator
      • System.Linq.IQueryable
      • System.Collections.Generic.IComparer
      • System.Collections.Generic.IEqualityComparer
      • System.IComparable
    Interfaces
      • System.Func
      • System.Action
      • System.Predicate
      • System.Comparison
      • System.EventHandler
    Delegates
  • C# 1.0 C# 2.0 C# 3.0 Managed Code Generics Language Integrated Query C# 4.0 Dynamic Programming
  • Source code Source code Source File Source code Source code .NET Assembly Meta-programming Read-Eval-Print Loop Language Object Model DSL Embedding Compiler Compiler Class Field public Foo private string X
  • Please fill out your evaluation for this session at: This session will be available as a recording at: www.microsoftpdc.com
  • 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vis