<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>Reflection for tag code samples</title><link>http://blog.bigfinger.se</link><pubDate>2012-02-07T23:20:56</pubDate><generator>umbraco</generator><description>Thoughts on life: Umbraco, EPiServer, .NET and Fatherhood.</description><language>en</language><copyright>Copyright 2009-2012 Stephan Kvart</copyright><webMaster>stephan@bigfinger.se</webMaster><item><title>Removing the "Create" option from the Context Menu in Umbraco.</title><link>http://blog.bigfinger.se/2010/1/29/removing-the-create-option-from-the-context-menu-in-umbraco.aspx</link><pubDate>Fri, 29 Jan 2010 15:17:31 GMT</pubDate><guid>http://blog.bigfinger.se/2010/1/29/removing-the-create-option-from-the-context-menu-in-umbraco.aspx</guid><description>
Many times I've found myself becoming irritated that the
"Create" option in the Umbraco UI context menu, is there even when
there aren't any allowed child nodes under that node. When I click
it, all I get is an empty dialog. Here's how you get rid of it.



Please, do note, this solution isn't for everyone. There might
be a special case when you'd want that empty dialog. I don't know
when or why, but it might happen. Also, you might ask why I keep
putting code samples in images. It's because...</description><content:encoded><![CDATA[ 
<p>Many times I've found myself becoming irritated that the
"Create" option in the Umbraco UI context menu, is there even when
there aren't any allowed child nodes under that node. When I click
it, all I get is an empty dialog. Here's how you get rid of it.</p>

<p><img src="/media/1418/eventhandlers_context_tree_remove.png" width="560" height="500" alt="Umbraco EventHandler: OnContentTreeBeforeNodeRender"/></p>

<p>Please, do note, this solution isn't for everyone. There might
be a special case when you'd want that empty dialog. I don't know
when or why, but it might happen. Also, you might ask why I keep
putting code samples in images. It's because I want you to actually
read what you are putting into your own source, and not just copy
and paste. Copy and paste isn't a very good practice you know.</p>
]]></content:encoded></item><item><title>Using an UrlRewriter in Umbraco to change the paging style.</title><link>http://blog.bigfinger.se/2010/1/23/using-an-urlrewriter-in-umbraco-to-change-the-paging-style.aspx</link><pubDate>Sat, 23 Jan 2010 09:40:28 GMT</pubDate><guid>http://blog.bigfinger.se/2010/1/23/using-an-urlrewriter-in-umbraco-to-change-the-paging-style.aspx</guid><description>
Paging using XSLT is a very useful, and fairly simple (and well-documented here). It generates very
SEO friendly links between pages, however, it can be used to
generate even better links, with a little tweaking and use of the
UrlRewriting.NET that comes
with Umbraco. The XSLT examples are from the BlogListPosts.xslt in
the Blog4Umbraco package.

Note: I'm using domain prefixes, and if you don't you might have
to alter the syntax in some small way to get it working flawlessly
for you.

1. Ad...</description><content:encoded><![CDATA[ 
<p>Paging using XSLT is a very useful, and fairly simple (and <a
href="http://our.umbraco.org/projects/paging-xslt" target="_blank"
title="Paging XSLT">well-documented here</a>). It generates very
SEO friendly links between pages, however, it can be used to
generate even better links, with a little tweaking and use of the
<a href="http://urlrewriting.net/149/en/home.html" target="_blank"
title="UrlRewritingNet.UrlRewrite">UrlRewriting.NET</a> that comes
with Umbraco. The XSLT examples are from the BlogListPosts.xslt in
the Blog4Umbraco package.</p>

<p>Note: I'm using domain prefixes, and if you don't you might have
to alter the syntax in some small way to get it working flawlessly
for you.</p>

<p>1. Add an entry to the /config/UrlRewriting.config<br />
 <img src="/media/1225/urlrewriting_pagerewrite.png" width="560" height="92" alt="Code Sample - UrlRewriting, Paging"/></p>

<p>2. Modify the XSLT so that it outputs a page reference, instead
of a querystring.<br />
 Was:<br />
 <img src="/media/1230/urlrewriting_paging_querystring.png" width="560" height="103" alt="Code Sample - UrlRewriting, Paging - Link w/ QueryString"/> Change into:<br />
 <img src="/media/1235/urlrewriting_paging_pagelink.png" width="560" height="103" alt="Code Sample - UrlRewriting, Paging - Link w/ Page Reference"/></p>

<p>Note: If you're using directory URLs, you can skip the ".aspx"
ending of the link, and just add a slash.</p>
]]></content:encoded></item><item><title>Making objects behave across a client-server relationship. Part 2 - Setting the parent reference.</title><link>http://blog.bigfinger.se/2010/1/14/making-objects-behave-across-a-client-server-relationship-part-2-setting-the-parent-reference.aspx</link><pubDate>Thu, 14 Jan 2010 08:16:01 GMT</pubDate><guid>http://blog.bigfinger.se/2010/1/14/making-objects-behave-across-a-client-server-relationship-part-2-setting-the-parent-reference.aspx</guid><description>
How to make sure that any objects added to the Children
property, gets a correct reference to the parent object
(this)?

Attempt 1: Adding Add and Insert methods to the
Element

