SlideShare a Scribd company logo
C# 6.0 Features and Tooling
Matt Ellis
@citizenmatt
Back story
Roslyn
Language features
HISTORY
C# 1.0 (2002)
Initial commit
C# 1.2 (2003)
Really!?
C# 2.0 (2005)
Generics
Nullable types
Iterators
Partial types
Anonymous methods
Getter/setter accessibility
Static classes
New CLR features
Language features
C# 3.0 (2007)
Anonymous types
Implicit typing (“var”)
Extension methods
Lambda expressions
Query expressions
Expression trees
Auto properties
Object and collection initialisers
Partial methods
LINQ
C# 4.0 (2010)
Dynamic
Named and optional
parameters
Embedded interop types
Co- and contra-variance for generics
COM interop
C# 5.0 (2012)
Async/await
Caller Info attributes
private async static Task<string> DownloadText(string url)
{
using (var webClient = new WebClient())
return await webClient.DownloadStringTaskAsync(url);
}
C# 6.0 (2015)
Roslyn
Auto property initialisers
Index initialisers
Using static members
Null propagation
Expression bodied members
IEnumerable params
nameof operator
Await in catch/finally
Exception filters
Ceremony
New compiler!
ROSLYN
Roslyn
“.NET Compiler Platform”
Complete redesign & rewrite of compiler
C# vs C++
Decade old codebase
Ease of adding new features
Parallel compilation
Open Source (github.com/dotnet/roslyn)
Compiler as a service
Compiler exposed as an API
Can host compiler in-process
Can compile in-memory
Can affect compilation steps, e.g. resolving
references (but no meta-programming)
Can access parse trees and semantic model
IDE features
Compiler powers syntax highlighting, navigation, etc.
Parser and semantic model available across the IDE
Abstract Syntax Tree based analysis, navigation and
refactoring
ScriptCS
C# based REPL and scripting
Script packs and NuGet references
ASP.Net vNext
Compiler pipeline based on Roslyn
Compiles to in-memory assemblies
Edit file + refresh browser = compiled
No need to recompile whole project
New project system, based on NuGet
Controls assembly/package resolution
Meta-programming. Kinda.
Problem:
CLR types defined by assembly qualified name
Everything based on binary references
Contracts are hardcoded. No loose coupling
E.g.: want to use the same logger across application +
3rd party framework?
Must share contract (assembly), or provide adapters
Assembly neutral interfaces
Ideal:
Duck typing/structural equivalence
Common contracts defined in source, resolved at runtime
But how do you work around assembly qualified name?
Compile time
// Compiled to CommonLogging.ILogger.dll
namespace CommonLogging
{
[AssemblyNeutral]
public interface ILogger
{
void Log(string value);
}
}
Finds and removes [AssemblyNeutral] contract types
Compile a new assembly for each type
Predictable assembly qualified name
Original assembly references the types in new assemblies
New assemblies saved as embedded resources in original assembly
Multiple assemblies defining same types generate same assemblies
Run time
Application tries to resolve
neutral assembly
Host environment looks in
resources of all assemblies
Uses first match it finds
If multiple assemblies define
same type, same dll is
generated
Types with same namespace
and name “Just Work”
LANGUAGE FEATURES
Language features
Auto property initialisers
Index initialisers
Using static members
Null propagation
Expression bodied members
IEnumerable params
nameof operator
Await in catch/finally
Exception filters
Auto property initialisation
Proper readonly (immutable) auto properties – getter only
No need for constructor or backing field
public class Person
{
public string Name { get; }
public Address Address { get; } = new Address();
public Person(string name)
{
// Assignment to getter only properties
Name = name;
}
}
Index initialisers
Nicer syntax than previous collection initialisers
Calls indexer rather than Add method
Extends object initialiser
var d = new Dictionary<string, int>
{
["doodad"] = 42,
["widget"] = 64
};
Using static members
Use static members without qualification
Applies to methods, properties, fields, events, etc.
Does not apply to extension methods
Local declarations resolved first
using static System.Math;
public class Sphere
{
private readonly double radius;
public Sphere(double radius)
{
this.radius = radius;
}
public double Volume
{
get { return (3/4)*PI*Pow(radius, 3); }
}
}
nameof operator
Returns short name of symbol
Any symbol – class, class member, namespace,
type parameters, variables, etc.
Ambiguities are not an error
public void Foo(string value)
{
if (value == null)
throw new ArgumentNullException(nameof(value));
}
Expression bodied members
Replaces single line methods, properties, indexers,
operators, etc.
Familiar lambda arrow syntax
Properties are created as getter only
Can only be single expression
public string FullName => FirstName + " " + LastName;
Null propagation
Conditional access operator
Returns null if qualifier is null, else evaluates
Short circuiting
Conditional method invocation, indexer access
Left hand side evaluated only once – thread safe
int? length = customers?.Length;
int length2 = customers?.Length ?? 0;
Await in catch/finally
Implementation detail
Previously “impossible”
IL cannot branch into or out of catch/finally
Uses ExceptionDispatchInfo to save exception
state and rethrow if necessary
Exception filters
Existing CLR feature
Only run catch block if exception handler returns true
Replaces if () throw; pattern
Expected “abuse” – logging
catch (Exception e) when (Log(e))
{
// ...
}
private bool Log(Exception exception)
{
Debug.WriteLine(exception);
return false;
}
String interpolation
$"My name is {name} and I’m {person.Age} years old"
Compiles to string.Format
Holes can contain expressions – e.g.
$"Hi {GetName(person)}"
Uses current culture by default
Format specifiers – e.g. $"{foo:D}”
Does not work with stored resource strings
Verbatim strings can contain strings. What!?
Formattable strings
Interpolated strings converted to
FormattableString by
FormattableStringFactory.Create
Passed to method that returns a string
formatted as required, e.g. Invariant culture,
URL encoding, SQL
Provide own FormattableString implementations
on downlevel versions
Summary
Roslyn
Complete rewrite
Easier to maintain
Open Source
Compiler as a service
IDE features, scripting,
hosting compilers
Language features
Auto property initialisers
Getter only auto properties
Index initialisers
Using static members
Null propagation
Expression bodied members
nameof operator
Await in catch/finally
Exception filters
Bonus – C# 7.0
Strong interest
Tuples
Pattern matching
Records
Non-nullable types
Async streams (observables) +
disposable
Some interest
Covariant return types
Expanded expression trees
Syntax for lists + dictionaries
Deterministic disposal
Immutable types
Type providers
Scripting
Method contracts
yield foreach
params IEnumerable
more...
Ad

