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.

New Features for Visual Studio 2010 / Dotnet 4.0

7,906 views

Published on

New Features for Visual Studio 2010 / Dotnet 4.0

Published in: Technology
  • Be the first to comment

  • Be the first to like this

New Features for Visual Studio 2010 / Dotnet 4.0

  1. 1. Whatis New in Visual Studio 2010 - .Net 4.0 !!!<br />By : ShahzadSarwar<br />
  2. 2. Dynamic Type<br /><ul><li>Background Theory, Difference between Static/Dynamic languages Plus Strongly typed/Weekly typed Languages[Static/Dynamic deals “When” of type checking for a language, however Strong/Week deals with “How” of type checking for a language.]
  3. 3. C# is Static and strongly typed language.
  4. 4. Type determination of “dynamic” type can be delayed till run time.
  5. 5. According to MSDN: “The type is a static type, but an object of type dynamic bypasses static type checking. In most cases, it functions like it has type object. At compile time, an element that is typed as dynamic is assumed to support any operation.”
  6. 6. Demo Code at: http://softarchitect.wordpress.com/2010/08/08/software-architecture-c-sharp-4-0-new-feature-dynamic-type/</li></li></ul><li>Dynamic Type<br />Where to use:<br />Perform so many cast operations that it makes your code almost unreadable.<br />Situations when a simple cast is not enough and needs reflection methods, such as InvokeMember or GetProperties.<br />Enable scenarios that were either impossible or difficult, including interoperation with dynamic languages. <br />Examples of Usage: <br /> COM APIs such as the Office Automation APIs<br /> Dynamic APIs such as IronPython libraries<br /> HTML Document Object Model (DOM)<br />Overload Resolution with Arguments of Type dynamic <br />Demo Code http://softarchitect.wordpress.com/2011/01/30/software-architecture-%e2%80%93-c-4-0-%e2%80%93-dynamic-type-compile-time-polymorphism-method-overloading/<br />
  7. 7. Dynamic Type<br /><ul><li>System.Dynamic namespace</li></ul>DynamicObjectClass:Provides a base class for specifying dynamic behavior at run time.<br />Demo Code:<br />http://softarchitect.wordpress.com/2011/02/26/software-architecture-dynamicobject-class-of-system-dynamic-namespace-in-c-shar-4-0/<br />ExpandoObject Class :Represents an object whose members can be dynamically added and removed at run time.<br /> Implementation of the dynamic object concept that enables getting, setting, and invoking members.<br />Demo Code:<br />http://softarchitect.wordpress.com/2011/02/26/software-architecture-expandoobject-class-of-system-dynamic-namespace-in-c-sharp-4-0/<br />
  8. 8. Tuple<br /><ul><li>Generic type that provide an option to group together different type of object in one piece.
  9. 9. Creation method via 1. Constructor 2. Static method create of System.Tuple
  10. 10. By default, eight elements, for further do nested Tuples.
  11. 11. Tuplesvs Anonymous Type1. Anonymous Type: Can’t be passed as return type from a method. Tuples can be passed as input parameters and return type.</li></ul> 2. Tuples can’t be identified with name, they are just called item1,item2,item3…itemn. However items of anonymous type can be named.<br />Demo Code: http://softarchitect.wordpress.com/2010/08/15/software-architecture-c-sharp-4-0-new-feature-tuple/<br />
  12. 12. Lazyinitialization<br /><ul><li>Backgroud, OR Mapping technologies like linq 2 sql or nhibernate, has ”Lazy loading” which suggest that a object/collection as property in a object is not created till it is accessed in the code.
  13. 13. Provided with Lazy class at System.Lazy(Of T).
  14. 14. Suggests that “an object is not created till it is used by the first time the Lazy(Of T).Value property is accessed or the Lazy(Of T).ToString method is called”
  15. 15. Demo Code:</li></ul>http://softarchitect.wordpress.com/2010/08/14/software-architecture-c-sharp-4-0-new-feature-lazy-initialization/<br />
  16. 16. Named Parameters and Optional Parameters<br /><ul><li>Named arguments enable you to specify an argument for a particular parameter by associating the argument with the parameter’s name rather than with the parameter’s position in the parameter list.
  17. 17. IntelliSense is shown for named parameters, by specifying parameters name followed by “:”
  18. 18. Each optional parameter has a default value as part of its definition.
  19. 19. Optional parameters are defined at the end of the parameter list, after any required parameters. If the caller provides an argument for any one of a succession of optional parameters, it must provide arguments for all preceding optional parameters.
  20. 20. Optional parameters are shown by square brackets.
  21. 21. Demo Code: http://softarchitect.wordpress.com/2010/07/25/software-architecture-c-4-0-new-feature-named-parameters-and-optional-parameters/</li></li></ul><li>Synchronized Data Structures<br /><ul><li>New namespace with name “System.Collections.Concurrent” which provide set of collections having thread safe behavior.
  22. 22. Some Important Thread Safe Collections.
  23. 23. BlockingCollection<T>
  24. 24. ConcurrentBag<T>
  25. 25. ConcurrentDictionary<TKey, TValue>
  26. 26. ConcurrentQueue<T>
  27. 27. ConcurrentStack<T>
  28. 28. OrderablePartitioner<TSource>
  29. 29. Partitioner
  30. 30. Partitioner<TSource>
  31. 31. Reference:</li></ul>http://softarchitect.wordpress.com/2010/08/15/software-architecture-c-sharp-4-0-new-feature-synchronized-data-structures-thread-safe-queue/<br />
  32. 32. Covariance and Contravariance and Invariance<br /><ul><li>Variance Theory </li></ul>As more specific type can be assigned to less specific type, but reverse is not possible. This thin is called compatibility Assignment.<br />In actual mathematical integers, consider ≤ relation on integers, the "less than or equal to" relation.<br />A "relation" is a function which takes two things and returns a bool which indicates whether the given relationship holds or does not hold.<br />A projection is a function which takes a single integer and returns a new integer. So, for example, z -> z + z is a projection; call it D for "double".  So are z -> 0 - z, N for "negate" and z -> z * z, S for "square".<br />(x ≤ y) = (D(x) ≤ D(y))?  <br /> [D preserves the direction of size, The projection D is "covariant"]<br />(x ≤ y) = (N(x) ≤ N(y))? <br />[N reverses the direction of size, The projection N is "contravariant"]<br />(x ≤ y) = (S(x) ≤ S(y))? <br />[S does not preserve the direction of size, and nor does it reverse it, The projection S is "invariant".]<br />
  33. 33. Covariance and Contravariance and Invariance<br />A Giraffe may be assigned to a variable of type Animal, and therefore an sequence of Giraffes may be assigned to a variable that can hold a sequence of Animals.<br />IEnumerable<T> is covariant" what we mean is "the projection which takes a reference type T and produces a reference type IEnumerable<T> is a covariant projection".<br />Demo Code 1 & 2<br />http://msdn.microsoft.com/en-us/library/ms173174(v=vs.80).aspx<br />http://blogs.msdn.com/b/ericlippert/archive/2009/11/30/what-s-the-difference-between-covariance-and-assignment-compatibility.aspxVideos:<br />http://msdn.microsoft.com/en-us/vcsharp/Video/ee672314<br />http://msdn.microsoft.com/en-us/vcsharp/video/Ee672319<br />
  34. 34. GenerateFrom Usage<br />Trick is to first use class,itsproperies,its method , its constructor and then generate code on basis of usage by simply pressing CTRL + “.” several times. [Demo]<br />Generating a Class from Usage<br />Generating a Delegate Stub from Usage<br />Generating an Interface Stub from Usage<br />Generating New Types with Additional Options from Usage ( General for all )<br />http://msdn.microsoft.com/en-us/library/dd409796.aspx<br />
  35. 35. Intelliense Modes<br />Use suggestion mode when classes and members are used before they are defined.<br />In suggestion mode, when you type in the editor and then commit the entry, the text you typed is inserted into the code. When you commit an entry in completion mode, the highlighted entry in the members list is inserted into the code.<br />To avoid this problem, press CTRL+ALT+SPACEBAR to switch to IntelliSense suggestion mode (as opposed to completion mode).<br />http://msdn.microsoft.com/en-us/library/exbffbc2.aspx<br />
  36. 36. Call Hierarchy window<br />To navigate through your code by displaying all calls to and from a selected method, property, or constructor.<br />Available at design time, unlike the call stack that is displayed by the debugger.<br />Search Scope box >> My Solution, Current Project, and Current Document.<br />Context Menu Item >>Add As New Root , Remove Root , Go To Definition , Find All References , Copy , Refresh <br />Reference: http://msdn.microsoft.com/en-us/library/dd409859.aspx<br />
  37. 37. Navigate To Window<br />A quick search tool for symbols Just press CTRL + “,” (or click Edit and then Navigate To) to see the new Navigate To window.<br />Other Options>>Object Browser,FindSymbol,Find ,Go To Line.<br />Reference: http://msdn.microsoft.com/en-us/library/4sadchd3(v=VS.100).aspx<br />
  38. 38. Productivity Options<br />Reference Highlighting<br />Put the cursor on a symbol (method, property, variable, etc.), all instances of this symbol are automatically highlighted in the code editor.<br />Navigate from one instance to another within a file by pressing CTRL+SHIFT+UP/DOWN ARROW.<br />Zoom<br /> Press CTRL and use your mouse wheel to enlarge or decrease your font size.<br />Box Selection and Multiline Editing<br />Press ALT and then use your mouse or arrow keys to select the box area.<br />Multiline box selection was there for delete from many versions of studio. But now insert,edit,replace is also supported.<br />http://blogs.msdn.com/b/vseditor/archive/2009/05/25/the-new-box-selection-now-with-multi-line-editing.aspx<br />
  39. 39. Productivity Options<br />Code Intellisense with VS 2010<br />(Regardless of what word it starts with – Find all keywords having that word)<br />Searching for Keywords <br />Searching for Types<br />Examples: Exception , List<br />Pascal Case Intellisense<br />Find and filter methods based on their pascal naming pattern. <br />For details see:<br />http://weblogs.asp.net/scottgu/archive/2009/10/22/vs-2010-code-intellisense-improvements-vs-2010-and-net-4-0-series.aspx<br />
  40. 40. Debugging Tips<br />Position cursor on the line in your code that you want to run the application to, and then press the Ctrl + F10 keys together.<br />Grouping Multiple Breakpoints Together using a Label + Filtering/Sorting Breakpoints by Label +Toggling Breakpoints On/Off by Label<br />Importing/Exporting Breakpoints<br />Pinned DataTips<br />Associating Comments with Pinned DataTips<br />See the Value Pinned DataTips from Last Debug Session<br />Importing/Exporting Pinned DataTips<br />Debugging Applications with IntelliTrace - Totally new debugger tool<br /> [Only for ultimate edition-Not covered in presentation-Self Reading]<br />Parallel Tasks and Parallel Stacks windows to debug a parallel application. [Not covered in presentation-Self Reading]<br />http://weblogs.asp.net/scottgu/archive/2010/08/18/debugging-tips-with-visual-studio-2010.aspx<br />http://weblogs.asp.net/scottgu/archive/2010/04/21/vs-2010-debugger-improvements-breakpoints-datatips-import-export.aspx<br />
  41. 41. Pinning Projects and Solutions <br />Pinning concept is there only for Windows 7<br />Window 7 allow to pin Mspaintot any other application.<br />Same can be done for Visual studio 2010<br />Even Projects can be pinned, so that they are available for quick access.<br />http://weblogs.asp.net/scottgu/archive/2010/05/10/pinning-projects-and-solutions-with-visual-studio-2010.aspx<br />
  42. 42. ASP .Net4.0 New Features<br />Read details here:<br />http://www.asp.net/learn/whitepapers/aspnet4<br />Filtering Data with the QueryExtender Control<br />http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.linqdatasource.where.aspx<br />http://www.asp.net/learn/whitepapers/aspnet4#0.2__Toc253429258<br />
  43. 43. ASP .Net<br />Routing in ASP.NET 4<br />Buildin Support – Namespace<br />Setting Client IDs<br />http://weblogs.asp.net/scottgu/archive/2010/03/30/cleaner-html-markup-with-asp-net-4-web-forms-client-ids-vs-2010-and-net-4-0-series.aspx<br />Persisting Row Selection in Data Controls<br />http://softarchitect.wordpress.com/2010/11/27/software-architecture-asp-net-4-0-for-data-bound-control-enablepersistedselection/<br />
  44. 44. ASP .Net<br />ASP .Net Charting buildin support<br />http://weblogs.asp.net/scottgu/archive/2010/02/07/built-in-charting-controls-vs-2010-and-net-4-series.aspx<br />jQuery library<br />The Visual Studio templates for both Web Forms and MVC include the open-source jQuery library.<br />Enabling View State for Individual Controls<br />In earlier versions of ASP.NET, developers could disable view state (EnableViewState)for individual controls in order to reduce page size, but had to do so explicitly for individual controls. In ASP.NET 4, Web server controls include a ViewStateMode property that lets you disable view state by default and then enable it only for the controls that require it in the page.<br />The ViewStateMode property takes an enumeration that has three values: Enabled, Disabled, and Inherit. Enabledenables view state for that control and for any child controls that are set to Inherit or that have nothing set. Disabled disables view state, and Inherit specifies that the control uses the ViewStateMode setting from the parent control.<br />
  45. 45. ASP .Net - Extensible Output Caching <br />Recap till ASP .Net 3.5<br /><%@ OutputCache Duration="#ofseconds" Location="Any | Client | Downstream | Server | None | ServerAndClient " Shared="True | False" VaryByControl="controlname" VaryByCustom="browser | customstring" VaryByHeader="headers" VaryByParam="parametername" VaryByContentEncoding="encodings" CacheProfile="cache profile name | ''" NoStore="true | false" SqlDependency="database/table name pair | CommandNotification" ProviderName="Provider Name" %><br />http://weblogs.asp.net/scottgu/archive/2010/01/27/extensible-output-caching-with-asp-net-4-vs-2010-and-net-4-0-series.aspx<br />http://msdn.microsoft.com/en-us/library/hdxfb6cy(v=VS.100).aspx<br />
  46. 46. Memory-mapped<br />According Wiki <br />A memory-mapped file is a segment of virtual memory which has been assigned a direct byte-for-byte correlation with some portion of a file or file-like resource. This resource is typically a file that is physically present on-disk, but can also be a device, shared memory object, or other resource that the operating system can reference through a file descriptor.<br />In C# 4.0, Microsoft has introduced a new namespace “System.IO.MemoryMappedFiles” for manipulating memory mapped file.<br />CreateViewStream method of MemoryMappedFiles is used to create a stream which is mapped to memory mapped file.<br />Reference: http://softarchitect.wordpress.com/2010/08/15/software-architecture-c-sharp-4-0-new-feature-memory-mapped-file/<br />
  47. 47. Enum-HasFlag(Enum flag )<br />In C# 4.0, enum has a new function as:public boolHasFlag(Enum flag )<br />which takes second enum as parameter and return bool as true if the bit field or bit fields that are set in flag are also set in the current instance; otherwise, false.<br />Logically HasFlag evaluates following expression:<br />thisInstance And flag = flag <br />Reference: http://softarchitect.wordpress.com/2010/09/15/software-architecture-c-sharp-4-0-new-feature-enum-hasflag/<br />
  48. 48. Managed Extensibility Framework or MEF<br />The Managed Extensibility Framework or MEF is a library for creating lightweight, extensible applications. It allows application developers to discover and use extensions with no configuration required. It also lets extension developers easily encapsulate code and avoid fragile hard dependencies. MEF not only allows extensions to be reused within applications, but across applications as well.<br />Reference: http://softarchitect.wordpress.com/2010/08/14/software-architecture-c-sharp-4-0-new-feature-whywhathow-of-managed-extensibility-framework-mef-sample-calculator-code/<br />
  49. 49. KeepVisiting me at:<br />http://softarchitect.wordpress.com<br />

×