No library is required, .Net has always had this feature. In fact the interpolation shown is new and few know it. This is the first time I meet someone who knows the new feature, not the old one.
It may not work well with the syntax you want, but this syntax to resolve at runtime is bad and error-inducing and matches names that the code can not always guarantee.
It's technically possible to make a library that accepts variable names instead of parameter numbers, but I do not see any advantages.
Note that the example shown can not do anything because you would have to pass the parameter at run-time. In fact not even using C # 6 interpolation this code works.
What you want is what you do with string.Format()
. The same one that has always been used internally in a WriteLine()
, for example.
var texto = string.Format("{0}", firstname);
See running on dotNetFiddle and on CodingGround .
C # 6 interpolation is a compile-time mechanism. I 'm talking about it in the question What does the "$" symbol mean before a string?
I'll quote a few libraries, but think 10 times before adopting them, it may seem like a good thing, but it's not what you need. I do not know them, I can not speak of their quality:
It has a code in CR.SE that can be an inspiration to make the mechanism itself (it is not easy think of everything).