Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- IList<FileInfo> fileInfos =
- new DirectoryInfo( "/path/to/reference/source/directory" )
- .GetFiles( "*.cs" )
- .ToList( );
- Console.WriteLine( $"found {fileInfos.Count} cs files" );
- int globalAllmanCount = 0;
- int globalKAndRCount = 0;
- int globalMixedCount = 0;
- void UpdateStats( int allmanCount, int kAndRCount ) {
- if( allmanCount+kAndRCount == 0 )
- return;
- float kAndRPercent = kAndRCount*100f/( allmanCount+kAndRCount );
- if( kAndRPercent <= .1f )
- ++globalAllmanCount;
- else if( kAndRCount >= .9f )
- ++globalKAndRCount;
- else
- ++globalMixedCount;
- }
- async Task ScanFile( FileInfo fi ) {
- using StreamReader sr = new(fi.OpenRead( ));
- string line;
- int allmanCount = 0;
- int kAndRCount = 0;
- while( ( line = await sr.ReadLineAsync( ) ) != null ) {
- if( !line.Contains( '{' ) )
- continue;
- if( string.IsNullOrWhiteSpace( line.Split( '{' )[ 0 ] ) )
- ++allmanCount;
- else
- ++kAndRCount;
- }
- UpdateStats( allmanCount, kAndRCount );
- }
- int cnt = 0;
- foreach( FileInfo fi in fileInfos ) {
- await ScanFile( fi );
- ++cnt;
- Console.Write( $"\rscanned {cnt}/{fileInfos.Count} files {cnt*100f/fileInfos.Count:0.00}%" );
- }
- Console.WriteLine( );
- int globalTotal = globalAllmanCount+globalKAndRCount+globalMixedCount;
- Console.WriteLine( $"K&R style: \t{globalKAndRCount*100f/globalTotal:0.00}%" );
- Console.WriteLine( $"Allman style: \t{globalAllmanCount*100f/globalTotal:0.00}%" );
- Console.WriteLine( $"mixed style: \t{globalMixedCount*100f/globalTotal:0.00}%" );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement