How to get the PageTypeName property without creating a page instance
In a project we’re currently working on here at Nansen we stumbled upon the need to get the name of a page type without having an actual reference to page of that type.
Since we’re using Joel’s PageTypeBuilder, getting the name was a simple task of reflecting the PageTypeAttributes object.
public static string GetPageTypeName<T>() where T : TypedPageData{System.Reflection.MemberInfo memberInfo = typeof(T);
object[] attributes = memberInfo.GetCustomAttributes(typeof(PageTypeAttribute), false);if (attributes.Count() > 0)
{PageTypeAttribute pta = attributes.First() as PageTypeAttribute;
return pta.Name;
}return string.Empty;}
Comments