overview of .net 4.0 sanjay vyas
DESCRIPTION
TRANSCRIPT
.NET Framework 4.0Differentiated
User Experience
Silverlight - cutting edge RIAs
Exploit Windows 7 and Office
Better support for standards based web experiences
Extend the .NET
Continuum
Consistent programming model across Client, Server, RIA
Dev + Designer collaboration
Superior Developer
Productivity
Network support and managed
services
Testability becomes mainstream
N-tier apps are as easy to build as one tier applications
Platform and process transparency
Deep Investments in
the Core
Agility and deployment flexibility
Managing .NET deployments is simpleCore server platform advances
Core client platform advances
.NET Framework Current "Layer Cake"
.NET Framework 2.0 + SP1
Windows Presentation Foundation
Windows Communication
Foundation
Windows Workflow
Foundation
Windows CardSpace
.NET Framework 3.0 + SP1
.NET Framework 3.5
LINQ WF & WCF Enhancements
Add-in Framework
Additional Enhancements
.NET Framework 3.5 + SP1
MVC Dynamic Data Entity Framework Data Services
Core
Services
.NET Framework 4.0
Base Class Library
Common Language Runtime
Windows Workflow
Foundation
Managed Extensibility Framework
Data ServicesWindows
Communication Foundation
“Velocity”
User Interface
Windows Presentation Foundation
ASP.NET(WebForms, MVC,
Dynamic Data)
Data Access
Entity Framework
LINQ
ADO.NET
Parallel Extensions
WinForms LINQ to SQL
LanguagesDynamic Language
Runtime
Whats New In Base Class Library
•Declaration & consumption of extensibility points•Monitoring for new runtime extension
Managed Extensibility Framework
•BigInteger•ComplexNumber•Tuple•SortedSet
New Data Types
•Memory Mapped Files•Unified Cancelling Model
I/O Improvements
Managed Extensibility Framework
Create reusable componentsDon’t we already have reusable components?
No need to create infrastructure from scratchMEF is dynamically composed
What’s so dynamic about itCurrent plugin model tied to specific appsSame component cannot be used across appsDiscoverable at runtimeTagging for rich queries and filtering
MEF Architecture
MEF
CatalogDiscovers and maintain extensions
CompositionContainerCoordinate creations and satisfy dependencies
ComposablePartOffer on or more exportsMay depend on imports for extension it uses
Managed Extensibiity FrameworkDemo
New Language Features
C# 4.0Named ParametersOptional ParametersDynamic Scoping
Generic VarianceExtension Property
VB.NET 10
Statement LambdasMultiline LambdasAuto implemented PropertiesCollection Initializ erGeneric VarianceExtension Property
Optional and Named Parameter
Some methods have excessive parametersToo many overloads of methodsMost aren’t used in everyday scenarioDevelopers still have to supply default valuesHeavy use of Type.MissingComma counting is a painDifficult to remember parameter by position
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 }}
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
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);
Dynamic scoping
C# is static type languagesTypes are explicitly definedMethods are bound at runtime
Dynamic dispatch existsReflection APIMethod.Invoke() is tedious
COM Automation is based on IDispatchMay not have .TLBLookup can be purely runtime
Certain Application Types require DynamismE.g. SOAP/REST proxies
Dynamic in .NET 4.0
CLR is mostly static typeCompile time type checking (e.g. IUnknown)
DLR added dynamism to .NETRun time type checking (e.g. IDispatch)
DLR is now part of .NET 4.0 APIFull support of IronRuby, IronPythonDynamic dispatch now built into .NET/C#
Dynamic Dispatch
Introduction of type – dynamicCompiler merely packages informationCompiler defers binding to runtime
Built-in support for COM CallsUses IDispatch interfacePIA not required
Runtime binding for framework objectsBuild your own – IDynamicObject
IronPython, IronRuby use thisE.g. RestProxy
Dynamic Data Type
Isnt Object type dynamic already?.NET already has var, why add dynamic?
Object – Static type, base classvar – is ALSO static type, compiler inferred dynamic – Evaluation deferred
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
Dynamic DispatchDemo
Variance
CovarianceSimilar to base reference to derived classCovariance is applied to arrays, delegates..
ContravarianceSimilar to derived instance passed to base
Changes to Variance
Variance can now be applied to InterfacesVariant types supports interfaces and delegatesVariance applies to reference conversion onlyValue types are not supported
CovarianceRequires the use of “out” keyword
ContravariantRequires the use of “in” keyword
It could be automatically inferred but that could lead to code-breaking when interface definition changes
VarianceDemo
Code Contracts
FoundationDesign by contractBased on MSR’s SPEC#
What does it bring?Improved testabilityStatic verificationAPI Documentation
How does it help?Guarantee obligations on entry (parameter validations)Guarantee property at exit (return value range)Maintain property during execution (object invariance)
Code Contracts
New namespace in .NETSystem.Diagnostics.Contracts
Parameter validationContract.Requires()
Return value guaranteeContract.Ensures()
Object state guaranteeContract.Invariant()
Code Contracts
Compile generates the IL codeContracts are conditionally compiledDefine CONTRACTS_FULL to enable
Code ContractsDemo
Parallelism in .NET 4.0
Don’t we have multithreading and ThreadPool?Requires too much workRequires understanding of nitty-gritties Bifurcated thinking for single CPU vs. multi
What does parallelism bring in?Make multicore programming simpleAutomatcially handle single vs. multicoreFocus on “what” rather than “how”
Parallels in .NET
Task Parallel Library (TPL)Task and Data Parallelism
LINQ to Parallel (PLINQ)Use LINQ to implement parallelism on queries
Coordinated Data StructuresHigh performance collection classes which are lock free and thread safe
Parallel Diagnostic ToolsParallels Debugger and VSTS Profiler concurrency view
Task Parallel Library
Write code which automatically uses multicoreExpose potential parallelism in sequential codeNo language extension (aka Syntactic sugar) yetParallelism types
The Task Class – Task ParallelismThe Parallel Class – Data Parallelism
Task ManagementTaskManager classUse default or create your own
Task Parallel LibraryDemo