<?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="http://world.optimizely.com" /><updated>2010-03-23T11:35:02.0000000Z</updated><id>https://world.optimizely.com/blogs/Bartek-Tatkowski/</id> <generator uri="http://world.optimizely.com" 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>&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=&quot;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&quot;&gt;&lt;pre style=&quot;background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px&quot;&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;string&lt;/span&gt; GetPageTypeName&amp;lt;T&amp;gt;() where T : TypedPageData
&lt;/pre&gt;&lt;pre style=&quot;background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px&quot;&gt;{
&lt;/pre&gt;&lt;pre style=&quot;background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px&quot;&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px&quot;&gt;    System.Reflection.MemberInfo memberInfo = &lt;span style=&quot;color: #0000ff&quot;&gt;typeof&lt;/span&gt;(T);
&lt;/pre&gt;&lt;pre style=&quot;background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px&quot;&gt;    &lt;span style=&quot;color: #0000ff&quot;&gt;object&lt;/span&gt;[] attributes =  memberInfo.GetCustomAttributes(&lt;span style=&quot;color: #0000ff&quot;&gt;typeof&lt;/span&gt;(PageTypeAttribute), &lt;span style=&quot;color: #0000ff&quot;&gt;false&lt;/span&gt;); 
&lt;/pre&gt;&lt;pre style=&quot;background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px&quot;&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px&quot;&gt;    &lt;span style=&quot;color: #0000ff&quot;&gt;if&lt;/span&gt; (attributes.Count() &amp;gt; 0)
&lt;/pre&gt;&lt;pre style=&quot;background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px&quot;&gt;    {
&lt;/pre&gt;&lt;pre style=&quot;background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px&quot;&gt;        PageTypeAttribute pta = attributes.First() &lt;span style=&quot;color: #0000ff&quot;&gt;as&lt;/span&gt; PageTypeAttribute;
&lt;/pre&gt;&lt;pre style=&quot;background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px&quot;&gt;        &lt;span style=&quot;color: #0000ff&quot;&gt;return&lt;/span&gt; pta.Name;
&lt;/pre&gt;&lt;pre style=&quot;background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px&quot;&gt;    } 
&lt;/pre&gt;&lt;pre style=&quot;background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px&quot;&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px&quot;&gt;    &lt;span style=&quot;color: #0000ff&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;string&lt;/span&gt;.Empty;
&lt;/pre&gt;&lt;pre style=&quot;background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px&quot;&gt;}
&lt;/pre&gt;&lt;pre style=&quot;background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px&quot;&gt;&lt;/pre&gt;&lt;/pre&gt;</id><updated>2010-03-23T11:35:02.0000000Z</updated><summary type="html">Blog post</summary></entry></feed>