More Related Content

What's hot (20)

Java 8 Lambda and Streams
Java 8 Lambda and StreamsJava 8 Lambda and Streams
Java 8 Lambda and Streams
Venkata Naga Ravi
 
C# basics
 C# basics C# basics
C# basics
Dinesh kumar
 
Introduction to Dart
Introduction to DartIntroduction to Dart
Introduction to Dart
RameshNair6
 
Javascript
JavascriptJavascript
Javascript
guest03a6e6
 
Java Basics
Java BasicsJava Basics
Java Basics
Dhanunjai Bandlamudi
 
JavaScript: The Language
JavaScript: The LanguageJavaScript: The Language
JavaScript: The Language
Engage Software
 
Cs30 New
Cs30 NewCs30 New
Cs30 New
DSK Chakravarthy
 
Introduction to c#
Introduction to c#Introduction to c#
Introduction to c#
OpenSource Technologies Pvt. Ltd.
 
Oop2010 Scala Presentation Stal
Oop2010 Scala Presentation StalOop2010 Scala Presentation Stal
Oop2010 Scala Presentation Stal
Michael Stal
 
Javascript
JavascriptJavascript
Javascript
Sunil Thakur
 
(6) c sharp introduction_advanced_features_part_i
(6) c sharp introduction_advanced_features_part_i(6) c sharp introduction_advanced_features_part_i
(6) c sharp introduction_advanced_features_part_i
Nico Ludwig
 
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and StreamsIntroduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
Emiel Paasschens
 
Lambda Expressions in Java 8
Lambda Expressions in Java 8Lambda Expressions in Java 8
Lambda Expressions in Java 8
icarter09
 
Java8
Java8Java8
Java8
Felipe Mamud
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript Programming
Sehwan Noh
 
Qcon2011 functions rockpresentation_f_sharp
Qcon2011 functions rockpresentation_f_sharpQcon2011 functions rockpresentation_f_sharp
Qcon2011 functions rockpresentation_f_sharp
Michael Stal
 
Oop2011 actor presentation_stal
Oop2011 actor presentation_stalOop2011 actor presentation_stal
Oop2011 actor presentation_stal
Michael Stal
 
Writing code that writes code - Nguyen Luong
Writing code that writes code - Nguyen LuongWriting code that writes code - Nguyen Luong
Writing code that writes code - Nguyen Luong
Vu Huy
 
Introduction to Swift
Introduction to SwiftIntroduction to Swift
Introduction to Swift
Matteo Battaglio
 
Streams in Java 8
Streams in Java 8Streams in Java 8
Streams in Java 8
Tobias Coetzee
 
Introduction to Dart
Introduction to DartIntroduction to Dart
Introduction to Dart
RameshNair6
 
JavaScript: The Language
JavaScript: The LanguageJavaScript: The Language
JavaScript: The Language
Engage Software
 
Oop2010 Scala Presentation Stal
Oop2010 Scala Presentation StalOop2010 Scala Presentation Stal
Oop2010 Scala Presentation Stal
Michael Stal
 
(6) c sharp introduction_advanced_features_part_i
(6) c sharp introduction_advanced_features_part_i(6) c sharp introduction_advanced_features_part_i
(6) c sharp introduction_advanced_features_part_i
Nico Ludwig
 
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and StreamsIntroduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
Emiel Paasschens
 
Lambda Expressions in Java 8
Lambda Expressions in Java 8Lambda Expressions in Java 8
Lambda Expressions in Java 8
icarter09
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript Programming
Sehwan Noh
 
Qcon2011 functions rockpresentation_f_sharp
Qcon2011 functions rockpresentation_f_sharpQcon2011 functions rockpresentation_f_sharp
Qcon2011 functions rockpresentation_f_sharp
Michael Stal
 
Oop2011 actor presentation_stal
Oop2011 actor presentation_stalOop2011 actor presentation_stal
Oop2011 actor presentation_stal
Michael Stal
 
