Net 4 Features that Every developer should know


Published on

Here I have demonstrated the things that are included in .NET framework 4.0 which includes the basic architecture, Co-variance and Contra-Variance, New Types , MEF, Parallel Extension, Code - Contract, Dynamic Capability, Optional Parameters etc.

Published in: Technology
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Net 4 Features that Every developer should know

  1. 1. .NET 4.0 Enhancements that Every developer should know…<br />By Abhishek Sur<br />Website:<br />Email :<br />
  2. 2. .NET Framework 4.0<br />User Interface<br />Data Access<br />Services<br />ASP.NET<br />(WebForms, MVC, Dynamic Data)<br />Windows Presentation Foundation<br />Windows Workflow Foundation<br />Entity Framework<br />ADO.NET<br />Windows Communication Foundation<br />WinForms<br />LINQ to SQL<br />Data Services <br />(ODATA)<br />Core<br />Base Class Library<br />Dynamic Language Runtime<br />Languages<br />Managed Extensibility Framework<br />LINQ<br />Parallel Extensions<br />Common Language Runtime<br />
  3. 3. Agenda<br />
  4. 4. Language Enhancements<br />
  5. 5. Named / Optional Parameters.<br />Long number of Parameter lists.<br />Most of them are not regularly used.<br />Developer needs to supply default values<br />Heavy use of Type.Missing<br />Comma counting is a pain<br />Difficult to remember parameters by position<br />
  6. 6. Overload Of Overloads<br />
  7. 7. Optional Parameters<br />Named Parameter<br />
  8. 8. Dynamic in .NET 4.0<br />CLR is mostly static type<br />Compile time type checking <br />DLR added dynamism to .NET<br />Run time type checking<br />DLR is now part of .NET 4.0 API<br />Full support of IronRuby, IronPython<br />
  9. 9. Dynamic Data Type<br />Isnt Object type dynamic already?<br />.NET already has var, why add dynamic?<br />Object – Static type, base class<br />var – is ALSO static type, compiler inferred <br />dynamic – Evaluation deferred <br />Build your own IDynamicObject<br />
  10. 10. Demo<br />Dynamic Dispatch<br />
  11. 11. Variance<br />Covariance<br />Similar to base reference to derived class<br />Covariance is applied to arrays, delegates<br />Should be used in output positions<br />Contravariance<br />Similar to derived instance passed to base<br />Should be used in input positions<br />
  12. 12. Demo<br />Variance<br />
  13. 13. New Data Types<br />
  14. 14. New DataTypes<br />BigInteger<br />Can work with any numbers<br />ComplexNumber<br />Complex number implementation (real /imaginary)<br />Tuple<br />Generic implementation of record<br />Lazy<br />Implementation of Lazy initializer<br />SortedSet<br />Combination of SortedList and HashSet<br />
  15. 15. Demo<br />Data Types<br />
  16. 16. Framework Enhancements<br />
  17. 17. Managed Extensibility Framework<br />Create reusable components<br />Don’t we already have reusable components?<br />No need to create infrastructure from scratch<br />MEF is dynamically composed<br />What’s so dynamic about it<br />Current plugin model tied to specific apps<br />Same component cannot be used across apps<br />Discoverable at runtime<br />Tagging for rich queries and filtering<br />
  18. 18. MEF Architecture<br />Catalog<br />CustomExportProvider<br />CatalogExportProvider<br />AggregatingExportProvider<br />CompositionContainer<br />Part<br />Part<br />Part<br />Export<br />Import<br />Export<br />Import<br />Export<br />Import<br />
  19. 19. MEF <br />Catalog<br />Discovers and maintain extensions<br />CompositionContainer<br />Coordinate creations and satisfy dependencies<br />ComposablePart<br />Are Imports and Exports that are composable to the Container<br />
  20. 20. Demo<br />Managed Extensibility Framework<br />
  21. 21. Parallelism in .NET 4.0<br />Don’t we have multithreading and ThreadPool?<br />Requires too much work<br />Requires understanding of nitty-gritties <br />Bifurcated thinking for single CPU vs. multi<br />What does parallelism bring in?<br />Make multicore programming simple<br />Automatcially handle single vs. multicore<br />Focus on “what” rather than “how”<br />
  22. 22. Parallels in .NET <br />Task Parallel Library (TPL)<br />Task and Data Parallelism<br />LINQ to Parallel (PLINQ)<br />Use LINQ to implement parallelism on queries<br />Coordinated Data Structures<br />High performance collection classes which are lock free and thread safe<br />BlockingCollection, ConcurrentCollectionetc<br />
  23. 23. Task Parallel Library<br />Write code which automatically uses multicore<br />Expose potential parallelism in sequential code<br />No language extension (aka Syntactic sugar) yet<br />Parallelism types<br />The Task Class – Task Parallelism<br />The Parallel Class – Data Parallelism<br />
  24. 24. Demo<br />Parallel Framework<br />
  25. 25. Code Contracts<br />Foundation<br />Design by contract<br />Based on MSR’s SPEC# (Pre/Post/Invariants)<br />What does it bring?<br />Improved testability<br />Static verification<br />How does it help?<br />Guarantee obligations on entry (parameter validations)<br />Guarantee property at exit (return value range)<br />Maintain property during execution (object invariance)<br />
  26. 26. Code Contracts(continues…)<br />New namespace in .NET<br />System.Diagnostics.Contracts<br />Parameter validation<br />Contract.Requires()<br />Return value guarantee<br />Contract.Ensures()<br />Object state guarantee<br />Contract.Invariant()<br />
  27. 27. Demo<br />Code Contracts<br />
  28. 28. Questions / Answers<br />
  29. 29. References<br />.NET 4.0 Features<br /><br /><br />Data Types<br /><br />MEF<br /><br />Code Contract<br /><br />
  30. 30. Abhishek Sur, MVP (Client App Dev)<br /><br />Email:<br />Twitter : @abhi2434<br />Thank you.<br />