MVP Showcase 2015 - C#
-
Upload
paulo-morgado -
Category
Software
-
view
211 -
download
1
Transcript of MVP Showcase 2015 - C#
![Page 1: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/1.jpg)
Independent Experts – Real World AnswersIndependent Experts – Real World Answers
Microsoft MVP Showcase22 Abril 2015
C#Paulo Morgado
.NET / C#
![Page 2: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/2.jpg)
Independent Experts – Real World AnswersIndependent Experts – Real World Answers
Social ResponsabilityMicrosoft MVP Showcase
22 Abril 2015
“OS DOUTORES PALHAÇOS
LEVAM ALEGRIA ÀS CRIANÇAS
HOSPITALIZADAS EM PORTUGAL”
http://www.narizvermelho.pt/
![Page 3: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/3.jpg)
Independent Experts – Real World Answers
Paulo Morgado.NET / C#
PauloMorgado
![Page 4: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/4.jpg)
Independent Experts – Real World AnswersIndependent Experts – Real World Answers
![Page 5: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/5.jpg)
Independent Experts – Real World Answers
![Page 6: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/6.jpg)
Independent Experts – Real World AnswersIndependent Experts – Real World Answers
![Page 7: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/7.jpg)
Independent Experts – Real World Answers
![Page 8: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/8.jpg)
Independent Experts – Real World AnswersIndependent Experts – Real World Answers
![Page 9: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/9.jpg)
Independent Experts – Real World Answers
![Page 10: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/10.jpg)
Independent Experts – Real World AnswersIndependent Experts – Real World Answers
![Page 11: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/11.jpg)
Independent Experts – Real World Answers
![Page 12: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/12.jpg)
Independent Experts – Real World AnswersIndependent Experts – Real World Answers
Foo(); var task = FooAsync();
From the method signature (how people call it)
void Foo(){
for (int i=0; i<100; i++)Math.Sin(i);
}
From the method implementation (what resources it uses)
async Task FooAsync(){
await client.DownloadAsync();}
![Page 13: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/13.jpg)
Independent Experts – Real World AnswersIndependent Experts – Real World Answers
Is this true for your async methods?
![Page 14: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/14.jpg)
Independent Experts – Real World Answers
![Page 15: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/15.jpg)
Independent Experts – Real World AnswersIndependent Experts – Real World Answers
synchronous block the current thread
asynchronous without spawning new threads
![Page 16: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/16.jpg)
Independent Experts – Real World AnswersIndependent Experts – Real World Answers
void Foo() { FooAsync().Wait(); } -- will deadlock!!!
![Page 17: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/17.jpg)
Independent Experts – Real World Answers
![Page 18: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/18.jpg)
Independent Experts – Real World AnswersIndependent Experts – Real World Answers
![Page 19: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/19.jpg)
Independent Experts – Real World Answers
![Page 20: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/20.jpg)
Independent Experts – Real World AnswersIndependent Experts – Real World Answers
![Page 21: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/21.jpg)
Independent Experts – Real World Answers
![Page 22: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/22.jpg)
Independent Experts – Real World AnswersIndependent Experts – Real World Answers
![Page 23: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/23.jpg)
Independent Experts – Real World AnswersIndependent Experts – Real World Answers
![Page 24: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/24.jpg)
Independent Experts – Real World AnswersIndependent Experts – Real World Answers
![Page 25: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/25.jpg)
Independent Experts – Real World Answers
![Page 26: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/26.jpg)
Independent Experts – Real World AnswersIndependent Experts – Real World Answers
![Page 27: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/27.jpg)
Independent Experts – Real World Answers
![Page 28: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/28.jpg)
Independent Experts – Real World AnswersIndependent Experts – Real World Answers
![Page 29: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/29.jpg)
Independent Experts – Real World Answers
![Page 30: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/30.jpg)
Independent Experts – Real World AnswersIndependent Experts – Real World Answers
public class Customer
{
public string First { get; set; } = "Jane";
public string Last { get; set; } = "Doe";
}
![Page 31: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/31.jpg)
Independent Experts – Real World AnswersIndependent Experts – Real World Answers
public class Customer
{
public string Name { get; };
public Customer(string first, string last)
{
Name = first + " " + last;
}
}
public class Customer
{
public string First { get } = "Jane";
public string Last { get; } = "Doe";
}
![Page 32: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/32.jpg)
Independent Experts – Real World AnswersIndependent Experts – Real World Answers
public Point Move(int dx, int dy) => new Point(x + dx, y + dy);
public static Complex operator +(Complex a, Complex b) => a.Add(b);
public static implicit operator string (Person p) => p.First + " " + p.Last;
public void Print() => Console.WriteLine(First + " " + Last);
![Page 33: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/33.jpg)
Independent Experts – Real World AnswersIndependent Experts – Real World Answers
public string Name => First + " " + Last;public Customer this[long id] => store.LookupCustomer(id);
![Page 34: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/34.jpg)
Independent Experts – Real World AnswersIndependent Experts – Real World Answers
using static System.Console;using static System.Math;using static System.DayOfWeek;class Program{
static void Main(){
WriteLine(Sqrt(3 * 3 + 4 * 4));WriteLine(Friday - Monday);
}}
![Page 35: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/35.jpg)
Independent Experts – Real World AnswersIndependent Experts – Real World Answers
using static System.Linq.Enumerable; // The type, not the namespaceclass Program{
static void Main(){
var range = Range(5, 17); // Ok: not extensionvar odd = Where(range, i => i % 2 == 1); // Error, not in scopevar even = range.Where(i => i % 2 == 0); // Ok
}}
![Page 36: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/36.jpg)
Independent Experts – Real World AnswersIndependent Experts – Real World Answers
int? length = customers?.Length; // null if customers is nullCustomer first = customers?[0]; // null if customers is null
int length = customers?.Length ?? 0; // 0 if customers is null
int? first = customers?[0].Orders?.Count(); // can be chained
PropertyChanged?.Invoke(this, args); // delegate invokation
![Page 37: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/37.jpg)
Independent Experts – Real World AnswersIndependent Experts – Real World Answers
var s = $"{p.Name} is {p.Age} year{{s}} old";
var s = $"{p.Name,20} is {p.Age:D3} year{{s}} old";
var s = $"{p.Name} is {p.Age} year{(p.Age == 1 ? "" : "s")} old";
![Page 38: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/38.jpg)
Independent Experts – Real World AnswersIndependent Experts – Real World Answers
if (x == null) throw new ArgumentNullException(nameof(x));
WriteLine(nameof(person.Address.ZipCode)); // prints "ZipCode"
![Page 39: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/39.jpg)
Independent Experts – Real World AnswersIndependent Experts – Real World Answers
var numbers = new Dictionary<int, string>{
[7] = "seven",[9] = "nine",[13] = "thirteen"
};
![Page 40: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/40.jpg)
Independent Experts – Real World AnswersIndependent Experts – Real World Answers
try { … }catch (SqlException e) when (myfilter(e)){
…}
![Page 41: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/41.jpg)
Independent Experts – Real World AnswersIndependent Experts – Real World Answers
Resource res = null;try{
res = await Resource.OpenAsync(…); // You could do this.…
}catch (ResourceException e){
await Resource.LogAsync(res, e); // Now you can do this …}finally{
await res?.CloseAsync(); // … and this.}
![Page 42: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/42.jpg)
Independent Experts – Real World AnswersIndependent Experts – Real World Answers
![Page 43: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/43.jpg)
Independent Experts – Real World AnswersIndependent Experts – Real World Answers
![Page 44: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/44.jpg)
Independent Experts – Real World Answers
![Page 45: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/45.jpg)
Independent Experts – Real World AnswersIndependent Experts – Real World Answers
![Page 46: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/46.jpg)
Independent Experts – Real World AnswersIndependent Experts – Real World Answers
CompilationUnit
ClassDeclaration
MethodDeclaration
class C{
void M(){}
}// C▫
ParameterList Block
var tree = CSharpSyntaxTree.ParseText("...");
![Page 47: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/47.jpg)
Independent Experts – Real World AnswersIndependent Experts – Real World Answers
CompilationUnit
ClassDeclaration
class C { MethodDeclaration }
EOF
void M ParameterList Block
( ) { }
class C{
void M(){}
}// C▫
![Page 48: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/48.jpg)
Independent Experts – Real World AnswersIndependent Experts – Real World Answers
class∙C{∙∙∙∙void∙M()∙∙∙∙{∙∙∙∙}}// C▫
CompilationUnit
ClassDeclaration
class C { MethodDeclaration }
EOF
void M ParameterList Block
( )
{ }
SP EOL EOL // C
SPx4 SP
EOL
EOL
EOLSPx4 EOL SPx4
![Page 49: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/49.jpg)
Independent Experts – Real World Answers
![Page 50: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/50.jpg)
Independent Experts – Real World AnswersIndependent Experts – Real World Answers
http://blogs.msdn.com/b/lucian/archive/2013/11/23/talk-mvp-summit-async-best-practices.aspx
http://channel9.msdn.com/Series/Three-Essential-Tips-for-Async/Three-Essential-Tips-For-Async-Introduction
http://curah.microsoft.com/45553/asyncawait-general
http://curah.microsoft.com/44400/async-and-aspnet
![Page 51: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/51.jpg)
Independent Experts – Real World AnswersIndependent Experts – Real World Answers
https://github.com/dotnet/roslyn/wiki/New-Language-Features-in-C%23-6
![Page 52: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/52.jpg)
Independent Experts – Real World AnswersIndependent Experts – Real World Answers
https://github.com/roslyn
https://roslyn.codeplex.com/
https://github.com/code-cracker/
https://github.com/dotnetAnalyzers/
https://github.com/icsharpcode/NRefactory/tree/roslyn
![Page 53: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/53.jpg)
Independent Experts – Real World AnswersIndependent Experts – Real World Answers
CommunitiesMicrosoft MVP Showcase
22 Abril 2015
![Page 54: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/54.jpg)
Independent Experts – Real World AnswersIndependent Experts – Real World Answers
We <3 love our sponsors !Microsoft MVP Showcase
22 Abril 2015
![Page 55: MVP Showcase 2015 - C#](https://reader035.fdocuments.us/reader035/viewer/2022062514/55a607b91a28abed248b480a/html5/thumbnails/55.jpg)
Independent Experts – Real World AnswersIndependent Experts – Real World Answers