Value type methods – call, callvirt, constrained and hidden boxing

Long time ago I wrote a post here on  call vs callvirt and the needed of the this null check. Here I want to wrote about this topic but on value types.

Look on these three ToString() calls: Continue reading

Advertisements
Posted in .NET, c#, Roslyn | Tagged , , , , , , , | Leave a comment

Make method static with Roslyn

Before Roslyn days, this was not easy to do that, like others re factoring.

Fortunately we have R# for this.

But now it’s not so hard to re factor an instance method into static method.

I wrote a rewriter that convert any Continue reading

Posted in .NET, c#, Roslyn | Tagged , , , , , | Leave a comment

What is the @ sign before a variable name

You probably saw this at least once

var @delegate = ...

Or especially in generated code (like if you let R# to do some rewriting for you) you can see

var @t = ...

So, what is it? the simple answer is the ‘@’ sign can be added to a reserved word and then you can define for example variable that with the name “@delegate” but you can not define “delegate” variable.

But what special with ‘@’ ? you can add any other characters like “_delegate”?

It’s indeed different because when you add the ‘@’ sign, in the assembly the variable name is Continue reading

Posted in .NET, c# | Tagged , , , , | Leave a comment

Convert linq query syntax to fluent syntax

In c# you can write LINQ queries in two ways. One is the fluent invocation syntax (extension method) and the other is query comprehension syntax.

Fluent example:

Enumerable.Range(1, 5).
Where(i => i % 2 == 0).
Select(i => i * 2);

Comprehension example:

from i in Enumerable.Range(1, 5)
where i % 2 == 0
select i * 2;

I was needed the ability to take the comprehension syntax and convert it to fluent syntax. So I wrote a rewriter with Roslyn that do exactly this.

Continue reading

Posted in .NET, c#, Roslyn | Tagged , , , , , , | Leave a comment