예제 #1
0
 /// <summary>
 /// checks if a property with the given name is enclosed
 /// by a region with the given name
 /// </summary>
 /// <param name="classDeclaration"></param>
 /// <param name="regionName"></param>
 /// <param name="propertyName"></param>
 /// <returns>true if there is a property between the region,
 /// false otherwise</returns>
 public static bool IsPropertyBetweenRegion(
     ClassDeclarationSyntax classDeclaration, 
     string regionName,
     string propertyName)
 {
     // assert: the method must be between the region
     // get begin and end region
     var beginRegion = classDeclaration.FindRegionByText(regionName);
     var endRegion = classDeclaration.FindEndRegion(regionName);
     // get all nodes between the regions
     var span = new TextSpan(beginRegion.Span.End, endRegion.Span.Start);
     var nodesBetweenRegion = classDeclaration.DescendantNodes(span);
     // check that a property declaration for a "Name" property is there
     var isPropertyBetweenRegion = nodesBetweenRegion
         .OfType<PropertyDeclarationSyntax>()
         .Any(x => x.Identifier.ToString() == propertyName);
     return isPropertyBetweenRegion;
 }