void RemoveTransparentIdentifierReferences(AstNode node, string transparentIdentifier)
{
foreach (AstNode child in node.Children) {
RemoveTransparentIdentifierReferences(child, transparentIdentifier);
}
MemberReferenceExpression mre = node as MemberReferenceExpression;
if (mre != null) {
IdentifierExpression ident = mre.Target as IdentifierExpression;
if (ident != null && ident.Identifier == transparentIdentifier) {
IdentifierExpression newIdent = new IdentifierExpression(mre.MemberName);
mre.TypeArguments.MoveTo(newIdent.TypeArguments);
newIdent.CopyAnnotationsFrom(mre);
newIdent.RemoveAnnotations<PropertyDeclaration>(); // remove the reference to the property of the anonymous type
mre.ReplaceWith(newIdent);
return;
} else if (mre.MemberName == transparentIdentifier) {
var newVar = mre.Target.Detach();
newVar.CopyAnnotationsFrom(mre);
newVar.RemoveAnnotations<PropertyDeclaration>(); // remove the reference to the property of the anonymous type
mre.ReplaceWith(newVar);
return;
}
}
}