Finding all Attribute types in an assembly through powershell

I was using the new xunit.net testing framework, and I wanted to see a list of all the attributes they had. This looks like a job for Powershell!!!


[System.Reflection.Assembly]::LoadFile("pathToFile.dll").GetTypes() | where-object { $_ -match "Attribute" }

That did the trick!

— bab

2 thoughts to “Finding all Attribute types in an assembly through powershell”

  1. I had to go look up Powershell on Wikipedia. It’s a windows thing and I am not used to being on or around windows much these days. Is that a Vista thing or did it appear sometime between XP and Vista?

    You could do the same in *nix systems with nm and grep or awk in a little less space, but the .getTypes() being so specific is kinda nice.

  2. Hi, Tim,

    Powershell is actually really nice. I, like you, have been a Unix/Linux hacker for years, and I can write just about anything in bash I could ever want to.

    But Powershell is different. You are passing objects around between cmdlets, so you can do a lot more. You also have access to the entire .Net library, so you can do a lot of cool things, and you can access just about any program that publishes a COM interfaace.

    Powershell was supposed to be part of Vista, but it got unbundled. You can download it from microsoft.com now.

    nm -ag <libname> | grep "Attribute" or something like that? Not sure about the arguments to nm. I know you want all global symbols. Is there a way using nm to get class declarations, or just functions?

    — bab

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.