Try our conversational search powered by Generative AI!

bartek.tatkowski@nansen.se
Mar 23, 2010
  2976
(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

Comments

Please login to comment.
Latest blogs
From Procrastination to Proficiency: Navigating Your Journey to Web Experimentation Certification

Hey there, Optimizely enthusiasts!   Join me in celebrating a milestone – I'm officially a certified web experimentation expert! It's an exhilarati...

Silvio Pacitto | May 17, 2024

GPT-4o Now Available for Optimizely via the AI-Assistant plugin!

I am excited to announce that GPT-4o is now available for Optimizely users through the Epicweb AI-Assistant integration. This means you can leverag...

Luc Gosso (MVP) | May 17, 2024 | Syndicated blog

The downside of being too fast

Today when I was tracking down some changes, I came across this commit comment Who wrote this? Me, almost 5 years ago. I did have a chuckle in my...

Quan Mai | May 17, 2024 | Syndicated blog

Optimizely Forms: Safeguarding Your Data

With the rise of cyber threats and privacy concerns, safeguarding sensitive information has become a top priority for businesses across all...

K Khan | May 16, 2024