KnownTypeAttribute in t4 file
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 transformati开发者_如何学Con: 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?
Do you have an <#@ assembly #> directive to bring in System.Runtime.Serialization? In VS2010, project references don't play any part in assembly resolution in T4.
精彩评论