X

C#

Universal hierarchy traversing in C#

I started playing with small idea about how to go through document repository on SharePoint using more universal approach than just piling code to using-blocks and methods that depend on these. My goal was to separate in code hierarchy traversing logic from document exporting logic so I can use traversing part also in other projects on different types of hirarchies. Here is my nice and clean solution.

Breaking static dependency

Static dependency can be nightmare for developers who write tests for their code. There is not much to do to get rid of static dependencies if they come with third-party libraries or NuGet packages. This blog post introduces two tricks to make code with static dependencies testable.

Using-declarations in C# 8.0

One of new language features of C# 8.0 is support for using declarations. These declarations enable shorter syntax for declaring disposable variables we want to dispose. Also using declarations give us a little bit cleaner code while compiler makes a dirty work of producing correct code that takes care of disposing disposable variables.

String repeat method for C#

C# doesn’t have built-in function to repeat a string. There are different version for string.Repeat() available in internet and it’s up to reader to find out which version works better. Here is the list of most popular implementations I found across the web. I list my findings here with the results of simple performance test.

Adding attribute to backing field of automated property

There are scenarios where developers want to add attributes to backing field of automated property. It was hard to do before C# 7.3. Now it is supported in Visual Studio and solution is simple. This blog post shows how to add attribute to backing field of automated property.

Pattern matching in switch statements

One of new features introduced by C# 7.0 is support for pattern matching in switch statements. It’s like mix of switch and if statements so we don’t have to nest these two. This blog post introduces pattern matching in switch statements and shows what C# compiler produces of switch statements.

Non-trailing named arguments in C# 7.2

One small change that comes with C# 7.2 is support for non-trailing named arguments in method calls. This post explains what are non-trailing named arguments, how to use them and how they look after compiling.

protected private access modifier in C# 7.2

C# 7.2 introduces new access modifier – protected private. It targets developers who are responsible for class libraries and API-s design and who need also consistent design for internals of class libraries. This blog post shows how protected private access modifier works.

Default literal expressions in C# 7.1

C# 7.1 introduces a little update to default literal expressions that makes them a little bit shorter and on some cases helps us write cleaner and more readable code. This blog post introduces this litlle feature update in C# 7.1.

Inferred tuple names in C# 7.1

Although C# 7.1 hasn’t many new features there are still some convenience hacks I like. One of these is inferred tuple names meaning that we can name tuple members using variable names. It’s not a big change in language but it still makes code a little bit cleaner where tuples are used.