What is FindParentElement??

Aug 24, 2012 at 2:46 PM

I want to know what does FindParentElement return?

I am writing a custom rule to make regions mandatory for all the methods in a C# code file.

So i am trying to

1. parse the CSDocument for all the tokens,  and raising a violation only for the methods that do not have region.

2. Trying to find ParentElement of a token and if the parent element is method and is not having a region then raising the vioaltion.

3. But the if condiotin to findparent element is not getting executed

for (Node<CsToken> tokenNode = document.Tokens.First; tokenNode != null; tokenNode = tokenNode.Next)
            {
                CsToken token = tokenNode.Value;
                CsElement element = token.FindParentElement();
                if (element.ElementType == ElementType.Method)
                {
                    if (token.CsTokenClass != CsTokenClass.RegionDirective)
                    {
                        base.AddViolation(element, "UseRegionsForAllTheCodeBlocks", new object[0]);
                    }
                }
            }

Can anyone help me .