Mar 23, 2010
(0 votes)

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;
Mar 23, 2010


Please login to comment.
Latest blogs
Optimizely PIM - Variant Management Overhaul & Rollout

Optimizely PIM has completely overhauled variant management with improved usability and support for variant swatches. In order to enable this...

Arthur Vander Voort | Feb 4, 2023

You Just Got Vectored! SVG Image Formats

 If you're reading this, then you've come across a need that nearly all Opti developers encounter in their careers; You need to display a vector...

Greg J | Feb 3, 2023 | Syndicated blog

CMS Core 12.12.0 delisted from Nuget feed

We have decided to delist version 12.12.0 of the CMS Core packages from our Nuget feed. As a consequence, we are also temporarily delisting version...

Magnus Rahl | Feb 3, 2023

How Optimizely Web Experimentation enables fast validation of design and UX changes

Ever wondered how to increase conversion rates and quickly validate design/UX alternatives to find the most impactful changes? I wrote a practical...

Jacob Pretorius | Jan 31, 2023