Skip to content

Instantly share code, notes, and snippets.

@wholroyd
Last active August 28, 2017 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wholroyd/e23c2727cb4eb0f9b3a435b4529a1c49 to your computer and use it in GitHub Desktop.
Save wholroyd/e23c2727cb4eb0f9b3a435b4529a1c49 to your computer and use it in GitHub Desktop.
C# 8 Syntax Suggestions

Current syntax for extensions on a reference type...

public static class PersonExtensionClass
{
  public string FullName(this Person person)
  {
    return $"{person.FirstName} {person.MiddleName} {person.LastName}";
  }
}

Current proposed syntax for extensions on a reference type...

public extension PersonExtensionClass extends Person
{
  public string FullName()
  {
    return $"{this.FirstName} {this.MiddleName} {this.LastName}";
  }
}

My proposed syntax for extensions on a reference type is mainly around the class declaration itself, not the logic being suggested within the class definition itself. My main gripe is that the proposal is for extensions to become their own classes in itself, as they would also maintain their own state, aren't following the syntax of normal classes. If extensions should be able to extend other extensions, there is the requirement to inheir like normal classes.

public extension PersonExtensionClass<IPerson>
{
  // code
}
public extension PersonExtensionClassOfExtensionClass<IPerson> : PersonExtensionClass<IPerson>, IDisposable
{
  // code
}

Seems a bit more natural in this usage to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment