
I have the class on C#. E.g it contains the property 'A':
This class also contains the method 'B' that uses Property 'A' in the various cases within body.
I need to delete any occurrences of 'A' within body of method 'B'.
It sounds like this might be done via enumerating all statements of MethodDeclaration of 'B' and if it contains simple name equal 'A' delete it like this:It appears this is very difficult because there are a lot of types of Statements and they could be used in manifold cases.
What means could be used to resolve this task?
Thanks in advance.
private string a_;
public string A
{
get { return a_; }
set { a_ = value; }
}
public void B()
{
if (!string.IsNullOrEmpty(A))
A = string.Format("{0}", A.ToLower());
// and others cases.
}
It sounds like this might be done via enumerating all statements of MethodDeclaration of 'B' and if it contains simple name equal 'A' delete it like this:
CompilationUnit cu = (CompilationUnit)document_.SemanticParseData;
foreach (TypeDeclaration typeDeclaration in cu.Types)
{
foreach (AstNodeBase childNode in typeDeclaration.ChildNodes)
{
MethodDeclaration node = childNode as MethodDeclaration;
if (node != null)
{
if (node.Name.Text == "B")
{
// 1. go over node.ChildNodes and get statements
// 2. Statement st = node as IfStatement; // there could be switch to check all variants of statements.
// 3 . Get SimpleName and compare to 'A'
// if step 3 return true replace like this :
// document_.ReplaceText(DocumentModificationType.Replace, simpleName.TextRange, string.Empty);
}
}
}
}
What means could be used to resolve this task?
Thanks in advance.