tags:

views:

48

answers:

1

I'm attempting to use CCI-Metadata for creating a code generator, by iterating over a set of assemblies, discovering the types and their metadata and then generating the code. I would like to be able to control the code generation by attaching custom attributes to the metadata of the original types.

Something like:

[GenerateSpecialClass(true, "foo", IsReallySpecial=false)]
public class MyClass { ... }

I have a INamedTypeDefinition and get an IEnumerable from the Attributes property. From here, I can't figure out what to do to get the value of custom attribute and it's properties.

Could someone give me a code sample: given an ICustomAttribute, how I can retrieve the values from my example attribute. Assume it's definition is:

public GenericSpecialClassAttribute : Attribute
{
    public bool Prop1 { get; set; }
    public string Prop2 {get; set; }
    public bool IsReallySpecial {get; set; }
    public GenericSpecialClassAttribute(bool prop1, string prop2)
    {
       Prop1 = prop1;
       Prop2 = prop2;
    } 
}

Any help would be very much appreciated. I assume I cast this to some other interface and do something magical on it; but I couldn't find a helper that did anything with it and don't fully understand the implementation/model hierarchy.

A: 

Check out Jason Bock's Injectors. I think he does what you are looking for in his InjectorContext.Find() method and then the looks up the different properties/parameters in the NotNullInjector.OnInject() method.

Get his code up and running, then you'll have a better understanding of how to do what you're looking to do.

Jason Haley