Writing code that writes code - Nguyen Luong
Writing code that writes code - Nguyen LuongWriting code that writes code - Nguyen Luong
Writing code that writes code - Nguyen Luong
Vu Huy
 

Viewers also liked (20)

C++11
C++11C++11
C++11
Andrey Dankevich
 
New features in C# 6
New features in C# 6New features in C# 6
New features in C# 6
Software Associates
 
Configuring SSL on NGNINX and less tricky servers
Configuring SSL on NGNINX and less tricky serversConfiguring SSL on NGNINX and less tricky servers
Configuring SSL on NGNINX and less tricky servers
Axilis
 
NuGet Must Haves for LINQ
NuGet Must Haves for LINQNuGet Must Haves for LINQ
NuGet Must Haves for LINQ
Axilis
 
Dynamic C#
Dynamic C# Dynamic C#
Dynamic C#
Antya Dev
 
C# features through examples
C# features through examplesC# features through examples
C# features through examples
Zayen Chagra
 
Evolution of c# - by K.Jegan
Evolution of c# - by K.JeganEvolution of c# - by K.Jegan
Evolution of c# - by K.Jegan
talenttransform
 
A Tour of EF Core's (1.1) Most Interesting & Important Features
A Tour of EF Core's (1.1) Most Interesting & Important FeaturesA Tour of EF Core's (1.1) Most Interesting & Important Features
A Tour of EF Core's (1.1) Most Interesting & Important Features
Julie Lerman
 
EF6 or EF Core? How Do I Choose?
EF6 or EF Core? How Do I Choose?EF6 or EF Core? How Do I Choose?
EF6 or EF Core? How Do I Choose?
Julie Lerman
 
ASP.NET MVC 4 Request Pipeline Internals
ASP.NET MVC 4 Request Pipeline InternalsASP.NET MVC 4 Request Pipeline Internals
ASP.NET MVC 4 Request Pipeline Internals
Lukasz Lysik
 
Dependency injection in asp.net core
Dependency injection in asp.net coreDependency injection in asp.net core
Dependency injection in asp.net core
Bill Lin
 
Functional Programming with C#
Functional Programming with C#Functional Programming with C#
Functional Programming with C#
EastBanc Tachnologies
 
Repository design pattern in laravel - Samir Poudel
Repository design pattern in laravel - Samir PoudelRepository design pattern in laravel - Samir Poudel
Repository design pattern in laravel - Samir Poudel
Sameer Poudel
 
ASP.NET MVC 4 - Routing Internals
ASP.NET MVC 4 - Routing InternalsASP.NET MVC 4 - Routing Internals
ASP.NET MVC 4 - Routing Internals
Lukasz Lysik
 
Introduction the Repository Pattern
Introduction the Repository PatternIntroduction the Repository Pattern
Introduction the Repository Pattern
Bill Lin
 
Day02 01 Advance Feature in C# DH TDT
Day02 01 Advance Feature in C# DH TDTDay02 01 Advance Feature in C# DH TDT
Day02 01 Advance Feature in C# DH TDT
Nguyen Patrick
 
Functional Programming in C# and F#
Functional Programming in C# and F#Functional Programming in C# and F#
Functional Programming in C# and F#
Alfonso Garcia-Caro
 
코드의 품질 (Code Quality)
코드의 품질 (Code Quality)코드의 품질 (Code Quality)
코드의 품질 (Code Quality)
ChulHui Lee
 
Repository and Unit Of Work Design Patterns
Repository and Unit Of Work Design PatternsRepository and Unit Of Work Design Patterns
Repository and Unit Of Work Design Patterns
Hatim Hakeel
 
Generic repository pattern with ASP.NET MVC and Entity Framework
Generic repository pattern with ASP.NET MVC and Entity FrameworkGeneric repository pattern with ASP.NET MVC and Entity Framework
Generic repository pattern with ASP.NET MVC and Entity Framework
Md. Mahedee Hasan
 
Configuring SSL on NGNINX and less tricky servers
Configuring SSL on NGNINX and less tricky serversConfiguring SSL on NGNINX and less tricky servers
Configuring SSL on NGNINX and less tricky servers
Axilis
 
NuGet Must Haves for LINQ
NuGet Must Haves for LINQNuGet Must Haves for LINQ
NuGet Must Haves for LINQ
Axilis
 
C# features through examples
C# features through examplesC# features through examples
C# features through examples
Zayen Chagra
 
Evolution of c# - by K.Jegan
Evolution of c# - by K.JeganEvolution of c# - by K.Jegan
Evolution of c# - by K.Jegan
talenttransform
 
A Tour of EF Core's (1.1) Most Interesting & Important Features
A Tour of EF Core's (1.1) Most Interesting & Important FeaturesA Tour of EF Core's (1.1) Most Interesting & Important Features
A Tour of EF Core's (1.1) Most Interesting & Important Features
Julie Lerman
 
EF6 or EF Core? How Do I Choose?
EF6 or EF Core? How Do I Choose?EF6 or EF Core? How Do I Choose?
EF6 or EF Core? How Do I Choose?
Julie Lerman
 
ASP.NET MVC 4 Request Pipeline Internals
ASP.NET MVC 4 Request Pipeline InternalsASP.NET MVC 4 Request Pipeline Internals
ASP.NET MVC 4 Request Pipeline Internals
Lukasz Lysik
 
