0

I've got a lot of methods with variuos parameters:

method1(int a, byte b, string c){ ... }  
method2(object d, DateTime f){ ... }  
...
methodN(short g, short h, string i, object j){ ... }

The numbers and types of parameters are different everywhere but inside all those methods I have to enumerate them all as [param name]:[value]. Don't ask me why :)
Is there a way do to it without putting them together explicitly one by one? Is there something like method context that I can ask what parameters have come to the current method?

LINQ2Vodka
  • 2,996
  • 2
  • 27
  • 47
  • No, this isn't Javascript. There is no `arguments` array. – xanatos Mar 09 '17 at 14:02
  • With C#6: `string paramValue = $"{nameof(a)}:{a}";`. If you want to enumerate all parameter there is only reflection. But i wouldn't use it without a really good reason – Tim Schmelter Mar 09 '17 at 14:03
  • 1
    Also similar question is http://stackoverflow.com/questions/2147368/using-reflection-to-analyze-parameters-and-their-values – Sergey Berezovskiy Mar 09 '17 at 14:03
  • 1
    The dup Q&A has an answer which can really assist you: http://stackoverflow.com/a/4717320/411632 (AOP) – Matías Fidemraizer Mar 09 '17 at 14:04
  • crap yes! Thank you all guys, helped a lot! – LINQ2Vodka Mar 09 '17 at 14:04
  • I saw AOP mentioned in duplicates, but didn't see concrete implementation (PostSharp) is mentioned there. With PostSharp (free version) you can do that easily. – Evk Mar 09 '17 at 14:27
  • Nowadays a feature that could be used to achieve this is [Roslyn's Source Generators](https://github.com/dotnet/roslyn/blob/master/docs/features/source-generators.md). Check [this answer](https://stackoverflow.com/questions/4717291/get-methods-parameters-names-and-values-from-inside-method/63277169#63277169) – CicheR Aug 06 '20 at 05:25

0 Answers0