Question

I'm trying to use some reflection in a .tt file, more specifically to determine the KnownTypes on a class. To do this I just use simple reflection, or rather want to use simple reflection, but when I try to:

List<String> GetKnownTypes(EntityType entity)
{
    List<String> knownTypes = new List<String>();
    System.Reflection.MemberInfo info = typeof(EntityType);
    object[] attributes = info.GetCustomAttributes(typeof(KnownTypeAttribute), false);
    for (int i = 0; i < attributes.Length; i++)
    {
        KnownTypeAttribute attr = (KnownTypeAttribute)attributes[i];
        knownTypes.Add(attr.Type.Name);
    }
    return knownTypes;
 }

I get slapped around the ears with an error:

Error 1 Compiling transformation: The type or namespace name 'KnownTypeAttribute' could not be found (are you missing a using directive or an assembly reference?)

But, I have a reference to System.Runtime.Serialization. I also import <#@ import namespace="System.Runtime.Serialization" #> at the beginning of the tt file. The target framework is .NET framework 4 (no client profile).

Any thought?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top