Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Lo Mejor Del Pdc2008 El Futrode C#

976 views

Published on

Presentación del Futuro del lenguaje C#

Published in: Technology, Travel
  • Be the first to comment

  • Be the first to like this

Lo Mejor Del Pdc2008 El Futrode C#

  1. 1. <ul><li>Juan Pablo Schmiede </li></ul><ul><li>C# MVP </li></ul><ul><li>[email_address] </li></ul><ul><li>http://jschmiede.spaces.live.com </li></ul><ul><li>HBH Sistemas Ltda. </li></ul><ul><li>Juan Pablo García </li></ul><ul><li>Solution Architect MVP </li></ul><ul><li>http://liarjo.spaces.live.com </li></ul><ul><li>[email_address] </li></ul><ul><li>Datco </li></ul>
  2. 2. C# 1.0 C# 2.0 Código manejado Generics
  3. 5. class Program { static IEnumerable<int> Range(int start, int count) { for (int i = 0; i < count; i++) yield return start + i; } static IEnumerable<int> Squares(IEnumerable<int> 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
  4. 6. C# 1.0 C# 2.0 C# 3.0 Código manejado Generics Language Integrated Query (Linq)
  5. 8. var contacts = from c in customers where c.State == &quot;WA&quot; select new { c.Name, c.Phone }; var contacts = customers .Where(c => c.State == &quot;WA&quot;) .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
  6. 11. Qué Cómo Imperativo Declarativo
  7. 15. C# 1.0 C# 2.0 C# 3.0 Código manejado Generics Language Integrated Query C# 4.0 Programación dinámica
  8. 17. 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…
  9. 18. Calculator calc = GetCalculator(); int sum = calc.Add(10, 20); object calc = GetCalculator(); Type calcType = calc.GetType(); object res = calcType.InvokeMember( &quot;Add&quot; , BindingFlags.InvokeMethod, null , new object [] { 10, 20 }); int sum = Convert.ToInt32(res); ScriptObject calc = GetCalculator(); object res = calc.Invoke( &quot;Add&quot; , 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
  10. 19. dynamic x = 1; dynamic y = &quot;Hello&quot; ; dynamic z = new List < int > { 1, 2, 3 }; En tiempo de compilación dynamic En Tiempo de ejecución System.Int32 <ul><li>Cuando los operandos son dynamic … </li></ul><ul><li>La selección de miembros es diferida al timepo de ejecución </li></ul><ul><li>En tiempo de ejecución, los tipos reales son sustituidos por dynamic </li></ul><ul><li>El resultado estático de la operación es dynamic </li></ul>
  11. 20. 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)
  12. 22. 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
  13. 23. 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( &quot;foo.txt&quot; , Encoding .UTF8); OpenTextFile( &quot;foo.txt&quot; , Encoding .UTF8, bufferSize: 4096); Argumentos por nombre OpenTextFile( bufferSize: 4096, path: &quot;foo.txt&quot; , 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
  14. 24. object fileName = &quot;Test.docx&quot; ; 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( &quot;Test.docx&quot; );
  15. 26. 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(); }
  16. 29. void Process( object [] objects) { … } string [] strings = GetStringArray(); Process(strings); void Process( object [] objects) { objects[0] = &quot;Hello&quot; ; // 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<T> is read-only and // therefore safely co-variant } C# 4.0 supports safe co- and contra-variance
  17. 30. public interface IEnumerable <T> { IEnumerator <T> GetEnumerator(); } public interface IEnumerator <T> { T Current { get ; } bool MoveNext(); } public interface IEnumerable < out T> { IEnumerator <T> 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 <T> { 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
  18. 32. <ul><ul><li>System.Collections.Generic.IEnumerable<out T> </li></ul></ul><ul><ul><li>System.Collections.Generic.IEnumerator<out T> </li></ul></ul><ul><ul><li>System.Linq.IQueryable<out T> </li></ul></ul><ul><ul><li>System.Collections.Generic.IComparer<in T> </li></ul></ul><ul><ul><li>System.Collections.Generic.IEqualityComparer<in T> </li></ul></ul><ul><ul><li>System.IComparable<in T> </li></ul></ul>Interfaces <ul><ul><li>System.Func<in T, …, out R> </li></ul></ul><ul><ul><li>System.Action<in T, …> </li></ul></ul><ul><ul><li>System.Predicate<in T> </li></ul></ul><ul><ul><li>System.Comparison<in T> </li></ul></ul><ul><ul><li>System.EventHandler<in T> </li></ul></ul>Delegates
  19. 33. C# 1.0 C# 2.0 C# 3.0 Managed Code Generics Language Integrated Query C# 4.0 Dynamic Programming
  20. 34. 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
  21. 38. Please fill out your evaluation for this session at: This session will be available as a recording at: www.microsoftpdc.com
  22. 40. © 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.

×