Dependency injection in asp.net core
Dependency injection in asp.net coreDependency injection in asp.net core
Dependency injection in asp.net core
Bill Lin
 
Repository design pattern in laravel - Samir Poudel
Repository design pattern in laravel - Samir PoudelRepository design pattern in laravel - Samir Poudel
Repository design pattern in laravel - Samir Poudel
Sameer Poudel
 
ASP.NET MVC 4 - Routing Internals
ASP.NET MVC 4 - Routing InternalsASP.NET MVC 4 - Routing Internals
ASP.NET MVC 4 - Routing Internals
Lukasz Lysik
 
Introduction the Repository Pattern
Introduction the Repository PatternIntroduction the Repository Pattern
Introduction the Repository Pattern
Bill Lin
 
Day02 01 Advance Feature in C# DH TDT
Day02 01 Advance Feature in C# DH TDTDay02 01 Advance Feature in C# DH TDT
Day02 01 Advance Feature in C# DH TDT
Nguyen Patrick
 
Functional Programming in C# and F#
Functional Programming in C# and F#Functional Programming in C# and F#
Functional Programming in C# and F#
Alfonso Garcia-Caro
 
코드의 품질 (Code Quality)
코드의 품질 (Code Quality)코드의 품질 (Code Quality)
코드의 품질 (Code Quality)
ChulHui Lee
 
Repository and Unit Of Work Design Patterns
Repository and Unit Of Work Design PatternsRepository and Unit Of Work Design Patterns
Repository and Unit Of Work Design Patterns
Hatim Hakeel
 
Generic repository pattern with ASP.NET MVC and Entity Framework
Generic repository pattern with ASP.NET MVC and Entity FrameworkGeneric repository pattern with ASP.NET MVC and Entity Framework
Generic repository pattern with ASP.NET MVC and Entity Framework
Md. Mahedee Hasan
 
Ad

Similar to C# 6.0 - DotNetNotts (20)

Java Script Patterns
Java Script PatternsJava Script Patterns
Java Script Patterns
Allan Huang
 
Gude for C++11 in Apache Traffic Server
Gude for C++11 in Apache Traffic ServerGude for C++11 in Apache Traffic Server
Gude for C++11 in Apache Traffic Server
Apache Traffic Server
 
Introduction to clojure
Introduction to clojureIntroduction to clojure
Introduction to clojure
Abbas Raza
 
whats new in java 8
whats new in java 8 whats new in java 8
whats new in java 8
Dori Waldman
 
SOLID mit Java 8
SOLID mit Java 8SOLID mit Java 8
SOLID mit Java 8
Roland Mast
 
C# - Igor Ralić
C# - Igor RalićC# - Igor Ralić
C# - Igor Ralić
Software StartUp Academy Osijek
 
Beginning Java for .NET developers
Beginning Java for .NET developersBeginning Java for .NET developers
Beginning Java for .NET developers
Andrei Rinea
 
Introduction to c_plus_plus (6)
Introduction to c_plus_plus (6)Introduction to c_plus_plus (6)
Introduction to c_plus_plus (6)
Sayed Ahmed
 
Introduction to c_plus_plus
Introduction to c_plus_plusIntroduction to c_plus_plus
Introduction to c_plus_plus
Sayed Ahmed
 
C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...
C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...
C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...
yazad dumasia
 
C sharp
C sharpC sharp
C sharp
Satish Verma
 
Lambda Chops - Recipes for Simpler, More Expressive Code
Lambda Chops - Recipes for Simpler, More Expressive CodeLambda Chops - Recipes for Simpler, More Expressive Code
Lambda Chops - Recipes for Simpler, More Expressive Code
Ian Robertson
 
Core Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika TutorialsCore Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika Tutorials
Mahika Tutorials
 
NLJUG University Sessie: Java Reborn, Powered by Ordina
NLJUG University Sessie: Java Reborn, Powered by OrdinaNLJUG University Sessie: Java Reborn, Powered by Ordina
NLJUG University Sessie: Java Reborn, Powered by Ordina
Martijn Blankestijn
 
EnScript Workshop
EnScript WorkshopEnScript Workshop
EnScript Workshop
Mark Morgan, CCE, EnCE
 
CSharp presentation and software developement
CSharp presentation and software developementCSharp presentation and software developement
CSharp presentation and software developement
frwebhelp
 
Back-2-Basics: .NET Coding Standards For The Real World (2011)
Back-2-Basics: .NET Coding Standards For The Real World (2011)Back-2-Basics: .NET Coding Standards For The Real World (2011)
Back-2-Basics: .NET Coding Standards For The Real World (2011)
David McCarter
 
Attributes & .NET components
Attributes & .NET componentsAttributes & .NET components
Attributes & .NET components
Bình Trọng Án
 
C# for beginners
C# for beginnersC# for beginners
C# for beginners
application developer
 
Java Intro
Java IntroJava Intro
Java Intro
backdoor
 
Java Script Patterns
Java Script PatternsJava Script Patterns
Java Script Patterns
Allan Huang
 
