Adding partial method with access modifier example
MODIFY
src/Chapter06/Listing06.53.DefiningAPartialMethodToAccessItsImplementation.cs
src/Chapter06/Listing06.53.DefiningAPartialMethodToAccessItsImplementation.cs
@@ -56,6 +56,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_53
}
private string _FirstName;
+ public partial string GetName();
}
// File: Person.cs
@@ -63,10 +64,9 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_53
{
static partial void OnLastNameChanging(string value)
{
- if(value is null)
- {
+ value = value ??
throw new ArgumentNullException(nameof(value));
- }
+
if (value.Trim().Length == 0)
{
throw new ArgumentException(
@@ -77,10 +77,9 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_53
#region EXCLUDE
static partial void OnFirstNameChanging(string value)
{
- if(value == null)
- {
+ value = value ??
throw new ArgumentNullException(nameof(value));
- }
+
if (value.Trim().Length == 0)
{
throw new ArgumentException(
@@ -90,6 +89,9 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_53
}
}
#endregion EXCLUDE
+
+
+ public partial string GetName() => $"{FirstName} {LastName}";
}
#endregion INCLUDE
}

Adding partial method with access modifier example