-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
164 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 16 | ||
VisualStudioVersion = 16.0.29318.209 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotNetConf2019C8Part1", "DotNetConf2019C8Part1\DotNetConf2019C8Part1.csproj", "{87EC18E8-D16A-481C-B4C8-12D380CF0746}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PersonStandardLibrary", "PersonStandardLibrary\PersonStandardLibrary.csproj", "{1D722957-FCF3-4051-A026-B6BD1794F364}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PersonCoreLibrary", "PersonCoreLibrary\PersonCoreLibrary.csproj", "{75796B95-8CC8-4B21-85AB-26D2C2A81902}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{87EC18E8-D16A-481C-B4C8-12D380CF0746}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{87EC18E8-D16A-481C-B4C8-12D380CF0746}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{87EC18E8-D16A-481C-B4C8-12D380CF0746}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{87EC18E8-D16A-481C-B4C8-12D380CF0746}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{1D722957-FCF3-4051-A026-B6BD1794F364}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{1D722957-FCF3-4051-A026-B6BD1794F364}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{1D722957-FCF3-4051-A026-B6BD1794F364}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{1D722957-FCF3-4051-A026-B6BD1794F364}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{75796B95-8CC8-4B21-85AB-26D2C2A81902}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{75796B95-8CC8-4B21-85AB-26D2C2A81902}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{75796B95-8CC8-4B21-85AB-26D2C2A81902}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{75796B95-8CC8-4B21-85AB-26D2C2A81902}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {05AD5788-BACA-4174-B36F-EA8DFC585C18} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp3.0</TargetFramework> | ||
<LangVersion>8.0</LangVersion> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\PersonCoreLibrary\PersonCoreLibrary.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// https://www.youtube.com/watch?v=TJiLhRPgyq4 | ||
// What's new in C# 8 - Part 1 | ||
using System; | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
var miguel = new Person("Miguel", "Angulo"); | ||
var length = GetMiddleNameLength(miguel); | ||
Console.WriteLine(length); | ||
} | ||
|
||
static int GetMiddleNameLength(Person person) // Person person | ||
{ | ||
//var middle = person.MiddleName; | ||
//// if (middle == null) return 0; // to avoi the warning | ||
//if (middle is null) return 0; // this works if you overwriten the equality == operator | ||
//return middle.Length; //It is not null safe. if middle name = null you get an error | ||
|
||
// return person.MiddleName.Length; // we get a warning it myt be null | ||
|
||
// or | ||
//return person.MiddleName?.Length ?? 0; // this is correct by construction you read the variable once | ||
|
||
// if you think you know better | ||
// use bank ! - null ignoring operator | ||
// if (person.MiddleName is null) return 0; | ||
// return person.MiddleName!.Length; // I know better | ||
|
||
var middle = person.MiddleName; | ||
if (string.IsNullOrEmpty(middle)) return 0; | ||
return middle.Length; | ||
} | ||
|
||
//static int GetMiddleNameLength(Person? person) | ||
//{ | ||
// // 1 | ||
// // { } is it an Object or is it something | ||
// /* if ((person?.MiddleName is { })) return person.MiddleName.Length;*/ // Alt + Enter or Ctrl + . | ||
// // 2 | ||
// //if ((person?.MiddleName is { } middle)) return middle.Length; | ||
// // 3 | ||
// //if ((person?.MiddleName is {Length: var length })) return length; | ||
// //return 0; | ||
// // and now only 1 line | ||
// return ((person?.MiddleName is { Length: var length })) ? length : 0; | ||
//} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// #nullable disable warnings | ||
// #nullable disable annotations | ||
// #nullable disable | ||
public class Person | ||
{ | ||
public string FirstName { get; set; } | ||
public string? MiddleName { get; set; } // you have to make it nullable explicitly in C# 8.0 | ||
public string FamilyName { get; set; } | ||
|
||
// if in the project file of this lib we have <LangVersion>8.0</LangVersion> <Nullable>enable</Nullable> we get warning middleName is not assigned | ||
public Person(string firstName, string familyName) | ||
{ | ||
FirstName = firstName; | ||
// we can solve the warnig like this | ||
MiddleName = null; // but we get the warning Cannot convert null to non-nullable reference type. Strings are not null by default anymore. You have to make string nullable | ||
FamilyName = familyName; | ||
} | ||
|
||
#nullable disable | ||
public Person(string firstName, string middleName, string familyName) | ||
{ | ||
FirstName = firstName; | ||
MiddleName = middleName; | ||
FamilyName = familyName; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.0</TargetFramework> | ||
<LangVersion>8.0</LangVersion> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
public class Person | ||
{ | ||
public string FirstName { get; set; } | ||
public string MiddleName { get; set; } | ||
public string FamilyName { get; set; } | ||
|
||
|
||
//// Severity Code Description Project File Line Suppression State | ||
//Warning CS8618 Non-nullable property 'MiddleName' is uninitialized.Consider declaring the property as nullable.PersonStandardLibrary C:\Users\User\source\repos\DotNetConf2019C8Part1\PersonStandardLibrary\Person.cs 7 Active | ||
public Person(string firstName, string familyName) | ||
{ | ||
FirstName = firstName; | ||
FamilyName = familyName; | ||
} | ||
public Person(string firstName, string middleName, string familyName) | ||
{ | ||
FirstName = firstName; | ||
MiddleName = middleName; | ||
FamilyName = familyName; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<LangVersion>8.0</LangVersion><!-- Without this is not giving me warning --> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</Project> |