Gude for C++11 in Apache Traffic Server
Gude for C++11 in Apache Traffic ServerGude for C++11 in Apache Traffic Server
Gude for C++11 in Apache Traffic Server
Apache Traffic Server
 
Introduction to clojure
Introduction to clojureIntroduction to clojure
Introduction to clojure
Abbas Raza
 
whats new in java 8
whats new in java 8 whats new in java 8
whats new in java 8
Dori Waldman
 
SOLID mit Java 8
SOLID mit Java 8SOLID mit Java 8
SOLID mit Java 8
Roland Mast
 
Beginning Java for .NET developers
Beginning Java for .NET developersBeginning Java for .NET developers
Beginning Java for .NET developers
Andrei Rinea
 
Introduction to c_plus_plus (6)
Introduction to c_plus_plus (6)Introduction to c_plus_plus (6)
Introduction to c_plus_plus (6)
Sayed Ahmed
 
Introduction to c_plus_plus
Introduction to c_plus_plusIntroduction to c_plus_plus
Introduction to c_plus_plus
Sayed Ahmed
 
C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...
C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...
C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...
yazad dumasia
 
Lambda Chops - Recipes for Simpler, More Expressive Code
Lambda Chops - Recipes for Simpler, More Expressive CodeLambda Chops - Recipes for Simpler, More Expressive Code
Lambda Chops - Recipes for Simpler, More Expressive Code
Ian Robertson
 
Core Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika TutorialsCore Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika Tutorials
Mahika Tutorials
 
NLJUG University Sessie: Java Reborn, Powered by Ordina
NLJUG University Sessie: Java Reborn, Powered by OrdinaNLJUG University Sessie: Java Reborn, Powered by Ordina
NLJUG University Sessie: Java Reborn, Powered by Ordina
Martijn Blankestijn
 
CSharp presentation and software developement
CSharp presentation and software developementCSharp presentation and software developement
CSharp presentation and software developement
frwebhelp
 
Back-2-Basics: .NET Coding Standards For The Real World (2011)
Back-2-Basics: .NET Coding Standards For The Real World (2011)Back-2-Basics: .NET Coding Standards For The Real World (2011)
Back-2-Basics: .NET Coding Standards For The Real World (2011)
David McCarter
 
Attributes & .NET components
Attributes & .NET componentsAttributes & .NET components
Attributes & .NET components
Bình Trọng Án
 
Java Intro
Java IntroJava Intro
Java Intro
backdoor
 
Ad

More from citizenmatt (10)

I see deadlocks : Matt Ellis - Techorama NL 2024
I see deadlocks : Matt Ellis - Techorama NL 2024I see deadlocks : Matt Ellis - Techorama NL 2024
I see deadlocks : Matt Ellis - Techorama NL 2024
citizenmatt
 
How to Parse a File (NDC London 2018)
How to Parse a File (NDC London 2018)How to Parse a File (NDC London 2018)
How to Parse a File (NDC London 2018)
citizenmatt
 
How to Parse a File (DDD North 2017)
How to Parse a File (DDD North 2017)How to Parse a File (DDD North 2017)
How to Parse a File (DDD North 2017)
citizenmatt
 
Rider - Taking ReSharper out of Process
Rider - Taking ReSharper out of ProcessRider - Taking ReSharper out of Process
Rider - Taking ReSharper out of Process
citizenmatt
 
The how-dare-you-call-me-an-idiot’s guide to the .NET Standard (NDC London 2017)
The how-dare-you-call-me-an-idiot’s guide to the .NET Standard (NDC London 2017)The how-dare-you-call-me-an-idiot’s guide to the .NET Standard (NDC London 2017)
The how-dare-you-call-me-an-idiot’s guide to the .NET Standard (NDC London 2017)
citizenmatt
 
.NET Core Blimey! Windows Platform User Group, Manchester
.NET Core Blimey! Windows Platform User Group, Manchester.NET Core Blimey! Windows Platform User Group, Manchester
.NET Core Blimey! Windows Platform User Group, Manchester
citizenmatt
 
.NET Core Blimey! (Shropshire Devs Mar 2016)
.NET Core Blimey! (Shropshire Devs Mar 2016).NET Core Blimey! (Shropshire Devs Mar 2016)
.NET Core Blimey! (Shropshire Devs Mar 2016)
citizenmatt
 
.NET Core Blimey! (dotnetsheff Jan 2016)
.NET Core Blimey! (dotnetsheff Jan 2016).NET Core Blimey! (dotnetsheff Jan 2016)
.NET Core Blimey! (dotnetsheff Jan 2016)
citizenmatt
 
.net Core Blimey - Smart Devs UG
.net Core Blimey - Smart Devs UG.net Core Blimey - Smart Devs UG
.net Core Blimey - Smart Devs UG
citizenmatt
 
.Net Core Blimey! (16/07/2015)
.Net Core Blimey! (16/07/2015).Net Core Blimey! (16/07/2015)
.Net Core Blimey! (16/07/2015)
citizenmatt
 
I see deadlocks : Matt Ellis - Techorama NL 2024
I see deadlocks : Matt Ellis - Techorama NL 2024I see deadlocks : Matt Ellis - Techorama NL 2024
I see deadlocks : Matt Ellis - Techorama NL 2024
citizenmatt
 
