C# Brief training: Extended Property Pattern

Learn more about C# in 3–5 minutes

Luiz Felipe
2 min readJun 16, 2022

--

Summary

  • What is an extended property pattern?
  • Implementing extended property pattern.
  • Conclusion

What is an extended property pattern?

Extended property patterns allow sub-patterns to reference nested members. It is useful when doing a pattern match for an if statement.

Implementing extended property pattern.

For simplicity’s sake, I created two simple classes so I can use them to demonstrate an example of how the extended property pattern works and show you how cool it is! It's going to look like this:

Now, all we have to do is verify if there's a pattern match and we can do this in C# 10 by typing:

We instantiated our Blog class and we're verifying if its property called title is equal to Brief C# Training. That's it, pretty simple, right?

We can also navigate to properties from child classes by just using dots without using any other curly braces, isn't that amazing and easy to use? So, it will look like this:

Conclusion

This is Extended Property Pattern! If you want to verify properties within an object without hurting the readability of your code extended property pattern is a good solution.

Will you use an extended property pattern from now? Did you like it? Let me know right down in the comments. See ya!

--

--