I want to perform parameter validation at compile time for an extension method.
Something like this
Here is the sample code of my program to validate
public class Program
{
static void Main(string[] args)
{
var sample = new Sample();
var output = sample.SampleMethod("To Validate"); // I want to validate this param
}
}
public static class Ext
{
public static string SampleMethod(this Sample sample, string sampleParam)
{
return sampleParam + " Hello";
}
}
public class Sample
{
}
I am planning to use Roslyn but I don't know the Action
to register and to get the parameter value that passed.
Sample code to validate parameter for a method using Roslyn will be very helpful