How to Parse a File (NDC London 2018)
How to Parse a File (NDC London 2018)How to Parse a File (NDC London 2018)
How to Parse a File (NDC London 2018)
citizenmatt
 
How to Parse a File (DDD North 2017)
How to Parse a File (DDD North 2017)How to Parse a File (DDD North 2017)
How to Parse a File (DDD North 2017)
citizenmatt
 
Rider - Taking ReSharper out of Process
Rider - Taking ReSharper out of ProcessRider - Taking ReSharper out of Process
Rider - Taking ReSharper out of Process
citizenmatt
 
The how-dare-you-call-me-an-idiot’s guide to the .NET Standard (NDC London 2017)
The how-dare-you-call-me-an-idiot’s guide to the .NET Standard (NDC London 2017)The how-dare-you-call-me-an-idiot’s guide to the .NET Standard (NDC London 2017)
The how-dare-you-call-me-an-idiot’s guide to the .NET Standard (NDC London 2017)
citizenmatt
 
.NET Core Blimey! Windows Platform User Group, Manchester
.NET Core Blimey! Windows Platform User Group, Manchester.NET Core Blimey! Windows Platform User Group, Manchester
.NET Core Blimey! Windows Platform User Group, Manchester
citizenmatt
 
.NET Core Blimey! (Shropshire Devs Mar 2016)
.NET Core Blimey! (Shropshire Devs Mar 2016).NET Core Blimey! (Shropshire Devs Mar 2016)
.NET Core Blimey! (Shropshire Devs Mar 2016)
citizenmatt
 
.NET Core Blimey! (dotnetsheff Jan 2016)
.NET Core Blimey! (dotnetsheff Jan 2016).NET Core Blimey! (dotnetsheff Jan 2016)
.NET Core Blimey! (dotnetsheff Jan 2016)
citizenmatt
 
.net Core Blimey - Smart Devs UG
.net Core Blimey - Smart Devs UG.net Core Blimey - Smart Devs UG
.net Core Blimey - Smart Devs UG
citizenmatt
 
.Net Core Blimey! (16/07/2015)
.Net Core Blimey! (16/07/2015).Net Core Blimey! (16/07/2015)
.Net Core Blimey! (16/07/2015)
citizenmatt
 

Recently uploaded (20)

Metal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistryMetal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistry
mee23nu
 
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITYADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ijscai
 
Degree_of_Automation.pdf for Instrumentation and industrial specialist
Degree_of_Automation.pdf for  Instrumentation  and industrial specialistDegree_of_Automation.pdf for  Instrumentation  and industrial specialist
Degree_of_Automation.pdf for Instrumentation and industrial specialist
shreyabhosale19
 
theory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptxtheory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptx
sanchezvanessa7896
 
railway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forgingrailway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forging
Javad Kadkhodapour
 
Mathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdfMathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdf
TalhaShahid49
 
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Journal of Soft Computing in Civil Engineering
 
International Journal of Distributed and Parallel systems (IJDPS)
International Journal of Distributed and Parallel systems (IJDPS)International Journal of Distributed and Parallel systems (IJDPS)
International Journal of Distributed and Parallel systems (IJDPS)
samueljackson3773
 
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptxExplainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
MahaveerVPandit
 
Data Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptxData Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptx
RushaliDeshmukh2
 
Oil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdfOil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdf
M7md3li2
 
Fort night presentation new0903 pdf.pdf.
Fort night presentation new0903 pdf.pdf.Fort night presentation new0903 pdf.pdf.
Fort night presentation new0903 pdf.pdf.
anuragmk56
 
IntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdfIntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdf
Luiz Carneiro
 
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
inmishra17121973
 
Machine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptxMachine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptx
rajeswari89780
 
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Journal of Soft Computing in Civil Engineering
 
new ppt artificial intelligence historyyy
new ppt artificial intelligence historyyynew ppt artificial intelligence historyyy
new ppt artificial intelligence historyyy
PianoPianist
 
Raish Khanji GTU 8th sem Internship Report.pdf
Raish Khanji GTU 8th sem Internship Report.pdfRaish Khanji GTU 8th sem Internship Report.pdf
Raish Khanji GTU 8th sem Internship Report.pdf
RaishKhanji
 
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdfRICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
MohamedAbdelkader115
 
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
charlesdick1345
 
Metal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistryMetal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistry
mee23nu
 
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITYADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ijscai
 
Degree_of_Automation.pdf for Instrumentation and industrial specialist
Degree_of_Automation.pdf for  Instrumentation  and industrial specialistDegree_of_Automation.pdf for  Instrumentation  and industrial specialist
Degree_of_Automation.pdf for Instrumentation and industrial specialist
shreyabhosale19
 
theory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptxtheory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptx
sanchezvanessa7896
 
railway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forgingrailway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forging
Javad Kadkhodapour
 
Mathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdfMathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdf
TalhaShahid49
 
International Journal of Distributed and Parallel systems (IJDPS)
International Journal of Distributed and Parallel systems (IJDPS)International Journal of Distributed and Parallel systems (IJDPS)
International Journal of Distributed and Parallel systems (IJDPS)
samueljackson3773
 
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptxExplainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
MahaveerVPandit
 
Data Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptxData Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptx
RushaliDeshmukh2
 
Oil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdfOil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdf
M7md3li2
 
