Overview Of .Net 4.0 Sanjay Vyas

1,378 views

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,378
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
56
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Overview Of .Net 4.0 Sanjay Vyas

  1. 1. Sanjay Vyas
  2. 2. .NET Framework 4.0 Network support and managed services
  3. 3. .NET Framework Current quot;Layer Cakequot; .NET Framework 3.5 + SP1 MVC Dynamic Data Entity Framework Data Services .NET Framework 3.5 WF & WCF Add-in Additional LINQ Enhancements Framework Enhancements .NET Framework 3.0 + SP1 Windows Windows Windows Workflow Windows Presentation Communication Foundation CardSpace Foundation Foundation .NET Framework 2.0 + SP1
  4. 4. .NET Framework 4.0 User Interface Services Data Access ASP.NET Windows Windows (WebForms, MVC, Presentation Data Services Communication ADO.NET Entity Framework Dynamic Data) Foundation Foundation Windows WinForms “Velocity” Workflow LINQ to SQL Foundation Core Managed Dynamic Language Parallel Extensions Extensibility LINQ Languages Base Class Library Runtime Framework Common Language Runtime
  5. 5. Whats New In Base Class Library Managed • Declaration & consumption of extensibility points Extensibility • Monitoring for new runtime extension Framework • BigInteger • ComplexNumber New Data Types • Tuple • SortedSet I/O • Memory Mapped Files Improvements • Unified Cancelling Model
  6. 6. Managed Extensibility Framework Create reusable components Don’t we already have reusable components? No need to create infrastructure from scratch MEF is dynamically composed What’s so dynamic about it Current plugin model tied to specific apps Same component cannot be used across apps Discoverable at runtime Tagging for rich queries and filtering
  7. 7. MEF Architecture
  8. 8. MEF Catalog Discovers and maintain extensions CompositionContainer Coordinate creations and satisfy dependencies ComposablePart Offer on or more exports May depend on imports for extension it uses
  9. 9. Managed Extensibiity Framework
  10. 10. New Language Features C# 4.0 VB.NET 10 Named Parameters Optional Parameters Dynamic Scoping Statement Lambdas Multiline Lambdas Auto implemented Properties Collection Initializ er Generic Variance Generic Variance Extension Property Extension Property
  11. 11. Optional and Named Parameter Some methods have excessive parameters Too many overloads of methods Most aren’t used in everyday scenario Developers still have to supply default values Heavy use of Type.Missing Comma counting is a pain Difficult to remember parameter by position
  12. 12. Overload Of Overloads class Book { // Multiple constructors Book() : this(“”, “”, “”, ) { } Book(string isbn) : this(isbn, “”, “”, 0) { } Book(string isbn, string title) : this(isbn, title, “”, 0) { } Book(string isbn, string title, string author) : this(isbn, title, author, 0) { } // Master Constructor which gets called by others Book(string isbn, string title, string author, int pages) { // Do the actual work here } }
  13. 13. Optional Parameters class Book { // Use optional parameters Book(string isbn=“”, string title=“”, string author=“”, int pages=0) { // Do the actual work here } } : : : Book book = new Book(“1-43254-333-1”); Book book = new Book(“1-43254-333-1”, “How not to code”); Book book = new Book(“1-43254-333-1”, “How not to code”, “Copy Paster”); Book book = new Book(“1-43254-333-1”, 240); // Cannot skip parameters
  14. 14. Named Parameter class Book { // Use optional parameters Book(string isbn=“”, string title=“”, string author=“”, int pages=0) { // Do the actual work here } } : : : Book book = new Book(isbn:“1-43254-333-1”); Book book = new Book(isbn:“1-43254-333-1”, title:“How not to code”); Book book = new Book(isbn:“1-43254-333-1”, title:“How not to code”, author:“Copy Paster”); Book book = new Book(isbn:“1-43254-333-1”, pages:240);
  15. 15. Dynamic scoping C# is static type languages Types are explicitly defined Methods are bound at runtime Dynamic dispatch exists Reflection API Method.Invoke() is tedious COM Automation is based on IDispatch May not have .TLB Lookup can be purely runtime Certain Application Types require Dynamism E.g. SOAP/REST proxies
  16. 16. Dynamic in .NET 4.0 CLR is mostly static type Compile time type checking (e.g. IUnknown) DLR added dynamism to .NET Run time type checking (e.g. IDispatch) DLR is now part of .NET 4.0 API Full support of IronRuby, IronPython Dynamic dispatch now built into .NET/C#
  17. 17. Dynamic Dispatch Introduction of type – dynamic Compiler merely packages information Compiler defers binding to runtime Built-in support for COM Calls Uses IDispatch interface PIA not required Runtime binding for framework objects Build your own – IDynamicObject IronPython, IronRuby use this E.g. RestProxy
  18. 18. Dynamic Data Type Isnt Object type dynamic already? .NET already has var, why add dynamic? Object – Static type, base class var – is ALSO static type, compiler inferred dynamic – Evaluation deferred
  19. 19. Dynamic implementation dynamic d = GetFlyingObject(“Superman”); d.Fly(); // Up, up and away dynamic d = GetFlyingObject(“AirPlane”); d.Fly(); // Take off dynamic d = GetFlyingObject(“Cat”); d.Fly(); // OOPS… but at runtime
  20. 20. Dynamic Dispatch
  21. 21. Variance Covariance Similar to base reference to derived class Covariance is applied to arrays, delegates.. Contravariance Similar to derived instance passed to base
  22. 22. Changes to Variance Variance can now be applied to Interfaces Variant types supports interfaces and delegates Variance applies to reference conversion only Value types are not supported Covariance Requires the use of “out” keyword Contravariant Requires the use of “in” keyword It could be automatically inferred but that could lead to code-breaking when interface definition changes
  23. 23. Variance
  24. 24. Code Contracts Foundation Design by contract Based on MSR’s SPEC# What does it bring? Improved testability Static verification API Documentation How does it help? Guarantee obligations on entry (parameter validations) Guarantee property at exit (return value range) Maintain property during execution (object invariance)
  25. 25. Code Contracts New namespace in .NET System.Diagnostics.Contracts Parameter validation Contract.Requires() Return value guarantee Contract.Ensures() Object state guarantee Contract.Invariant()
  26. 26. Code Contracts Compile generates the IL code Contracts are conditionally compiled Define CONTRACTS_FULL to enable
  27. 27. Code Contracts
  28. 28. Parallelism in .NET 4.0 Don’t we have multithreading and ThreadPool? Requires too much work Requires understanding of nitty-gritties Bifurcated thinking for single CPU vs. multi What does parallelism bring in? Make multicore programming simple Automatcially handle single vs. multicore Focus on “what” rather than “how”
  29. 29. Parallels in .NET Task Parallel Library (TPL) Task and Data Parallelism LINQ to Parallel (PLINQ) Use LINQ to implement parallelism on queries Coordinated Data Structures High performance collection classes which are lock free and thread safe Parallel Diagnostic Tools Parallels Debugger and VSTS Profiler concurrency view
  30. 30. Task Parallel Library Write code which automatically uses multicore Expose potential parallelism in sequential code No language extension (aka Syntactic sugar) yet Parallelism types The Task Class – Task Parallelism The Parallel Class – Data Parallelism Task Management TaskManager class Use default or create your own
  31. 31. Task Parallel Library

×