public abstract class Element {
 public Element() {
 this.Children = new List&amp;lt;Element&amp;gt;();
 }
 public int ID { get; protected set; }
 public string Name { get; protected set; }
 public virtual Element Parent { get; internal set; }
 public virtual List&amp;lt;Element&amp;gt; Children { get; private set;
}...</description><content:encoded><![CDATA[ 
<p><strong>How to make sure that any objects added to the Children
property, gets a correct reference to the parent object
(this)?</strong></p>

<p><em>Attempt 1: Adding Add and Insert methods to the
Element</em></p>

<p>public abstract class Element {<br />
 public Element() {<br />
 this.Children = new List&lt;Element&gt;();<br />
 }<br />
 public int ID { get; protected set; }<br />
 public string Name { get; protected set; }<br />
 public virtual Element Parent { get; internal set; }<br />
 public virtual List&lt;Element&gt; Children { get; private set;
}<br />
 public string Instructions { get; set; }<br />
<br />
 public void Add(Element item){<br />
 item.Parent = this;<br />
 this.Children.Add(item);<br />
 }<br />
 ...<br />
 }</p>

<p>This solution works all-right for many cases, however, it
doesn't solve the issue when the Add method is used on the
List&lt;Element&gt; directly. We'll want this.</p>

<p><em>Attempt 2: Changing the List type</em></p>

<p>public abstract class Element {<br />
 public Element() {<br />
 this.Children = new ElementList();<br />
 }<br />
 public int ID { get; protected set; }<br />
 public string Name { get; protected set; }<br />
 public virtual Element Parent { get; internal set; }<br />
 public virtual ElementList Children { get; private set; }<br />
 public string Instructions { get; set; }<br />
 }</p>

<p>public class ElementList : List&lt;Element&gt; {<br />
 public Element Element { get; internal set; }<br />
 public ElementList(Element element) {<br />
 if (element != null){ this.Element = element; }<br />
 else { throw new ArgumentNullException("element"); }<br />
 }<br />
 new public void Add(Element item) {<br />
 if ( item.Parent == null) { item.Parent = Element; }<br />
 base.Add(item);<br />
 }<br />
 new public void Insert(int index, Element item) {<br />
 if (item.Parent == null) { item.Parent = Element; }<br />
 base.Insert(index, item);<br />
 }<br />
 new public void InsertRange(int index, IEnumerable&lt;Element&gt;
collection){<br />
 foreach (Element e in collection){<br />
 if (e.Parent == null) { e.Parent = Element; }<br />
 }<br />
 base.InsertRange(index, collection);<br />
 }<br />
 new public void AddRange(IEnumerable&lt;Element&gt; collection)
{<br />
 foreach (Element e in collection) {<br />
 if (e.Parent == null) { e.Parent = Element; }<br />
 }<br />
 base.AddRange(collection);<br />
 }<br />
 }</p>

<p>This solution ensures that all Elements added to an ElementList,
gets their Parent property re-set to reference the ElementLists
Element property. This way, one can always assume that an Element's
Children, always have their Parent references set.</p>

<p>Next up: Serialization.</p>
]]></content:encoded></item><item><title>Making objects behave across a client-server relationship. Part 1 - The scenario.</title><link>http://blog.bigfinger.se/2010/1/13/making-objects-behave-across-a-client-server-relationship-part-1-the-scenario.aspx</link><pubDate>Wed, 13 Jan 2010 22:47:19 GMT</pubDate><guid>http://blog.bigfinger.se/2010/1/13/making-objects-behave-across-a-client-server-relationship-part-1-the-scenario.aspx</guid><description>
Ok, so here's the scenario. I have a set of objects, which all
inherit from Element (shown below). I need these objects to behave
properly when transferred across a web service, and more
importantly, when they return. One assumption I want to be able to
make, is that any Element contained in the Children property,
should have its Parent property set to the containing object, so
it's a node-like structure. Furthermore, I need my non-default
constructor logic to apply, to de-serialized...</description><content:encoded><![CDATA[ 
<p>Ok, so here's the scenario. I have a set of objects, which all
inherit from Element (shown below). I need these objects to behave
properly when transferred across a web service, and more
importantly, when they return. One assumption I want to be able to
make, is that any Element contained in the Children property,
should have its Parent property set to the containing object, so
it's a node-like structure. Furthermore, I need my non-default
constructor logic to apply, to de-serialized objects, as if they
were initialized with my parameterized constructor.</p>

<p>public abstract class Element {<br />
 public Element() {<br />
 this.Children = new List&lt;Element&gt;();<br />
 }<br />
 public int ID { get; protected set; }<br />
 public string Name { get; protected set; }<br />
 public virtual Element Parent { get; internal set; }<br />
 public virtual List&lt;Element&gt; Children { get; private set;
}<br />
 public string Instructions { get; set; }<br />
 }</p>

<p><strong>The problems:</strong></p>

<p>How to make sure that any objects added to the Children
property, gets a correct reference to the parent object (this)?</p>

<p>How to make sure that my object can be serialized in an orderly
fashion?</p>

<p>How to enforce that initialization is done properly once the
object has been de-serialized?</p>

<p>&nbsp;</p>
]]></content:encoded></item></channel></rss>