Fort night presentation new0903 pdf.pdf.
Fort night presentation new0903 pdf.pdf.Fort night presentation new0903 pdf.pdf.
Fort night presentation new0903 pdf.pdf.
anuragmk56
 
IntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdfIntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdf
Luiz Carneiro
 
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
inmishra17121973
 
Machine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptxMachine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptx
rajeswari89780
 
new ppt artificial intelligence historyyy
new ppt artificial intelligence historyyynew ppt artificial intelligence historyyy
new ppt artificial intelligence historyyy
PianoPianist
 
Raish Khanji GTU 8th sem Internship Report.pdf
Raish Khanji GTU 8th sem Internship Report.pdfRaish Khanji GTU 8th sem Internship Report.pdf
Raish Khanji GTU 8th sem Internship Report.pdf
RaishKhanji
 
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdfRICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
MohamedAbdelkader115
 
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
charlesdick1345
 

C# 6.0 - DotNetNotts

  • 1. C# 6.0 Features and Tooling Matt Ellis @citizenmatt
  • 4. C# 1.0 (2002) Initial commit C# 1.2 (2003) Really!?
  • 5. C# 2.0 (2005) Generics Nullable types Iterators Partial types Anonymous methods Getter/setter accessibility Static classes New CLR features Language features
  • 6. C# 3.0 (2007) Anonymous types Implicit typing (“var”) Extension methods Lambda expressions Query expressions Expression trees Auto properties Object and collection initialisers Partial methods LINQ
  • 7. C# 4.0 (2010) Dynamic Named and optional parameters Embedded interop types Co- and contra-variance for generics COM interop
  • 8. C# 5.0 (2012) Async/await Caller Info attributes private async static Task<string> DownloadText(string url) { using (var webClient = new WebClient()) return await webClient.DownloadStringTaskAsync(url); }
  • 9. C# 6.0 (2015) Roslyn Auto property initialisers Index initialisers Using static members Null propagation Expression bodied members IEnumerable params nameof operator Await in catch/finally Exception filters Ceremony New compiler!
  • 11. Roslyn “.NET Compiler Platform” Complete redesign & rewrite of compiler C# vs C++ Decade old codebase Ease of adding new features Parallel compilation Open Source (github.com/dotnet/roslyn)
  • 12. Compiler as a service Compiler exposed as an API Can host compiler in-process Can compile in-memory Can affect compilation steps, e.g. resolving references (but no meta-programming) Can access parse trees and semantic model
  • 13. IDE features Compiler powers syntax highlighting, navigation, etc. Parser and semantic model available across the IDE Abstract Syntax Tree based analysis, navigation and refactoring
  • 14. ScriptCS C# based REPL and scripting Script packs and NuGet references
  • 15. ASP.Net vNext Compiler pipeline based on Roslyn Compiles to in-memory assemblies Edit file + refresh browser = compiled No need to recompile whole project New project system, based on NuGet Controls assembly/package resolution
  • 16. Meta-programming. Kinda. Problem: CLR types defined by assembly qualified name Everything based on binary references Contracts are hardcoded. No loose coupling E.g.: want to use the same logger across application + 3rd party framework? Must share contract (assembly), or provide adapters
  • 17. Assembly neutral interfaces Ideal: Duck typing/structural equivalence Common contracts defined in source, resolved at runtime But how do you work around assembly qualified name?
  • 18. Compile time // Compiled to CommonLogging.ILogger.dll namespace CommonLogging { [AssemblyNeutral] public interface ILogger { void Log(string value); } } Finds and removes [AssemblyNeutral] contract types Compile a new assembly for each type Predictable assembly qualified name Original assembly references the types in new assemblies New assemblies saved as embedded resources in original assembly Multiple assemblies defining same types generate same assemblies
  • 19. Run time Application tries to resolve neutral assembly Host environment looks in resources of all assemblies Uses first match it finds If multiple assemblies define same type, same dll is generated Types with same namespace and name “Just Work”
  • 21. Language features Auto property initialisers Index initialisers Using static members Null propagation Expression bodied members IEnumerable params nameof operator Await in catch/finally Exception filters
  • 22. Auto property initialisation Proper readonly (immutable) auto properties – getter only No need for constructor or backing field public class Person { public string Name { get; } public Address Address { get; } = new Address(); public Person(string name) { // Assignment to getter only properties Name = name; } }
  • 23. Index initialisers Nicer syntax than previous collection initialisers Calls indexer rather than Add method Extends object initialiser var d = new Dictionary<string, int> { ["doodad"] = 42, ["widget"] = 64 };
  • 24. Using static members Use static members without qualification Applies to methods, properties, fields, events, etc. Does not apply to extension methods Local declarations resolved first using static System.Math; public class Sphere { private readonly double radius; public Sphere(double radius) { this.radius = radius; } public double Volume { get { return (3/4)*PI*Pow(radius, 3); } } }
  • 25. nameof operator Returns short name of symbol Any symbol – class, class member, namespace, type parameters, variables, etc. Ambiguities are not an error public void Foo(string value) { if (value == null) throw new ArgumentNullException(nameof(value)); }
  • 26. Expression bodied members Replaces single line methods, properties, indexers, operators, etc. Familiar lambda arrow syntax Properties are created as getter only Can only be single expression public string FullName => FirstName + " " + LastName;
  • 27. Null propagation Conditional access operator Returns null if qualifier is null, else evaluates Short circuiting Conditional method invocation, indexer access Left hand side evaluated only once – thread safe int? length = customers?.Length; int length2 = customers?.Length ?? 0;
  • 28. Await in catch/finally Implementation detail Previously “impossible” IL cannot branch into or out of catch/finally Uses ExceptionDispatchInfo to save exception state and rethrow if necessary
  • 29. Exception filters Existing CLR feature Only run catch block if exception handler returns true Replaces if () throw; pattern Expected “abuse” – logging catch (Exception e) when (Log(e)) { // ... } private bool Log(Exception exception) { Debug.WriteLine(exception); return false; }
  • 30. String interpolation $"My name is {name} and I’m {person.Age} years old" Compiles to string.Format Holes can contain expressions – e.g. $"Hi {GetName(person)}" Uses current culture by default Format specifiers – e.g. $"{foo:D}” Does not work with stored resource strings Verbatim strings can contain strings. What!?
  • 31. Formattable strings Interpolated strings converted to FormattableString by FormattableStringFactory.Create Passed to method that returns a string formatted as required, e.g. Invariant culture, URL encoding, SQL Provide own FormattableString implementations on downlevel versions
  • 32. Summary Roslyn Complete rewrite Easier to maintain Open Source Compiler as a service IDE features, scripting, hosting compilers Language features Auto property initialisers Getter only auto properties Index initialisers Using static members Null propagation Expression bodied members nameof operator Await in catch/finally Exception filters
  • 33. Bonus – C# 7.0 Strong interest Tuples Pattern matching Records Non-nullable types Async streams (observables) + disposable Some interest Covariant return types Expanded expression trees Syntax for lists + dictionaries Deterministic disposal Immutable types Type providers Scripting Method contracts yield foreach params IEnumerable more...

Editor's Notes

  • #5: C# 1.0 released in 2002 C# 1.2 released for .net 1.1. Called Dispose on IEnumerators which also implemented IDisposable. A few other features Anonymous methods – code blocks for delegates. NOT lambdas
  • #6: C# 1.0 released in 2002 C# 1.2 released for .net 1.1. Called Dispose on IEnumerators which also implemented IDisposable. A few other features Anonymous methods – code blocks for delegates. NOT lambdas
  • #8: I can take *in* a larger type than I was requesting, e.g. IEnumerable<Cat> passed into IEnumerable<Animal>
  • #9: Caller info – CallerFilePathAttribute, CallerLineNumberAttribute, CallerMethodNameAttribute Couple of minor fixes to scoping of variables in foreach loops, and order of evaluation of named and positional parameters
  • #12: Open Source – taken contributions. Nothing major, but e.g. improvements to error messages
  • #14: In the old world – compiler was one parser, language services was another parser, and expression evaluator was a third. Roslyn unifies all of these, which is a good thing
  • #16: Lots of other changes – no msbuild project file, json for configuration, heavily intertwined with NuGet, based on OWIN, etc.
  • #24: Also, collection initialisers will now use Add extension methods
  • #25: Again, about brevity Some talk of substituting, e.g. Console.WriteLine for Debug.WriteLine, but don’t approve of that Useful for e.g. System.Math, Logger.Log Error if there’s an ambiguity e.g. using Console + Debug, and call WriteLine ReSharper: Good support – missing QF + CA Parses, code completion in using list, code completion for symbols, resolves, find usages, navigation Missing QF + CA, control flow redundant code in qualifier
  • #26: For getting rid of magic strings. E.g. Reflection, PropertyChanged, ArgumentException Stems from typeof and mythical infoof Short name. Drops type parameters. Last name of namespace Type parameter is unsubstituted. Aliases are unsubstituted Nameof(int) vs nameof(int32) Interesting questions for refactoring, as name can be ambiguous – what if I rename one of the symbols in the set? ReSharper support: None. Tries to resolve symbol called nameof namespace A.B.C { class C { } } namespace D.E.F { class C { } // same generic arity } namespace G.H.I { class C<T, U, V> { } } namespace X { using A.B.C; using D.E.F; using G.H.I; class X { // here 'C' reference means three different 'C' types // no 'ambiguous reference' error produced at all void M(string s) => M(nameof(C)); } }
  • #27: Must be a statement for void methods, so return value isn’t even ignored ReSharper support: Full Parses, resolves, find usages, control flow Inspection on property getter return statement CA on return statement of simple method CA on expression bodied member
  • #28: Evaluates left to right If it’s any step is null, returns null, short circuits *all* following steps Conditional method invocations can be skipped if null Lifts type to be a nullable type – use null coalescing to reduce back down to type Grouping with brackets (customers?[0]?).ToUpper() <- need better example Grouping with brackets break out of short circuiting uses result as qualifier (because using the access operator, not the conditional access operator) Cannot do delegate?(args), must do delegate?.Invoke(args) Thread safe due to LHS only evaluated once + stored in temporary variable, so useful for event handlers
  • #29: Where TryRoslyn is really nice. Can see exactly what the implementation is
  • #30: Order of filters is important Previous syntax was “if”, but that broke existing code with an if in a catch statement