BuildingCoder.CmdPurgeLineStyles.PurgeGraphicStyles C# (CSharp) Method

PurgeGraphicStyles() private method

Purge all graphic styles whose name contains the given substring. Watch out what you do! If your substring is empty, this might delete all graphic styles in the entire project!
private PurgeGraphicStyles ( Document doc, string name_substring ) : void
doc Document
name_substring string
return void
        void PurgeGraphicStyles( 
            Document doc,
            string name_substring)
        {
            FilteredElementCollector graphic_styles
            = new FilteredElementCollector( doc )
              .OfClass( typeof( GraphicsStyle ) );

              int n1 = graphic_styles.Count<Element>();

              IEnumerable<Element> red_line_styles
            = graphic_styles.Where<Element>( e
              => e.Name.Contains( name_substring ) );

              int n2 = red_line_styles.Count<Element>();

              if( 0 < n2 )
              {
            using( Transaction tx = new Transaction( doc ) )
            {
              tx.Start( "Delete Line Styles" );

              doc.Delete( red_line_styles
            .Select<Element, ElementId>( e => e.Id )
            .ToArray<ElementId>() );

              tx.Commit();

              TaskDialog.Show( "Purge line styles",
            string.Format(
              "Deleted {0} graphic style{1} named '*{2}*' "
              + "from {3} total graohic styles.",
              n2, ( 1 == n2 ? "" : "s" ),
              name_substring, n1 ) );
            }
              }
        }