Brian Button - One Agile Coder

Blogging on all things .Net, C#, and Agile

My Links

Blog Stats

News

Archives

Post Categories

Agile Solutions Group

Blogs I read

Enterprise Library V1 Team

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

posted on Tuesday, October 23, 2007 12:57 PM

Feedback

# Interesting Finds: October 24, 2007 10/24/2007 7:15 AM Jason Haley

# re: Finding all Attribute types in an assembly through powershell 10/25/2007 9:33 AM Tim Ottinger

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.

# re: Finding all Attribute types in an assembly through powershell 10/25/2007 6:57 PM Brian Button

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

Title  
Name  
Url
Spam Protection:
Enter the code you see:
If you can't read it, click your refresh button to get a new image.
Comments