Find all optional parameters and delete them.

Using the optional parameters in several classes here and there, I do not like them very much due to the fact that in certain cases they lead to problems with overloading, i.e. difficulties in binding delegates to them due to signature conflicts, as well as dynamic calls regarding the number of method arguments.

How can I search all files in a Visual Studio IDE (2010) project and find all optional usage parameters? Maybe there is a clever regex that I could use? Or perhaps using an older version of Visual Studio, where optional parameters are not supported? I try to avoid problems with manually scanning files in a project, as this can be tedious and error prone. Thanks!

+4
source share
2 answers

Your best bet may be a reflection - it should be easy enough to go through all the members of all types, where they are methods, and they have at least one optional parameter.

This does not replace you, but it can give you a list of all abusive members.

Sort of:

foreach (Type tp in currentAssembly.GetTypes()) foreach (MethodInfo func in tp.GetMethods()) if(func.GetParameters().Any(p=>p.IsOptional)) Console.WriteLine(func.ToString()); 
+6
source

Although this is probably not the best way, I tend to look at Class View in visual studio. Types shown in square brackets are optional parameters.

+1
source

All Articles