<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom"><title type="text">Blog posts by Bartek Tatkowski</title><link href="https://world.optimizely.com/blogs/Bartek-Tatkowski/" /><updated>2010-03-23T11:35:02.5470000Z</updated><id>https://world.optimizely.com/blogs/Bartek-Tatkowski/</id><generator uri="https://world.optimizely.com/blogs/Bartek-Tatkowski/" version="2.0">Optimizely World</generator><entry><title>How to get the PageTypeName property without creating a page instance</title><link href="https://world.optimizely.com/blogs/Bartek-Tatkowski/Dates/2010/3/How-to-get-the-PageTypeName-property-without-creating-a-page-instance/" /><id>https://world.optimizely.com/blogs/Bartek-Tatkowski/Dates/2010/3/How-to-get-the-PageTypeName-property-without-creating-a-page-instance/</id><published>2010-03-23T11:35:02.0000000Z</published><updated>2010-03-23T11:35:02.5470000Z</updated><author><name>bartek.tatkowski@nansen.se</name></author><category term="Blog post" /><summary type="html">&lt;p&gt;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. &lt;/p&gt;  &lt;p&gt;Since we’re using Joel’s PageTypeBuilder, getting the name was a simple task of reflecting the PageTypeAttributes object.&lt;/p&gt;  &lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; GetPageTypeName&amp;lt;T&amp;gt;() where T : TypedPageData
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    System.Reflection.MemberInfo memberInfo = &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(T);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;object&lt;/span&gt;[] attributes =  memberInfo.GetCustomAttributes(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(PageTypeAttribute), &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;); 
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (attributes.Count() &amp;gt; 0)
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        PageTypeAttribute pta = attributes.First() &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; PageTypeAttribute;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; pta.Name;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    } 
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.Empty;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;}
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;/pre&gt;</summary></entry></feed>