Thank you for your feedback.
Each IMethodInvocation has an IArguments property. The "IArguments" type holds the arguments collection. So if you want to iterate over the arguments of a method invocation you need:
There is also no need for you to cast the expression of an argument. You can directly access its type:
var expressionType = argument.Expression.Type;
isStringType = expressionType.Equals(argument.StringTypeAtThisLocation());
"StringTypeAtThisLocation" return the "String" type for the current language (this way your extension can work for any language that has "string" as a type.
I also noticed the way that you try to cast constructs. We recommend to use the JC API in order to cast one construct to another.
var expression = argument.Expression.As<IArgument>();
isArgument = argument.Expression.Is<IArgument>();
These methods never throw exceptions and the "As<>" method never returns null so that you will not need to do any null checks. If the cast fails we simply return a proxy object (a stub) that has the default behavior for the given type. And this way the execution of your code will continue without any exceptions.
Another thing that I would like to suggest is to use IConstructLanguage.AreNamesEqual method. This method knows whether the language is case sensitive or not and does the correct check. For instance:
fileModel.All<IMethodInvocation>().Where(x => x.Language.AreNamesEqual(x.Identifier.Name,
Please note that I also use x.Identifier.Name, not x.Identifier.Text. Although, they both return the same thing, the "Name" property is much more faster.
If you have any more questions or remarks, please do not hesitate to contact us again!
the Telerik team
Share what you think about JustCode with us, so we can help you even better! You can use the built-in feedback tool inside JustCode, our forum
, or our JustCode