<?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/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>welt-held.de &#187; Programmierung</title>
	<atom:link href="http://www.welt-held.de/category/programmierung/feed" rel="self" type="application/rss+xml" />
	<link>http://www.welt-held.de</link>
	<description>Sind wir nicht alle Welt Held?</description>
	<lastBuildDate>Wed, 23 Nov 2011 09:14:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>TFS Alerts</title>
		<link>http://www.welt-held.de/2012-tfs-alerts.html</link>
		<comments>http://www.welt-held.de/2012-tfs-alerts.html#comments</comments>
		<pubDate>Wed, 23 Nov 2011 09:14:36 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[Programmierung]]></category>
		<category><![CDATA[alert]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[source control]]></category>
		<category><![CDATA[tfs]]></category>
		<category><![CDATA[visual studio 201]]></category>

		<guid isPermaLink="false">http://www.welt-held.de/?p=2012</guid>
		<description><![CDATA[Der Team Foundation Server bringt ein sehr nettes Feature mit, er informiert mich über bestimmte Änderungen per Email.
Finden tut ihr den &#8220;Alert Explorer&#8221; in Visual Studio 2010 unter &#8220;Team&#8221; - &#8220;Alert Explorer&#8221;. 

 Ich habe hier ein Alert auf meine Work Items und Tasks sowie wenn jemand bestimmte  [...]]]></description>
			<content:encoded><![CDATA[<p>Der Team Foundation Server bringt ein sehr nettes Feature mit, er informiert mich über bestimmte Änderungen per Email.<br />
Finden tut ihr den &#8220;Alert Explorer&#8221; in Visual Studio 2010 unter &#8220;Team&#8221; -> &#8220;Alert Explorer&#8221;. </p>
<p><a href="http://welt-held.de/files/AlertExplorer.jpg"><img src="http://welt-held.de/files/AlertExplorer.jpg" alt="Alert Explorer Visual Studio 2010" title="Alert Explorer" width="665" height="201" class="aligncenter size-full wp-image-2013" /></a></p>
<p><a href="http://welt-held.de/files/NewAlert.jpg"><img src="http://welt-held.de/files/NewAlert-150x150.jpg" alt="Alert hinzufügen in Visual Studio 2010" title="New Alert" width="150" height="150" class="alignright size-thumbnail wp-image-2014" /></a> Ich habe hier ein Alert auf meine Work Items und Tasks sowie wenn jemand bestimmte Dateien eincheckt. Möglich sind aber auch noch Meldungen über Builds.<br />
Mit einem Klick auf &#8220;New Alert&#8221; findet ihr Vorlagen für die verschiedenen Alert-Arten sowie einige vordefinierten Templates.<br />
Wenn ihr eine Vorlage auswählt, seid ihr automatisch als Empfänger vorbelegt. Ihr könnt allerdings auch mehrere Benutzer informieren lassen. Der Name dient ledeglich zur Organisation im Alert Explorer, den Betreff oder den Inhalt der Emails kann man leider nicht weiter beeinflussen. Dies wäre durchaus praktisch um in Outlook spezielle Regeln greifen zu lassen.<br />
Unterhalt der &#8220;Alert Definition&#8221; werden die gewünschten Filterkreterien angegeben, hier mal ein Beispiel um mich über alle Änderungen an meinen Workpackages / Tasks / Bugs / etc. informieren zu lassen, die nicht ich gemacht habe.</p>
<p><a href="http://welt-held.de/files/WorkItemChanged.jpg"><img src="http://welt-held.de/files/WorkItemChanged-150x150.jpg" alt="" title="Work Item Changed" width="150" height="150" class="aligncenter size-thumbnail wp-image-2018" /></a></p>
<p>Wer über Änderungen an Dateien informiert werden will, hat über den Source Control Explorer zusätzlich die Möglichkeit mit einem Rechtsklick auf die gewünschte Datei oder Ordner einen Alert zu erstellen. Hier bei wird nur eine Datei in die Alert Definition hinzugefügt. Markiert man mehrere Dateien im SCE, so bleibt der Punkt disabled. Allerdings kann man die Defintition logisch mit OR verknüpfen und so mehrer Dateien mit einer Defintition traken.<br />
<a href="http://welt-held.de/files/AlertInSourceControl.jpg"><img src="http://welt-held.de/files/AlertInSourceControl-150x150.jpg" alt="" title="Alert In Source Control Explorer" width="150" height="150" class="aligncenter size-thumbnail wp-image-2019" /></a></p>
<p>Meiner Meinung nach ein großartiges Feature. Nicht selten kommt es vor, dass Workpackages angelegt oder geändert werden, ich dies aber erst spät mitbekomme. Oder aber ich kann verfolgen, ob die Kollegen in den getrakten Dateien auch nur die Zeilen ändern, die sie ändern dürfen <img src='http://welt-held.de/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.welt-held.de%2F2012-tfs-alerts.html&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://www.welt-held.de/2012-tfs-alerts.html"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.welt-held.de/2012-tfs-alerts.html"  data-text="TFS Alerts" data-count="horizontal" data-via="trashar">Tweet</a>
			</div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div> <p><a href="http://welt-held.de/?flattrss_redirect&amp;id=2012&amp;md5=6d55c74ee6fce7ba0e472172a2033ca6" title="Flattr" target="_blank"><img src="http://welt-held.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.welt-held.de/2012-tfs-alerts.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="http://welt-held.de/?flattrss_redirect&amp;id=2012&amp;md5=6d55c74ee6fce7ba0e472172a2033ca6" type="text/html" />
	</item>
		<item>
		<title>StringWriter mit anderem Encoding</title>
		<link>http://www.welt-held.de/2008-stringwriter-mit-anderem-encoding.html</link>
		<comments>http://www.welt-held.de/2008-stringwriter-mit-anderem-encoding.html#comments</comments>
		<pubDate>Thu, 03 Nov 2011 05:43:53 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[serialize]]></category>
		<category><![CDATA[stringwriter]]></category>
		<category><![CDATA[utf16]]></category>
		<category><![CDATA[utf8]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.welt-held.de/?p=2008</guid>
		<description><![CDATA[Vor einer ganzen Weile habe ich mal die StringWriter-Klasse empfohlen.
Die StringWriter-Klasse nutzt intern UTF-16, wodurch zum Beispiel bei der Xml-Serialisierung von Klassen auch das Ergebnis in UTF-16 vorliegt. Dies ist nicht zwangsläufig gewünscht, bei mir hat dadurch ein Backend-Service  [...]]]></description>
			<content:encoded><![CDATA[<p>Vor einer ganzen Weile habe ich mal die <a href="http://www.welt-held.de/1964-tipp-stringreader-und-stringwriter.html">StringWriter</a>-Klasse empfohlen.<br />
Die StringWriter-Klasse nutzt intern UTF-16, wodurch zum Beispiel bei der Xml-Serialisierung von Klassen auch das Ergebnis in UTF-16 vorliegt. Dies ist nicht zwangsläufig gewünscht, bei mir hat dadurch ein Backend-Service gestreikt.<br />
Um trotzdem den StringWriter weiter zu verwenden, muss man sich eine eigene Klasse schreiben, welche von der StringWriter ableitet und das Encoding-Property überschreibt:</p>
<pre class="brush: csharp; title: ; notranslate">using System;
using System.IO;
using System.Text;

namespace Utilities.IO
{

	/// &lt;summary&gt;
	/// 	A simple class derived from StringWriter, but which allows
	/// 	the user to select which Encoding is used. This is most
	/// 	likely to be used with XmlTextWriter, which uses the Encoding
	/// 	property to determine which encoding to specify in the XML.
	/// &lt;/summary&gt;
	public class StringWriterWithEncoding : StringWriter
	{
		private Encoding _encoding;

		/// &lt;summary&gt;
		/// 	Initializes a new instance of the StringWriterWithEncoding class
		/// 	with the specified encoding.
		/// &lt;/summary&gt;
		/// &lt;param name = &quot;encoding&quot;&gt;The encoding to report.&lt;/param&gt;
		public StringWriterWithEncoding(Encoding encoding)
			: base()
		{
			this._encoding = encoding;
		}

		/// &lt;summary&gt;
		/// 	Initializes a new instance of the StringWriter class with the
		/// 	specified format control and encoding.
		/// &lt;/summary&gt;
		/// &lt;param name = &quot;encoding&quot;&gt;The encoding to report.&lt;/param&gt;
		/// &lt;param name = &quot;formatProvider&quot;&gt;An IFormatProvider object that controls formatting.&lt;/param&gt;
		public StringWriterWithEncoding(Encoding encoding, IFormatProvider formatProvider)
			: base(formatProvider)
		{
			this._encoding = encoding;
		}

		/// &lt;summary&gt;
		/// 	Initializes a new instance of the StringWriter class that writes to the
		/// 	specified StringBuilder, and reports the specified encoding.
		/// &lt;/summary&gt;
		/// &lt;param name = &quot;encoding&quot;&gt;The encoding to report.&lt;/param&gt;
		/// &lt;param name = &quot;sb&quot;&gt;The StringBuilder to write to. &lt;/param&gt;
		public StringWriterWithEncoding(Encoding encoding, StringBuilder sb)
			: base(sb)
		{
			this._encoding = encoding;
		}

		/// &lt;summary&gt;
		/// 	Initializes a new instance of the StringWriter class that writes to the specified
		/// 	StringBuilder, has the specified format provider, and reports the specified encoding.
		/// &lt;/summary&gt;
		/// &lt;param name = &quot;encoding&quot;&gt;The encoding to report.&lt;/param&gt;
		/// &lt;param name = &quot;sb&quot;&gt;The StringBuilder to write to. &lt;/param&gt;
		/// &lt;param name = &quot;formatProvider&quot;&gt;An IFormatProvider object that controls formatting.&lt;/param&gt;
		public StringWriterWithEncoding(Encoding encoding, StringBuilder sb, IFormatProvider formatProvider)
			: base(sb, formatProvider)
		{
			this._encoding = encoding;
		}

		/// &lt;summary&gt;
		/// 	Gets the Encoding in which the output is written.
		/// &lt;/summary&gt;
		public override Encoding Encoding
		{
			get { return this._encoding; }
		}
	}
}
</pre>
<p><strong>Update:</strong><br />
Habe die Klasse mal um Kommentare erweitert.</p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.welt-held.de%2F2008-stringwriter-mit-anderem-encoding.html&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://www.welt-held.de/2008-stringwriter-mit-anderem-encoding.html"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.welt-held.de/2008-stringwriter-mit-anderem-encoding.html"  data-text="StringWriter mit anderem Encoding" data-count="horizontal" data-via="trashar">Tweet</a>
			</div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div> <p><a href="http://welt-held.de/?flattrss_redirect&amp;id=2008&amp;md5=67cf5eb483bf133c953176986f619a70" title="Flattr" target="_blank"><img src="http://welt-held.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.welt-held.de/2008-stringwriter-mit-anderem-encoding.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="http://welt-held.de/?flattrss_redirect&amp;id=2008&amp;md5=67cf5eb483bf133c953176986f619a70" type="text/html" />
	</item>
		<item>
		<title>XML serialisierbares Dictionary</title>
		<link>http://www.welt-held.de/2002-xml-serialisierbares-dictionary-tkey-tvalue.html</link>
		<comments>http://www.welt-held.de/2002-xml-serialisierbares-dictionary-tkey-tvalue.html#comments</comments>
		<pubDate>Mon, 17 Oct 2011 14:24:08 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Programmierung]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[dictionary]]></category>
		<category><![CDATA[generic]]></category>
		<category><![CDATA[serialize]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.welt-held.de/?p=2002</guid>
		<description><![CDATA[Ich verstehe zwar nicht, warum es standardmäßig nicht im .NET Framework implementiert ist, allerdings ist es ohne Hilfsmittel nicht möglich, eine Klasse mit einem Dictionary mittels XmlSerializer zu serialisieren! Mit folgender Hilfsklasse funktioniert es dahin anstandslos, vorausgesetzt sowohl  [...]]]></description>
			<content:encoded><![CDATA[<p>Ich verstehe zwar nicht, warum es standardmäßig nicht im .NET Framework implementiert ist, allerdings ist es ohne Hilfsmittel nicht möglich, eine Klasse mit einem Dictionary<tkey ,TValue> mittels <a href="http://msdn.microsoft.com/de-de/library/system.xml.serialization.xmlserializer(v=vs.80).aspx">XmlSerializer</a> zu serialisieren! Mit folgender Hilfsklasse funktioniert es dahin anstandslos, vorausgesetzt sowohl TKey und TValue sind Xml-serialisierbar.</p>
<pre class="brush: csharp; title: ; notranslate">
using System.Collections.Generic;
using System.Xml.Serialization;

namespace Utilities.Generic
{
	[XmlRoot(&quot;dictionary&quot;)]
	public class SerializableDictionary&lt;TKey, TValue&gt; : Dictionary&lt;TKey, TValue&gt;, IXmlSerializable
	{
		#region Constructors

		public SerializableDictionary():base() {}

		public SerializableDictionary(IDictionary&lt;TKey, TValue&gt; dictionary) : base(dictionary) { }

		public SerializableDictionary(IDictionary&lt;TKey, TValue&gt; dictionary, IEqualityComparer&lt;TKey&gt; comparer) : base(dictionary, comparer) {}

		public SerializableDictionary(int capacity, IEqualityComparer&lt;TKey&gt; comparer) : base(capacity, comparer) { }

		public SerializableDictionary(IEqualityComparer&lt;TKey&gt; comparer) : base(comparer) { }

		public SerializableDictionary(int capacity) : base(capacity) { }

		#endregion

		private const string ItemTagName = &quot;item&quot;;
		private const string KeyTagName = &quot;key&quot;;
		private const string ValueTagName = &quot;value&quot;;

		/// &lt;summary&gt;
		/// Diese Methode ist reserviert und sollte nicht verwendet werden. Wenn Sie die IXmlSerializable-Schnittstelle implementieren, sollten Sie null (Nothing in Visual Basic) von der Methode zurückgeben und stattdessen das &lt;see cref=&quot;T:System.Xml.Serialization.XmlSchemaProviderAttribute&quot;/&gt; auf die Klasse anwenden, wenn ein benutzerdefiniertes Schema erforderlich ist.
		/// &lt;/summary&gt;
		/// &lt;returns&gt;
		/// Ein &lt;see cref=&quot;T:System.Xml.Schema.XmlSchema&quot;/&gt; zur Beschreibung der XML-Darstellung des Objekts, das von der &lt;see cref=&quot;M:System.Xml.Serialization.IXmlSerializable.WriteXml(System.Xml.XmlWriter)&quot;/&gt;-Methode erstellt und von der &lt;see cref=&quot;M:System.Xml.Serialization.IXmlSerializable.ReadXml(System.Xml.XmlReader)&quot;/&gt;-Methode verwendet wird.
		/// &lt;/returns&gt;
		public System.Xml.Schema.XmlSchema GetSchema()
		{
			return null;
		}

		/// &lt;summary&gt;
		/// Generiert ein Objekt aus seiner XML-Darstellung.
		/// &lt;/summary&gt;
		/// &lt;param name=&quot;reader&quot;&gt;Der &lt;see cref=&quot;T:System.Xml.XmlReader&quot;/&gt;-Stream, aus dem das Objekt deserialisiert wird.&lt;/param&gt;
		public void ReadXml(System.Xml.XmlReader reader)
		{
			XmlSerializer keySerializer = new XmlSerializer(typeof(TKey));
			XmlSerializer valueSerializer = new XmlSerializer(typeof(TValue));

			bool wasEmpty = reader.IsEmptyElement;
			reader.Read();

			if (wasEmpty)
			{
				return;
			}

			while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
			{
				reader.ReadStartElement(ItemTagName);

				reader.ReadStartElement(KeyTagName);
				TKey key = (TKey)keySerializer.Deserialize(reader);
				reader.ReadEndElement();

				reader.ReadStartElement(ValueTagName);
				TValue value = (TValue)valueSerializer.Deserialize(reader);
				reader.ReadEndElement();

				this.Add(key, value);

				reader.ReadEndElement();
				reader.MoveToContent();
			}
			reader.ReadEndElement();
		}

		/// &lt;summary&gt;
		/// Konvertiert ein Objekt in seine XML-Darstellung.
		/// &lt;/summary&gt;
		/// &lt;param name=&quot;writer&quot;&gt;Der &lt;see cref=&quot;T:System.Xml.XmlWriter&quot;/&gt;-Stream, in den das Objekt serialisiert wird.&lt;/param&gt;
		public void WriteXml(System.Xml.XmlWriter writer)
		{
			XmlSerializer keySerializer = new XmlSerializer(typeof(TKey));
			XmlSerializer valueSerializer = new XmlSerializer(typeof(TValue));

			foreach (TKey key in this.Keys)
			{
				writer.WriteStartElement(ItemTagName);

				writer.WriteStartElement(KeyTagName);
				keySerializer.Serialize(writer, key);
				writer.WriteEndElement();

				writer.WriteStartElement(ValueTagName);
				TValue value = this[key];
				valueSerializer.Serialize(writer, value);
				writer.WriteEndElement();

				writer.WriteEndElement();
			}
		}
	}
}</pre>
<p>Den ursprünglichen Code habe ich <a href="http://weblogs.asp.net/pwelter34/archive/2006/05/03/444961.aspx">hier</a> her.</tkey></p>
<p><strong>Update:</strong><br />
Habe die Klasse mal um die Standardkonstruktoren der Basis-Klasse erweitert um ein bestehendes Dictionary einfach umwandeln zu können.</p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.welt-held.de%2F2002-xml-serialisierbares-dictionary-tkey-tvalue.html&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://www.welt-held.de/2002-xml-serialisierbares-dictionary-tkey-tvalue.html"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.welt-held.de/2002-xml-serialisierbares-dictionary-tkey-tvalue.html"  data-text="XML serialisierbares Dictionary<TKey,TValue>" data-count="horizontal" data-via="trashar">Tweet</a>
			</div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div> <p><a href="http://welt-held.de/?flattrss_redirect&amp;id=2002&amp;md5=a29081684b9356ba8ec932604d93c0c8" title="Flattr" target="_blank"><img src="http://welt-held.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.welt-held.de/2002-xml-serialisierbares-dictionary-tkey-tvalue.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="http://welt-held.de/?flattrss_redirect&amp;id=2002&amp;md5=a29081684b9356ba8ec932604d93c0c8" type="text/html" />
	</item>
		<item>
		<title>Verschiedene ContextMenues bei einem NotifyIcon</title>
		<link>http://www.welt-held.de/1996-verschiedene-contextmenues-bei-einem-notifyicon.html</link>
		<comments>http://www.welt-held.de/1996-verschiedene-contextmenues-bei-einem-notifyicon.html#comments</comments>
		<pubDate>Mon, 25 Jul 2011 20:31:14 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[contextmenu]]></category>
		<category><![CDATA[notifyicon]]></category>
		<category><![CDATA[source]]></category>

		<guid isPermaLink="false">http://www.welt-held.de/?p=1996</guid>
		<description><![CDATA[In einer kleinen Applikation mit NotifyIcon in der Taskbar wollte ich unterschiedliche ContextMenues öffnen, je nachdem, ob man mit der linken oder rechten Maustaste auf das Icon klickt.
Die erste Hürde, welche es zu nehmen gilt, ist es, dass ContextMenü auch bei einem Links-Klick zu öffnen. Man  [...]]]></description>
			<content:encoded><![CDATA[<p>In einer kleinen Applikation mit NotifyIcon in der Taskbar wollte ich unterschiedliche ContextMenues öffnen, je nachdem, ob man mit der linken oder rechten Maustaste auf das Icon klickt.</p>
<p>Die erste Hürde, welche es zu nehmen gilt, ist es, dass ContextMenü auch bei einem Links-Klick zu öffnen. Man kann zwar eine entsprechende Methode nutzen, jedoch gibt es damit <a href="http://stackoverflow.com/questions/2208690/invoke-notifyicons-context-menu/2208910#2208910">Probleme</a>. Daher sollte man hier Reflection nutzen:</p>
<pre class="brush: csharp; title: ; notranslate">
// constructor..
this._trayIcon.MouseDown += this.TrayIconMouseDown;

private void TrayIconMouseDown(object sender, MouseEventArgs e)
{
	if (e.Button == MouseButtons.Left)
	{
		MethodInfo mi = typeof (NotifyIcon).GetMethod(&quot;ShowContextMenu&quot;, BindingFlags.Instance | BindingFlags.NonPublic);
		mi.Invoke(this._trayIcon, null);
	}
}
</pre>
<p>Nun öffnet sich schon mal das Kontextmenü auch beim Linksklick. Und hier kann man ansetzen, um das Menü entweder zu manipulieren oder zu ersetzen. Ich selbst habe mir einfach zwei Objekte vorbereitet, welche ich je nach Mausklick austausche:</p>
<pre class="brush: csharp; title: ; notranslate">
private void TrayIconMouseDown(object sender, MouseEventArgs e)
{
	if (e.Button == MouseButtons.Left)
	{
		this._trayIcon.ContextMenu = this._leftClickMenu;
		MethodInfo mi = typeof (NotifyIcon).GetMethod(&quot;ShowContextMenu&quot;, BindingFlags.Instance | BindingFlags.NonPublic);
		mi.Invoke(this._trayIcon, null);
	}
	else if (e.Button == MouseButtons.Right)
	{
		this._trayIcon.ContextMenu = this._rightClickMenu;
		MethodInfo mi = typeof(NotifyIcon).GetMethod(&quot;ShowContextMenu&quot;, BindingFlags.Instance | BindingFlags.NonPublic);
		mi.Invoke(this._trayIcon, null);
	}
}
</pre>
<p>Beim Testen ist mir aufgefallen, dass es mehrere Events gibt, an die man sich hängen könnte, etwa &#8220;MouseUp&#8221;, &#8220;MouseClick&#8221; usw. Beim Testen hat bei mir allerdings nur &#8220;MouseDown&#8221; korrekt funktioniert, bei den anderen hatte ich das Problem, dass zum Teil das Menü erst angezeigt wurde und dann der Eventhandler durchlaufen wurde (ich glaube sogar immer, wenn ich mit der linken Maustaste geklickt habe). Erklären konnte ich es mir allerdings nicht.</p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.welt-held.de%2F1996-verschiedene-contextmenues-bei-einem-notifyicon.html&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://www.welt-held.de/1996-verschiedene-contextmenues-bei-einem-notifyicon.html"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.welt-held.de/1996-verschiedene-contextmenues-bei-einem-notifyicon.html"  data-text="Verschiedene ContextMenues bei einem NotifyIcon" data-count="horizontal" data-via="trashar">Tweet</a>
			</div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div> <p><a href="http://welt-held.de/?flattrss_redirect&amp;id=1996&amp;md5=13599e4f664332ff77c98333f55ca252" title="Flattr" target="_blank"><img src="http://welt-held.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.welt-held.de/1996-verschiedene-contextmenues-bei-einem-notifyicon.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="http://welt-held.de/?flattrss_redirect&amp;id=1996&amp;md5=13599e4f664332ff77c98333f55ca252" type="text/html" />
	</item>
		<item>
		<title>Signieren einer XML-Datei in C#</title>
		<link>http://www.welt-held.de/1983-signieren-einer-xml-datei-in-c.html</link>
		<comments>http://www.welt-held.de/1983-signieren-einer-xml-datei-in-c.html#comments</comments>
		<pubDate>Mon, 20 Jun 2011 18:03:54 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[asymmetrische verschlüsselung]]></category>
		<category><![CDATA[rsa]]></category>
		<category><![CDATA[signatur]]></category>
		<category><![CDATA[signieren]]></category>
		<category><![CDATA[xml signatur]]></category>

		<guid isPermaLink="false">http://www.welt-held.de/?p=1983</guid>
		<description><![CDATA[Vielleicht haben sich schon einige von euch mit Lizenzen beschäftigt. Man erstellt eine Software, verkauft sie und möchte natürlich nicht, dass sie einfach von anderen kostenlos genutzt wird. Ich möchte daher heute eine Möglichkeit vorstellen. Sie ist recht simpel aber dennoch sehr flexibel  [...]]]></description>
			<content:encoded><![CDATA[<p>Vielleicht haben sich schon einige von euch mit Lizenzen beschäftigt. Man erstellt eine Software, verkauft sie und möchte natürlich nicht, dass sie einfach von anderen kostenlos genutzt wird. Ich möchte daher heute eine Möglichkeit vorstellen. Sie ist recht simpel aber dennoch sehr flexibel gestaltet.</p>
<p>Um meinen Ansatz zu verstehen, muss man wissen, was eine <a href="http://de.wikipedia.org/wiki/Asymmetrisches_Kryptosystem">asymmetrische Verschlüsselung</a> funktioniert. Während bei einer symmetrischen Verschlüsselung mit einem Passwort sowohl ver- als auch entschlüsselt wird, gibt es bei der asymmetrischen Verschlüsselung zwei Schlüssel. Den Private und den Public Key. Während der Private und der Public Key verschlüsseln können, ist nur der Private Key in der Lage wieder zu entschlüsseln. Will man hingegen wissen, ob eine Nachricht wirklich vom Besitzer des Private Keys kommt, spricht man von Signierung. Signieren kann nur der Besitzer des Privaten Schlüssels, während jeder Public Key Besitzer dies verifizieren kann.</p>
<p>Dieses Verhalten kann man ausnutzen, der Hersteller der Software ist im Besitz des Private Keys und signiert Dateien, welche von der Software, welche den Public Key kennt, verifiziert. Sollte die Signatur nicht gültig sein, verweigert die Software ihren Dienst. Sollte jemand den Inhalt der Datei manipulieren, so muss sie wieder mit dem Private Key neu signiert werden.</p>
<p>Ich habe mir daher eine kleine, aber feine Klasse erstellt, welche entweder ein XML-Dokument oder eine Klasse, welche per XmlSerializer serialisierbar ist, signieren kann. So kann man theoretisch jede Information in eine XML-Lizenz-Datei hinterlegen, etwa wie lange die Lizenz gültig ist. Die nötigen Klassen befinden sich alle im .NET-Framework ab Version 2.0. Der Code ist zum Teil aus der MSDN (siehe Links am Ende des Beitrages).</p>
<p>Diese Möglichkeit bietet keinen absoluten Schutz. Leute könnten mit Programmen wie <a href="http://www.jetbrains.com/decompiler/">dotPeek</a> an den SourceCode gelangen und die Prüfung ausbauen. Mit einem <a href="http://de.wikipedia.org/wiki/Obfuscator">Obfuscator</a> kann dies erschwert werden. Zudem dürft ihr niemals den privaten Schlüssel herausgeben, da dieser sowohl signieren als auch einen Public Key erstellen kann.</p>
<h3>Beispielapplikation:</h3>
<p><a href='http://welt-held.de/files/XmlSign.zip'>Hier</a> findet ihr eine kleine Beispielanwendung. Die Form ist sehr trivial, erstellt erst die Keys, dann die Dummy-Klasse, signieren und zum Schluss validieren.</p>
<h4>Links:</h4>
<p><a href="http://msdn.microsoft.com/en-us/library/ms229745%28v=VS.85%29.aspx">How to: Sign XML Documents with Digital Signatures </a><br />
<a href="http://msdn.microsoft.com/en-us/library/ms229950(v=VS.85).aspx">How to: Verify the Digital Signatures of XML Documents </a><br />
<a href='http://welt-held.de/files/XmlSign.zip'>Beispielanwendung</a></p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.welt-held.de%2F1983-signieren-einer-xml-datei-in-c.html&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://www.welt-held.de/1983-signieren-einer-xml-datei-in-c.html"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.welt-held.de/1983-signieren-einer-xml-datei-in-c.html"  data-text="Signieren einer XML-Datei in C#" data-count="horizontal" data-via="trashar">Tweet</a>
			</div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div> <p><a href="http://welt-held.de/?flattrss_redirect&amp;id=1983&amp;md5=f5b9245bc323013a844eb016241d056b" title="Flattr" target="_blank"><img src="http://welt-held.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.welt-held.de/1983-signieren-einer-xml-datei-in-c.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="http://welt-held.de/?flattrss_redirect&amp;id=1983&amp;md5=f5b9245bc323013a844eb016241d056b" type="text/html" />
	</item>
		<item>
		<title>Tipp: StringReader und StringWriter</title>
		<link>http://www.welt-held.de/1964-tipp-stringreader-und-stringwriter.html</link>
		<comments>http://www.welt-held.de/1964-tipp-stringreader-und-stringwriter.html#comments</comments>
		<pubDate>Wed, 23 Mar 2011 21:05:09 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[.net 3.5]]></category>
		<category><![CDATA[.net 4]]></category>
		<category><![CDATA[stringreader]]></category>
		<category><![CDATA[stringwriter]]></category>
		<category><![CDATA[tipp]]></category>

		<guid isPermaLink="false">http://www.welt-held.de/?p=1964</guid>
		<description><![CDATA[Ein kleiner Tipp für die Leute, die .NET Version 3.5 oder höher einsetzen:
Wer Text an Methoden / Klassen weitergeben will, die mit Streams arbeiten, sollte dies nicht umständlich über den MemoryStream lösen, sondern sich lieber mal die beiden Klassen StringReader und StringWriter anschauen. Geht  [...]]]></description>
			<content:encoded><![CDATA[<p>Ein kleiner Tipp für die Leute, die .NET Version 3.5 oder höher einsetzen:</p>
<p>Wer Text an Methoden / Klassen weitergeben will, die mit Streams arbeiten, sollte dies nicht umständlich über den <a href="http://msdn.microsoft.com/de-de/library/system.io.memorystream(v=vs.80).aspx">MemoryStream</a> lösen, sondern sich lieber mal die beiden Klassen <a href="http://msdn.microsoft.com/en-us/library/system.io.stringreader.aspx">StringReader</a> und <a href="http://msdn.microsoft.com/en-us/library/system.io.stringwriter.aspx">StringWriter</a> anschauen. Geht deutlich einfacher und man braucht nicht umständlich mit irgendwelchen Encodings / Bytes / Stream-Positionen rumspielen.</p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.welt-held.de%2F1964-tipp-stringreader-und-stringwriter.html&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://www.welt-held.de/1964-tipp-stringreader-und-stringwriter.html"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.welt-held.de/1964-tipp-stringreader-und-stringwriter.html"  data-text="Tipp: StringReader und StringWriter" data-count="horizontal" data-via="trashar">Tweet</a>
			</div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div> <p><a href="http://welt-held.de/?flattrss_redirect&amp;id=1964&amp;md5=d8ac50cc28ac33490d759ceb2addf30a" title="Flattr" target="_blank"><img src="http://welt-held.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.welt-held.de/1964-tipp-stringreader-und-stringwriter.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<atom:link rel="payment" href="http://welt-held.de/?flattrss_redirect&amp;id=1964&amp;md5=d8ac50cc28ac33490d759ceb2addf30a" type="text/html" />
	</item>
		<item>
		<title>XSLT Transformation in C#</title>
		<link>http://www.welt-held.de/1960-xslt-transformation-in-c.html</link>
		<comments>http://www.welt-held.de/1960-xslt-transformation-in-c.html#comments</comments>
		<pubDate>Wed, 23 Mar 2011 20:58:24 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[short end tag]]></category>
		<category><![CDATA[transform]]></category>
		<category><![CDATA[xslcompiledtransform]]></category>
		<category><![CDATA[xslt]]></category>

		<guid isPermaLink="false">http://www.welt-held.de/?p=1960</guid>
		<description><![CDATA[Ich hatte ein recht umfangreiches Xml-Schema. Dieses wird ständig mal erweitert und eine andere Applikation benötigt nur einen Teil dieses Schemas. Dazu wurde es immer von Hand für die andere Applikation geändert. Um mir das Leben einfacher zu machen, wollte ich dies über eine XSLT-Transformation  [...]]]></description>
			<content:encoded><![CDATA[<p>Ich hatte ein recht umfangreiches Xml-Schema. Dieses wird ständig mal erweitert und eine andere Applikation benötigt nur einen Teil dieses Schemas. Dazu wurde es immer von Hand für die andere Applikation geändert. Um mir das Leben einfacher zu machen, wollte ich dies über eine XSLT-Transformation lösen, schließlich ist ein Schema auch nur eine XML-Datei. Ein großer Teil wurde einfach nur kopiert, dennoch sah die Ausgabe anders aus als die Eingabe. Mein Kopiertemplate sah folgendermaßen aus:</p>
<pre class="brush: xml; title: ; notranslate">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;
    xmlns:msxsl=&quot;urn:schemas-microsoft-com:xslt&quot; exclude-result-prefixes=&quot;msxsl&quot;
&gt;
    &lt;xsl:output method=&quot;xml&quot; indent=&quot;yes&quot;/&gt;
    &lt;xsl:template match=&quot;@* | node()&quot;&gt;
        &lt;xsl:copy&gt;
            &lt;xsl:apply-templates select=&quot;@* | node()&quot;/&gt;
        &lt;/xsl:copy&gt;
    &lt;/xsl:template&gt;
&lt;/xsl:stylesheet&gt;
</pre>
<p>Einfach alle Nodes und Attribute kopieren, also nichts wildes. Dennoch wurde aus:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;xs:element name=&quot;comment&quot; type=&quot;xs:string&quot; minOccurs=&quot;0&quot; /&gt;
</pre>
<p>folgendes:</p>
<pre class="brush: xml; title: ; notranslate">&lt;xs:element name=&quot;comment&quot; type=&quot;xs:string&quot; minOccurs=&quot;0&quot;&gt;&lt;/xs:element&gt;</pre>
<p>Das Schema ist noch valide und funktioniert tadellos, nur sieht es nicht wirklich schön aus. Nachdem ich im Netz nach einen bestimmten Parameter im C#-Code und ähnliches gesucht hatte, wurde ich doch noch fündig. Das .NET-Framework bietet zwei verschiedene Methoden zur Transformation.<br />
<a href="http://msdn.microsoft.com/de-de/library/system.xml.xsl.xsltransform.aspx">XslTransform</a> und <a href="http://msdn.microsoft.com/de-de/library/system.xml.xsl.xslcompiledtransform.aspx">XslCompiledTransform</a>. Der Kommentar in der MSDN sagt eigentlich alles:</p>
<blockquote><p>Die XslCompiledTransform-Klasse ist ein XSLT-Prozessor, der die XSLT 1.0 Syntax unterstützt. Dies ist eine neue Implementierung, die im Vergleich zur veralteten XslTransform-Klasse die Leistung verbessert. Die Struktur der XslCompiledTransform-Klasse ist der XslTransform-Klasse sehr ähnlich.</p></blockquote>
<p>Nebenbei werden auch noch das ShortEndTag unterstützt, womit mein Problem gelöst wäre. Der Vollständigkeit halber sollte noch auf diesen Blogeintrag hingewiesen werden: <a href="http://blogs.msdn.com/b/antosha/archive/2006/07/16/xslcompiledtransform-slower-than-xsltransform.aspx">XslCompiledTransform Slower than XslTransform?</a>, denn auch noch die veraltete XslTransform-Klasse scheint noch ihre Daseinsberechtigung zu haben.</p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.welt-held.de%2F1960-xslt-transformation-in-c.html&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://www.welt-held.de/1960-xslt-transformation-in-c.html"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.welt-held.de/1960-xslt-transformation-in-c.html"  data-text="XSLT Transformation in C#" data-count="horizontal" data-via="trashar">Tweet</a>
			</div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div> <p><a href="http://welt-held.de/?flattrss_redirect&amp;id=1960&amp;md5=cc06b2a782246bed56510c97502e9971" title="Flattr" target="_blank"><img src="http://welt-held.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.welt-held.de/1960-xslt-transformation-in-c.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="http://welt-held.de/?flattrss_redirect&amp;id=1960&amp;md5=cc06b2a782246bed56510c97502e9971" type="text/html" />
	</item>
		<item>
		<title>Löschen von Nodes in einem XML-Dokument</title>
		<link>http://www.welt-held.de/1951-loschen-von-nodes-in-einem-xml-dokument.html</link>
		<comments>http://www.welt-held.de/1951-loschen-von-nodes-in-einem-xml-dokument.html#comments</comments>
		<pubDate>Mon, 07 Mar 2011 20:43:21 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[deleteself]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[xmldocument]]></category>
		<category><![CDATA[xpathnavigator]]></category>

		<guid isPermaLink="false">http://www.welt-held.de/?p=1951</guid>
		<description><![CDATA[Ich hatte letztens ein XML-Dokument, welches ich etwas verschlanken wollte. Das Format war in etwa folgendes:
Ich wollte nur die &#8220;node1&#8243; &#8211; Node behalten, sprich alle anderen entfernen. Daher mein erster Ansatz:
Funktioniert und gut.
Nun wollte ich den Ansatz umdrehen, und alle Nodes entfernen, die  [...]]]></description>
			<content:encoded><![CDATA[<p>Ich hatte letztens ein XML-Dokument, welches ich etwas verschlanken wollte. Das Format war in etwa folgendes:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;root&gt;
  &lt;node1&gt;Content&lt;/node1&gt;
  &lt;node2&gt;Content&lt;/node2&gt;
  &lt;node3&gt;Content&lt;/node3&gt;
  &lt;node4&gt;Content&lt;/node4&gt;
&lt;/root&gt;
</pre>
<p>Ich wollte nur die &#8220;node1&#8243; &#8211; Node behalten, sprich alle anderen entfernen. Daher mein erster Ansatz:</p>
<pre class="brush: csharp; title: ; notranslate">
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.LoadXml(&quot;&lt;root&gt;&lt;node1&gt;Content&lt;/node1&gt;&lt;node2&gt;Content&lt;/node2&gt;&lt;node3&gt;Content&lt;/node3&gt;&lt;node4&gt;Content&lt;/node4&gt;&lt;/root&gt;&quot;);
XPathNavigator navigator = xmlDocument.CreateNavigator();

string[] nodesToRemove = new[] {&quot;//node2&quot;, &quot;//node3&quot;, &quot;//node4&quot;};

foreach (var nodeName in nodesToRemove)
{
	XPathNavigator node = navigator.SelectSingleNode(nodeName);
	if (node != null)
	{
		node.DeleteSelf();
	}
}

Console.WriteLine(xmlDocument.OuterXml);</pre>
<p>Funktioniert und gut.</p>
<p>Nun wollte ich den Ansatz umdrehen, und alle Nodes entfernen, die nicht den Namen &#8220;node1&#8243; haben. </p>
<pre class="brush: csharp; title: ; notranslate">XmlDocument xmlDocument = new XmlDocument();
xmlDocument.LoadXml(&quot;&lt;root&gt;&lt;node1&gt;Content&lt;/node1&gt;&lt;node2&gt;Content&lt;/node2&gt;&lt;node3&gt;Content&lt;/node3&gt;&lt;node4&gt;Content&lt;/node4&gt;&lt;/root&gt;&quot;);
XPathNavigator navigator = xmlDocument.CreateNavigator();

string xpath = &quot;/root/node()[name()!='node1']&quot;;

XPathNodeIterator nodes = navigator.Select(xpath);
while(nodes.MoveNext())
{
	if(nodes.Current != null)
	{
		nodes.Current.DeleteSelf();
	}
}

Console.WriteLine(xmlDocument.OuterXml);</pre>
<p>Leider war das Ergebnis nicht so wie erwartet, obwohl der XPath korrekt ist und die anderen Nodes selektiert. Es wurde nur &#8220;node2&#8243; gelöscht, sprich die erste Node, welche mit dem NodeIterator angesprochen wird. Durch das DeleteSelf() liefert MoveNext() automatisch false zurück, wenn es wieder aufgerufen wird. Ähnliche Probleme gibt es etwa auch, wenn in einer foreach()-Schleife der Enumerator geändert wird. Eine mögliche Lösung wäre folgendes:</p>
<pre class="brush: csharp; title: ; notranslate">while(nodes.MoveNext())
{
	if(nodes.Current != null)
	{
		nodes.Current.DeleteSelf();
		nodes = navigator.Select(xpath);
	}
}</pre>
<p>Nach dem Löschen wird der XPath einfach noch mal ausgeführt. Meiner Meinung nach keine wirklich schöne Lösung, leider aber die einzige die ich gefunden habe, welche auch funktioniert.</p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.welt-held.de%2F1951-loschen-von-nodes-in-einem-xml-dokument.html&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://www.welt-held.de/1951-loschen-von-nodes-in-einem-xml-dokument.html"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.welt-held.de/1951-loschen-von-nodes-in-einem-xml-dokument.html"  data-text="Löschen von Nodes in einem XML-Dokument" data-count="horizontal" data-via="trashar">Tweet</a>
			</div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div> <p><a href="http://welt-held.de/?flattrss_redirect&amp;id=1951&amp;md5=3f4299721257612a493b4e792875198d" title="Flattr" target="_blank"><img src="http://welt-held.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.welt-held.de/1951-loschen-von-nodes-in-einem-xml-dokument.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<atom:link rel="payment" href="http://welt-held.de/?flattrss_redirect&amp;id=1951&amp;md5=3f4299721257612a493b4e792875198d" type="text/html" />
	</item>
		<item>
		<title>Mein persönlicher Coding Style Horror</title>
		<link>http://www.welt-held.de/1942-mein-persoenlicher-coding-style-horro.html</link>
		<comments>http://www.welt-held.de/1942-mein-persoenlicher-coding-style-horro.html#comments</comments>
		<pubDate>Mon, 28 Feb 2011 22:07:08 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[Allgemein]]></category>
		<category><![CDATA[Programmierung]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[kollegen]]></category>
		<category><![CDATA[programmierung]]></category>
		<category><![CDATA[team programming]]></category>

		<guid isPermaLink="false">http://www.welt-held.de/?p=1942</guid>
		<description><![CDATA[Seit ich bei meinem neuem Arbeitgeber tätig bin, refactore ich viel Code von meinem Vorgänger. Er hat leider nur sehr funktionell gedacht, selbe Funktionen mehrfach implementiert anstatt ordentliche Überladungen oder ähnliches zu nutzen und sich leider auch nicht an vorgegebene Coding Styles  [...]]]></description>
			<content:encoded><![CDATA[<p>Seit ich bei meinem neuem Arbeitgeber tätig bin, refactore ich viel Code von meinem Vorgänger. Er hat leider nur sehr funktionell gedacht, selbe Funktionen mehrfach implementiert anstatt ordentliche Überladungen oder ähnliches zu nutzen und sich leider auch nicht an vorgegebene Coding Styles gehalten. Mittlerweile habe ich hier schon sehr viel Zeit investiert, finde jedoch immer wieder Stellen, bei denen ich einfach nur die Hände über den Kopf zusammenschlagen kann. Einige Dinge passieren mir auch gerne mal, was ich dann aber doch viel schlimmer finde, ist die Tatsache, dass es andere Kollegen kopieren, den Variablennamen ändern und sich den Mist nicht einmal anschauen. Und sich so natürlich Fehler einschleichen können, welche sich durch die ganze Anwendung ziehen. Und das bereits seit einigen produktiven Versionen. Hier mal ein paar fiktive Beispiele:</p>
<pre class="brush: csharp; title: ; notranslate">
if(!string.IsNullOrEmpty(groupName) &amp;&amp; (groupName != &quot;Wert1&quot; || groupName != &quot;Wert2&quot;)) { .. }
</pre>
<p>So eine Code-Stelle war bereits seit 2 1/2 Jahren implementiert. Die if-Bedingung ist immer wahr, sobald <em>groupName</em> gesetzt ist. Die hinteren beiden Bedingungen waren total sinnfrei. Glück im Unglück, in der if-Bedingung wurde zufällig noch mal gefiltert, so dass es hinhaute.<br />
Oder das hier:</p>
<pre class="brush: csharp; title: ; notranslate">
public bool MyProperty {
    get {
         bool myProperty = MethodeSowieso(..);
         return myProperty;
    }
}
</pre>
<p>Warum erst in eine Variable packen?</p>
<pre class="brush: csharp; title: ; notranslate">
if(irgendeineTrueFalseBedingung) {
      return true;
}
else {
       return false;
}
</pre>
<p>Brauch ich ja nicht weiter zu erläutern oder?<br />
Einen kleinen Trieb bekomme ich persönlich beim Klammern. Nehmen wir noch mal das Beispiel von ganz oben, diesmal korrekt aber ohne Klammern:</p>
<pre class="brush: csharp; title: ; notranslate">
if(!string.IsNullOrEmpty(groupName) &amp;&amp; groupName == &quot;Wert1&quot; || groupName == &quot;Wert2&quot;) { .. }
</pre>
<p>Ich muss erstmal genau Nachdenken, um zu sagen, bei welchen Werten die Bedingung erfüllt ist. Mit zwei Klammern wird dieses Problem sofort gelöst und man kann es als Entwickler nicht mal falsch interpretieren. Ein anderer Kollege klammert auch gern zu viel:</p>
<pre class="brush: csharp; title: ; notranslate">
return (variable);
</pre>
<p>Es stört meiner Meinung nach nur beim Lesen und Sinn erkenne ich hier absolut nicht.</p>
<p>Ich erwarte ja keinen perfekten Code, sicherlich habe ich auch einige Coding Styles an mir, welche andere zum Würgen bringen. Aber ist es zu viel verlangt, zwei mal darüber nachzudenken, was man grade programmiert hat? Und das es auch andere verstehen müssen? </p>
<p>JM2C</p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.welt-held.de%2F1942-mein-persoenlicher-coding-style-horro.html&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://www.welt-held.de/1942-mein-persoenlicher-coding-style-horro.html"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.welt-held.de/1942-mein-persoenlicher-coding-style-horro.html"  data-text="Mein persönlicher Coding Style Horror" data-count="horizontal" data-via="trashar">Tweet</a>
			</div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div> <p><a href="http://welt-held.de/?flattrss_redirect&amp;id=1942&amp;md5=535d57bfc6e3656d224af33af942b318" title="Flattr" target="_blank"><img src="http://welt-held.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.welt-held.de/1942-mein-persoenlicher-coding-style-horro.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="http://welt-held.de/?flattrss_redirect&amp;id=1942&amp;md5=535d57bfc6e3656d224af33af942b318" type="text/html" />
	</item>
		<item>
		<title>HowTo: C# Programm nur mit NotifyIcon ohne Form starten</title>
		<link>http://www.welt-held.de/1935-howto-c-programm-nur-mit-notifyicon-ohne-form-starten.html</link>
		<comments>http://www.welt-held.de/1935-howto-c-programm-nur-mit-notifyicon-ohne-form-starten.html#comments</comments>
		<pubDate>Sat, 08 Jan 2011 11:32:23 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[How To]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[notifyicon]]></category>
		<category><![CDATA[winforms]]></category>

		<guid isPermaLink="false">http://www.welt-held.de/?p=1935</guid>
		<description><![CDATA[Für den Fall, dass ihr eine Anwendung erstellen wollt, welche (zum Start) nur ein NotifyIcon (also ein Symbol in der Taskleiste besitzt), müsst ihr den Standardprogrammaufruf etwas abändern.
Der standardmäßig erstellte Code von VisualStudio startet automatisch eine Form. Diese könnte man nun  [...]]]></description>
			<content:encoded><![CDATA[<p>Für den Fall, dass ihr eine Anwendung erstellen wollt, welche (zum Start) nur ein NotifyIcon (also ein Symbol in der Taskleiste besitzt), müsst ihr den Standardprogrammaufruf etwas abändern.<br />
Der standardmäßig erstellte Code von VisualStudio startet automatisch eine Form. Diese könnte man nun ausblenden (WindowState = Minimized, ShowInTaskBar = false) aber es geht auch eleganter. Erstellt einfach ein NotifyIcon mit Icon und Visible = true und ruft Application.Run() ohne Parameter auf.</p>
<pre class="brush: csharp; title: ; notranslate">		/// &lt;summary&gt;
		/// 	Der Haupteinstiegspunkt für die Anwendung.
		/// &lt;/summary&gt;
		[STAThread]
		private static void Main()
		{
			Application.EnableVisualStyles();
			Application.SetCompatibleTextRenderingDefault(false);

			_trayIcon = new NotifyIcon {Icon = Icon.FromHandle(new Bitmap(&quot;Gear.png&quot;).GetHicon()), Visible = true};
			_trayIcon.Click += TrayIconClick;

			Application.Run();
			_trayIcon.Dispose();
		}</pre>
<p>Im Anhang findet ihr eine Beispielsolution. Wichtig ist, dass ihr euch selbst ums Dispose() kümmern müsst, damit etwa das NotifyIcon aus der Taskleiste verschwindet, sobald die Applikation beendet wird. Das Beispiel öffnet beim Klick auf das NotifyIcon eine leere Form. Wird diese geschlossen, wird das ganze Programm beendet.</p>
<p>Download: <a href='http://welt-held.de/files/StartWithNotifyIcon.zip'>Beispiel Solution &#8211; Start App With Notify Icon</a></p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.welt-held.de%2F1935-howto-c-programm-nur-mit-notifyicon-ohne-form-starten.html&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://www.welt-held.de/1935-howto-c-programm-nur-mit-notifyicon-ohne-form-starten.html"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.welt-held.de/1935-howto-c-programm-nur-mit-notifyicon-ohne-form-starten.html"  data-text="HowTo: C# Programm nur mit NotifyIcon ohne Form starten" data-count="horizontal" data-via="trashar">Tweet</a>
			</div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div> <p><a href="http://welt-held.de/?flattrss_redirect&amp;id=1935&amp;md5=786e015a4eb30ec008b2a77ab6ccc0c5" title="Flattr" target="_blank"><img src="http://welt-held.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.welt-held.de/1935-howto-c-programm-nur-mit-notifyicon-ohne-form-starten.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="http://welt-held.de/?flattrss_redirect&amp;id=1935&amp;md5=786e015a4eb30ec008b2a77ab6ccc0c5" type="text/html" />
	</item>
		<item>
		<title>Icons in Visual Studio 2010</title>
		<link>http://www.welt-held.de/1917-icons-in-visual-studio-2010.html</link>
		<comments>http://www.welt-held.de/1917-icons-in-visual-studio-2010.html#comments</comments>
		<pubDate>Tue, 26 Oct 2010 07:32:58 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[icons]]></category>
		<category><![CDATA[visual studio]]></category>

		<guid isPermaLink="false">http://www.welt-held.de/?p=1917</guid>
		<description><![CDATA[Ich habe immer das Problem, geeignete Icons für meine Applikationen zu finden, meistens wird dann wild bei Google nach etwas passendem und schönen gesucht. 
Dabei bringt Visual Studio 2010 eine Reihe von wunderschönen Icons mit.

			
			
			
			
			
			
			Tweet
						
			]]></description>
			<content:encoded><![CDATA[<p>Ich habe immer das Problem, geeignete Icons für meine Applikationen zu finden, meistens wird dann wild bei Google nach etwas passendem und schönen gesucht. </p>
<p><a href="http://blogs.msdn.com/b/olivers/archive/2010/10/25/visual-studio-2010-anwendungen-entwickeln-mit-schicken-icons.aspx">Dabei bringt Visual Studio 2010 eine Reihe von wunderschönen Icons mit</a>.</p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.welt-held.de%2F1917-icons-in-visual-studio-2010.html&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://www.welt-held.de/1917-icons-in-visual-studio-2010.html"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.welt-held.de/1917-icons-in-visual-studio-2010.html"  data-text="Icons in Visual Studio 2010" data-count="horizontal" data-via="trashar">Tweet</a>
			</div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div> <p><a href="http://welt-held.de/?flattrss_redirect&amp;id=1917&amp;md5=5318977fd5667a17c27cdb22e42bed11" title="Flattr" target="_blank"><img src="http://welt-held.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.welt-held.de/1917-icons-in-visual-studio-2010.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="http://welt-held.de/?flattrss_redirect&amp;id=1917&amp;md5=5318977fd5667a17c27cdb22e42bed11" type="text/html" />
	</item>
		<item>
		<title>Passwort Karte</title>
		<link>http://www.welt-held.de/1912-passwort-karte.html</link>
		<comments>http://www.welt-held.de/1912-passwort-karte.html#comments</comments>
		<pubDate>Sat, 23 Oct 2010 07:15:45 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[password card]]></category>

		<guid isPermaLink="false">http://www.welt-held.de/?p=1912</guid>
		<description><![CDATA[Ich habe vor ein paar Tagen beim Hostblogger von der Passwort-Karte gelesen. Ich finde die Idee nicht schlecht, und es ist besser als Passwörter oder PINs versteckt auf kleinen Zettelchen in der Geldbörse zu haben oder in seinem Handy als Notiz.
Jedoch hat der Generator vom Manuel Schmitt einen  [...]]]></description>
			<content:encoded><![CDATA[<p>Ich habe vor ein paar Tagen beim <a href="http://www.hostblogger.de/">Hostblogger</a> von der <a href="http://www.hostblogger.de/blog/archives/4951-Passwort-Karte-5.html">Passwort-Karte</a> gelesen. Ich finde die Idee nicht schlecht, und es ist besser als Passwörter oder PINs versteckt auf kleinen Zettelchen in der Geldbörse zu haben oder in seinem Handy als Notiz.</p>
<p>Jedoch hat der Generator vom Manuel Schmitt einen kleinen Nachteil. Nun gibt es Passwörter / PINs die ich mir nicht merken kann aber auch nicht ändern kann. Sprich ich muss eine Möglichkeit haben, meine vorhandenen Daten in so ein &#8220;Zufallsbild&#8221; hineinzubekommen. Und daran arbeite ich gerade.<br />
Aktuell kann man sich die Passwortkarte schon generieren, eigene Daten kann man aber noch nicht angeben.</p>
<p><a href="http://welt-held.de/files/pc.jpg"><img src="http://welt-held.de/files/pc-150x150.jpg" alt="" title="Password Card Generator" width="150" height="150" class="aligncenter size-thumbnail wp-image-1913" /></a></p>
<p>Wenn der Kram fertig ist, gibs ihn hier zum herunterladen!</p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.welt-held.de%2F1912-passwort-karte.html&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://www.welt-held.de/1912-passwort-karte.html"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.welt-held.de/1912-passwort-karte.html"  data-text="Passwort Karte" data-count="horizontal" data-via="trashar">Tweet</a>
			</div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div> <p><a href="http://welt-held.de/?flattrss_redirect&amp;id=1912&amp;md5=1dc660a4abf8334b2c606cdc4e6586ea" title="Flattr" target="_blank"><img src="http://welt-held.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.welt-held.de/1912-passwort-karte.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="http://welt-held.de/?flattrss_redirect&amp;id=1912&amp;md5=1dc660a4abf8334b2c606cdc4e6586ea" type="text/html" />
	</item>
		<item>
		<title>Ein Dictionary als DataSource</title>
		<link>http://www.welt-held.de/1858-ein-dictionary-als-datasource.html</link>
		<comments>http://www.welt-held.de/1858-ein-dictionary-als-datasource.html#comments</comments>
		<pubDate>Mon, 23 Aug 2010 21:44:22 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[bindingsource]]></category>
		<category><![CDATA[combobox]]></category>
		<category><![CDATA[databinding]]></category>
		<category><![CDATA[datasource]]></category>
		<category><![CDATA[dictionary]]></category>

		<guid isPermaLink="false">http://www.welt-held.de/?p=1858</guid>
		<description><![CDATA[Ich habe ein Dictionary nach folgendem Schema:
Die Werte möchte ich in einer ComboBox haben, die Values als anzuzeigenden Text, die Values soll er mir im Code zurückgeben. Ein Dictionary kann man jedoch nicht direkt als DataSource binden. Da die Lösung selbst bei Google etwas versteckt ist, hier  [...]]]></description>
			<content:encoded><![CDATA[<p>Ich habe ein Dictionary nach folgendem Schema:</p>
<pre class="brush: csharp; title: ; notranslate">
var dic = new Dictionary&lt;string, string&gt;()
       	{
	{&quot;de&quot;, &quot;Deutsch&quot;},
	{&quot;en&quot;, &quot;Englisch&quot;}
       	};
</pre>
<p>Die Werte möchte ich in einer ComboBox haben, die Values als anzuzeigenden Text, die Values soll er mir im Code zurückgeben. Ein Dictionary kann man jedoch nicht direkt als DataSource binden. Da die Lösung selbst bei Google etwas versteckt ist, hier die Lösung:</p>
<pre class="brush: csharp; title: ; notranslate">
combobox1.DataSource = new BindingSource(dic, null);
combobox1.DisplayMember = &quot;Value&quot;;
combobox1.ValueMember = &quot;Key&quot;;
</pre>
<p>Und schon werden alle Einträge aus dem Dictionary angezeigt <img src='http://welt-held.de/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>(via <a href="http://madprops.org/blog/bind-a-combobox-to-a-generic-dictionary/">Mad Props</a>)</p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.welt-held.de%2F1858-ein-dictionary-als-datasource.html&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://www.welt-held.de/1858-ein-dictionary-als-datasource.html"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.welt-held.de/1858-ein-dictionary-als-datasource.html"  data-text="Ein Dictionary als DataSource" data-count="horizontal" data-via="trashar">Tweet</a>
			</div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div> <p><a href="http://welt-held.de/?flattrss_redirect&amp;id=1858&amp;md5=8364c30d06be5c1f2b4f0b156b106bd5" title="Flattr" target="_blank"><img src="http://welt-held.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.welt-held.de/1858-ein-dictionary-als-datasource.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="http://welt-held.de/?flattrss_redirect&amp;id=1858&amp;md5=8364c30d06be5c1f2b4f0b156b106bd5" type="text/html" />
	</item>
		<item>
		<title>Wie bringe ich mich selbst zum Kommentieren meines Codes?</title>
		<link>http://www.welt-held.de/1852-wie-bringe-ich-mich-selbst-zum-kommentieren-meines-codes.html</link>
		<comments>http://www.welt-held.de/1852-wie-bringe-ich-mich-selbst-zum-kommentieren-meines-codes.html#comments</comments>
		<pubDate>Sat, 14 Aug 2010 06:25:20 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[]]></category>
		<category><![CDATA[ghostdoc]]></category>
		<category><![CDATA[kommentieren]]></category>
		<category><![CDATA[visual studio]]></category>
		<category><![CDATA[xml kommentare]]></category>

		<guid isPermaLink="false">http://www.welt-held.de/?p=1852</guid>
		<description><![CDATA[Man ist ja selbst etwas faul. Meist weiß man, was sein Code so macht (oder besser machen sollte) und man kommentiert daher nur sehr sporadisch. Wenn man den Code dann eine Weile später wieder zur Hand nimmt, fällt es einem oft schwer seinen alten Code zu verstehen.
Daher gibt es Kommentare, in C#  [...]]]></description>
			<content:encoded><![CDATA[<p>Man ist ja selbst etwas faul. Meist weiß man, was sein Code so macht (oder besser machen sollte) und man kommentiert daher nur sehr sporadisch. Wenn man den Code dann eine Weile später wieder zur Hand nimmt, fällt es einem oft schwer seinen alten Code zu verstehen.<br />
Daher gibt es Kommentare, in C# in Form des &#8220;<strong>&lt;summary&gt;</strong>&#8220;-Tags. Drei Slashes und Visual Studio fügt schon automatisch das Grundgerüst ein.<br />
Damit nun auch wirklich jede public / internal Methode / Property kommentiert wird, muss man den Kompiler sagen, dass er fehlende Summaries als Fehler an erkennen soll.</p>
<p>Dazu geht ihr in die Projekteigenschaften und aktiviert unter dem Reiter &#8220;Erstellen&#8221; den Hacken bei &#8220;XML-Dokumentationsdatei&#8221;. Nun erstellt er euch aus den Kommentaren bei jedem Build eine solche XML-Datei. Im Editor wird nun auch schon angemeckert, dass die XML-Kommentare fehlen. Um euch nun wirklich zu zwingen, sollte die Solution gar nicht erst gebaut werden, wenn die Kommentare fehlen. Das Fehlen wird als Warning gemeldet, daher sagen wir den Kompiler einfach, er soll Warnings als Fehler behandeln.<br />
Dies geschieht ebenfalls in den Projekteigenschaften unter &#8220;Erstellen&#8221;. Evtl. kann man das noch verfeinern, indem man nur bestimmte Warnungen als Fehler behandelt, jedoch konnte ich auf die schnelle keine entsprechenden Informationen dazu finden. Ich versuche diese nachzureichen.</p>
<p><a href="http://welt-held.de/files/xmldokuaktivieren.jpg"><img src="http://welt-held.de/files/xmldokuaktivieren-150x150.jpg" alt="" title="Xml Dokumentation aktivieren und Warnungen als Fehler behandeln" width="150" height="150" class="aligncenter size-thumbnail wp-image-1853" /></a></p>
<p>Von nun an lässt sich die Solution also nicht mehr kompilieren, sofern nicht überall Kommentare verfasst wurden. Um sich das Leben an dieser Stelle deutlich einfacher zu machen, empfehle ich die kostenlose Visual Studio Erweiterung <a href="http://submain.com/products/ghostdoc.aspx">GhostDoc</a>. Mit ihr könnt ihr per Rechtsklick oder Tastenkombination eure Methode oder Property kommentieren. Dabei werden zum Beispiel schon vorhandene Kommentare aus Interfaces über Überladungen übernommen. Ansonsten erstellt er anhand des Methodennamen eine entsprechende Dokumentation. Man kann sich auch eigene Templates anlegen (habe ich mir sagen lassen). Gebündelt mit einem ordentlichen Programmierstil (bei der Namensgebung) kann man so bestimmt 80% automatisch kommentieren. Eine unglaubliche Zeitersparnis.</p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.welt-held.de%2F1852-wie-bringe-ich-mich-selbst-zum-kommentieren-meines-codes.html&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://www.welt-held.de/1852-wie-bringe-ich-mich-selbst-zum-kommentieren-meines-codes.html"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.welt-held.de/1852-wie-bringe-ich-mich-selbst-zum-kommentieren-meines-codes.html"  data-text="Wie bringe ich mich selbst zum Kommentieren meines Codes?" data-count="horizontal" data-via="trashar">Tweet</a>
			</div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div> <p><a href="http://welt-held.de/?flattrss_redirect&amp;id=1852&amp;md5=77b55d602cbf2354c054ad93d29d3a58" title="Flattr" target="_blank"><img src="http://welt-held.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.welt-held.de/1852-wie-bringe-ich-mich-selbst-zum-kommentieren-meines-codes.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="http://welt-held.de/?flattrss_redirect&amp;id=1852&amp;md5=77b55d602cbf2354c054ad93d29d3a58" type="text/html" />
	</item>
		<item>
		<title>WinMerge mit AnkhSVN nutzen</title>
		<link>http://www.welt-held.de/1849-winmerge-mit-ankhsvn-nutzen.html</link>
		<comments>http://www.welt-held.de/1849-winmerge-mit-ankhsvn-nutzen.html#comments</comments>
		<pubDate>Fri, 13 Aug 2010 19:01:18 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[ankhsvn]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[diff]]></category>
		<category><![CDATA[merge]]></category>
		<category><![CDATA[subversion]]></category>
		<category><![CDATA[svn]]></category>
		<category><![CDATA[tool]]></category>
		<category><![CDATA[visual studio]]></category>
		<category><![CDATA[winmerge]]></category>

		<guid isPermaLink="false">http://www.welt-held.de/?p=1849</guid>
		<description><![CDATA[Sollte jemand von euch AnkhSVN in Visual Studio nutzen und ihr möchtet eure Dateien mit WinMerge vergleichen oder mergen, dann müsst ihr unter Optionen - Source Control - Subversion User Tools folgende Befehle angeben
Den Merge-Befehl (der zweite) habe ich noch nicht getestet. Wichtig ist, dass die  [...]]]></description>
			<content:encoded><![CDATA[<p>Sollte jemand von euch <a href="http://ankhsvn.open.collab.net/">AnkhSVN</a> in Visual Studio nutzen und ihr möchtet eure Dateien mit WinMerge vergleichen oder mergen, dann müsst ihr unter Optionen -> Source Control -> Subversion User Tools folgende Befehle angeben</p>
<pre class="brush: plain; title: ; notranslate">
C:\Program Files (x86)\WinMerge\WinMergeU.exe /x /e /wl /ub /dl &quot;$(BaseName)&quot; /dr &quot;$(MineName)&quot; &quot;$(Base)&quot; &quot;$(Mine)&quot;

C:\Program Files (x86)\WinMerge\WinMergeU.exe /x /e /wl /ub /dl &quot;$(TheirName)&quot; /dr &quot;$(MineName)&quot; &quot;$(Theirs)&quot; &quot;$(Mine)&quot; &quot;$(Merged)&quot;
</pre>
<p>Den Merge-Befehl (der zweite) habe ich noch nicht getestet. Wichtig ist, dass die Anführungszeichen setzt. Sonst gibt es Probleme bei Leerzeichen und WinMerge will irgendwelche Verzeichnisse anstatt Dateien öffnen.</p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.welt-held.de%2F1849-winmerge-mit-ankhsvn-nutzen.html&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://www.welt-held.de/1849-winmerge-mit-ankhsvn-nutzen.html"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.welt-held.de/1849-winmerge-mit-ankhsvn-nutzen.html"  data-text="WinMerge mit AnkhSVN nutzen" data-count="horizontal" data-via="trashar">Tweet</a>
			</div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div> <p><a href="http://welt-held.de/?flattrss_redirect&amp;id=1849&amp;md5=4d708ae660aaf5054eea5047799b656c" title="Flattr" target="_blank"><img src="http://welt-held.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.welt-held.de/1849-winmerge-mit-ankhsvn-nutzen.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="http://welt-held.de/?flattrss_redirect&amp;id=1849&amp;md5=4d708ae660aaf5054eea5047799b656c" type="text/html" />
	</item>
		<item>
		<title>Dämlicher Programmierfehler</title>
		<link>http://www.welt-held.de/1756-damlicher-programmierfehler.html</link>
		<comments>http://www.welt-held.de/1756-damlicher-programmierfehler.html#comments</comments>
		<pubDate>Tue, 23 Mar 2010 10:30:37 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[index]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[out of range]]></category>
		<category><![CDATA[problem]]></category>

		<guid isPermaLink="false">http://www.welt-held.de/?p=1756</guid>
		<description><![CDATA[Grad bestimmt 20 Minuten bei der Fehlersuche drauf gegangen. Folgender Code:
Mein Code war natürlich nicht mit Integerwerten. Ich musste noch ein paar andere Sachen machen, daher war ein RemoveRange() nicht möglich.
Nun wer findet den Fehler?
Ich liste es einfach mal auf:
Beim letzten Durchlauf  [...]]]></description>
			<content:encoded><![CDATA[<p>Grad bestimmt 20 Minuten bei der Fehlersuche drauf gegangen. Folgender Code:</p>
<pre class="brush: csharp; title: ; notranslate">

List&lt;int&gt; _list = new List&lt;int&gt;();
_list.Add(1);
_list.Add(2);
_list.Add(3);
_list.Add(4);

for(int i = 1; i &lt;= 3; i++) {
   int x = _list[i];
   _list.Remove(x);
}
</pre>
<p>Mein Code war natürlich nicht mit Integerwerten. Ich musste noch ein paar andere Sachen machen, daher war ein RemoveRange() nicht möglich.<br />
Nun wer findet den Fehler?</p>
<p>Ich liste es einfach mal auf:</p>
<pre class="brush: plain; title: ; notranslate">
Durchlauf: 1 - Lösche Element 1 - Rest 2
Durchlauf: 2 - Lösche Element 2 - Rest 1
Durchlauf: 3 - Lösche Element 3 - Rest 0
</pre>
<p>Beim letzten Durchlauf wird er immer Probleme kriegen. Das Element gibt es nicht mehr. Durch Remove() rücken die Elemente in der Indizierung nach.<br />
Es müsste also heißen:</p>
<pre class="brush: plain; title: ; notranslate">
Durchlauf: 1 - Lösche Element 1 - Rest 2
Durchlauf: 2 - Lösche Element 1 - Rest 1
Durchlauf: 3 - Lösche Element 1 - Rest 0
</pre>
<p> oder in C#-Code:</p>
<pre class="brush: csharp; title: ; notranslate">for(int i = 1; i &lt;= 3; i++) {
   int x = _list[1];
   _list.Remove(x);
}
</pre>
<p>Vor allem wenn man in den Debugger schaut, kamen da merkwürdige Werte raus. <a href="http://welt-held.de/files/csharpproblem.jpg"><img src="http://welt-held.de/files/csharpproblem-150x150.jpg" alt="" title="C# Problem mit Liste." width="150" height="150" class="alignnone size-thumbnail wp-image-1757" /></a><br />
Ich sehe, dass die Methode &#8220;DeleteEntries()&#8221; mit dem Count-Parameter 2 aufgerufen wird, oben zeigt mir der Debugger aber 1 an. Liegt daran, dass in der Liste bereits ein Element entfernt wurde. Somit ist also, wenn man es genau nimmt, beides richtig.</p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.welt-held.de%2F1756-damlicher-programmierfehler.html&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://www.welt-held.de/1756-damlicher-programmierfehler.html"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.welt-held.de/1756-damlicher-programmierfehler.html"  data-text="Dämlicher Programmierfehler" data-count="horizontal" data-via="trashar">Tweet</a>
			</div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div> <p><a href="http://welt-held.de/?flattrss_redirect&amp;id=1756&amp;md5=4ea2a531bd52f782cc51981bf0c93904" title="Flattr" target="_blank"><img src="http://welt-held.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.welt-held.de/1756-damlicher-programmierfehler.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="http://welt-held.de/?flattrss_redirect&amp;id=1756&amp;md5=4ea2a531bd52f782cc51981bf0c93904" type="text/html" />
	</item>
		<item>
		<title>PHP: Direktzugriff auf eine Datei unterbinden</title>
		<link>http://www.welt-held.de/1732-php-direktzugriff-auf-eine-datei-unterbinden.html</link>
		<comments>http://www.welt-held.de/1732-php-direktzugriff-auf-eine-datei-unterbinden.html#comments</comments>
		<pubDate>Sat, 13 Mar 2010 08:51:57 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[Programmierung]]></category>
		<category><![CDATA[codeschnippsel]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.welt-held.de/?p=1732</guid>
		<description><![CDATA[Falls man den direkten Zugriff auf eine PHP-Datei unterbinden möchte (z.B. wo die Konfigurationen drin stehen), kann man folgenden Code nutzen:
Man kann alternativ auf &#8220;HTTP/1.1 403 Forbidden&#8221; senden, so wird dem Benutzer aber gleich vorgegaukelt, dass die Datei gar nicht existent sei.
In andere  [...]]]></description>
			<content:encoded><![CDATA[<p>Falls man den direkten Zugriff auf eine PHP-Datei unterbinden möchte (z.B. wo die Konfigurationen drin stehen), kann man folgenden Code nutzen:</p>
<pre class="brush: php; title: ; notranslate">if(basename($_SERVER[&quot;SCRIPT_FILENAME&quot;]) == basename(__FILE__)) {
	header (&quot;HTTP/1.1 404 Not Found&quot;);
	exit;
}</pre>
<p>Man kann alternativ auf &#8220;HTTP/1.1 403 Forbidden&#8221; senden, so wird dem Benutzer aber gleich vorgegaukelt, dass die Datei gar nicht existent sei.<br />
In andere Scripte kann man die Datei dennoch ganz normal importieren, etwa per require().</p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.welt-held.de%2F1732-php-direktzugriff-auf-eine-datei-unterbinden.html&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://www.welt-held.de/1732-php-direktzugriff-auf-eine-datei-unterbinden.html"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.welt-held.de/1732-php-direktzugriff-auf-eine-datei-unterbinden.html"  data-text="PHP: Direktzugriff auf eine Datei unterbinden" data-count="horizontal" data-via="trashar">Tweet</a>
			</div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div> <p><a href="http://welt-held.de/?flattrss_redirect&amp;id=1732&amp;md5=afb5aa6b95cb4400ee7357fb65de84d2" title="Flattr" target="_blank"><img src="http://welt-held.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.welt-held.de/1732-php-direktzugriff-auf-eine-datei-unterbinden.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="http://welt-held.de/?flattrss_redirect&amp;id=1732&amp;md5=afb5aa6b95cb4400ee7357fb65de84d2" type="text/html" />
	</item>
		<item>
		<title>C#4.0 &#8211; Problematik bei Default Values</title>
		<link>http://www.welt-held.de/1715-c4-0-problematik-bei-default-values.html</link>
		<comments>http://www.welt-held.de/1715-c4-0-problematik-bei-default-values.html#comments</comments>
		<pubDate>Fri, 12 Mar 2010 17:43:02 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[How To]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[c#4.0]]></category>
		<category><![CDATA[default values]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[lösung]]></category>
		<category><![CDATA[problem]]></category>

		<guid isPermaLink="false">http://www.welt-held.de/?p=1715</guid>
		<description><![CDATA[Golo Roden erwähnte es bereits in den Kommentaren, daher möchte ich noch mal genauer darauf eingehen.
Dazu erstelle ich eine Solution in Visual Studio 2010 mit einer Konsolenapplikation, welche ich &#8220;DefaultValues&#8221; nenne.
Die alte Schreibweise
Die Schreibweise unter C#3.0 mit Überladung wäre also in  [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.des-eisbaeren-blog.de/">Golo Roden</a> erwähnte es bereits in den <a href="http://www.welt-held.de/1713-c-4-0-default-values-und-delegates.html#comment-19050">Kommentaren</a>, daher möchte ich noch mal genauer darauf eingehen.<br />
Dazu erstelle ich eine Solution in Visual Studio 2010 mit einer Konsolenapplikation, welche ich &#8220;DefaultValues&#8221; nenne.<span id="more-1715"></span></p>
<h3>Die alte Schreibweise</h3>
<p>Die Schreibweise unter C#3.0 mit Überladung wäre also in etwa so:</p>
<pre class="brush: csharp; title: ; notranslate">    public class Program
    {
        static void Main(string[] args)
        {

            AddValues(&quot;Ich bin ein&quot;, &quot;String&quot;);
            Console.WriteLine(_value);

            AddValues(&quot;Ich bin ein&quot;, &quot;String&quot;, true);

            Console.ReadLine();
        }

        public static string _value;

        public static void AddValues(string value1, string value2)
        {
            AddValues(value1, value2, false);
        }
        public static void AddValues(string value1, string value2, bool output)
        {
            _value = string.Format(&quot;{0} {1}&quot;, value1, value2);
            if(output)
            {
                Console.WriteLine(_value);
            }
        }
    }</pre>
<p>Wenn wir nun das Projekt ausführen erhalten wir folgende Ausgabe.</p>
<pre class="brush: plain; title: ; notranslate">Ich bin ein String
Ich bin ein String</pre>
<p>Die erste Ausgabe erfolgt manuell, die zweite direkt in der Methode, wie gewünscht.</p>
<h3>C#4.0 mit Default Values</h3>
<p>Unter C#4.0 mit Default Values kann man die ganze Sache nun vereinfachen:</p>
<pre class="brush: csharp; title: ; notranslate">public static void AddValues(string value1, string value2, bool output = false)
{
    _value = string.Format(&quot;{0} {1}&quot;, value1, value2);
    if(output)
    {
        Console.WriteLine(_value);
    }
}</pre>
<p>Die Ausgabe ist identisch. Die erste Zeile wird manuell ausgegeben, die zweite über den Methodenaufruf. Das macht die Sache einfach, spart Code, macht ihn leserlicher. Man findet sicherlich noch weitere Vorteile.</p>
<h3>Das Problem erkennen</h3>
<p>Kommen wir nun zu den Problemen. Bevor ich die erläutern kann, muss man wissen, wie C# die Default Values behandelt. Wenn man sich die Anwendung per <a href="http://reflector.red-gate.com/Download.aspx">Reflector</a> ansieht, sieht man folgenden Code (in der C#-Ansicht):</p>
<pre class="brush: csharp; title: ; notranslate">
private static void AddValues(string value1, string value2, [Optional, DefaultParameterValue(false)] bool output);
</pre>
<p>Die Zeile spricht für sich. Der Standardwert lautet &#8220;false&#8221;. Nun erstellen wir ein neues Projekt (&#8220;TestApp&#8221;) und referenzieren auf unsere Methode mit dem Default Value:</p>
<pre class="brush: csharp; title: ; notranslate">namespace TestApp
{
    class Program
    {
        static void Main(string[] args)
        {
            DefaultValues.Program.AddValues(&quot;Ich bin ein&quot;, &quot;String&quot;);
            Console.WriteLine(DefaultValues.Program._value);

            Console.ReadLine();
        }
    }
}</pre>
<p>Ausgegben wird eine Zeile, wie erwartet, durch die manuelle Ausgabe. Nun sehen wir uns die zweite Exe-Datei mal im Reflector an:</p>
<pre class="brush: csharp; title: ; notranslate">
Program.AddValues(&quot;Ich bin ein&quot;, &quot;String&quot;, false);
</pre>
<p>Auf einmal sind drei Parameter vorhanden, obwohl wir nur zwei im Sourcecode angegeben haben. Der Compiler setzt automatisch den dritten Parameter mit dem Standardwert, in dem Fall <em>false</em>.<br />
Nun ändern wir die AddValues()-Methode, die Ausgabe soll standardmäßig sofort in der Methode erfolgen, zudem ändern wir den String etwas:</p>
<pre class="brush: csharp; title: ; notranslate">public static void AddValues(string value1, string value2, bool output = true)
{
    _value = string.Format(&quot;Zusammengesetzt: {0} {1}&quot;, value1, value2);
    if (output)
    {
        Console.WriteLine(_value);
    }
}</pre>
<p>Nun kompilier ich <strong>nur</strong> das Projekt &#8220;DefaultValues&#8221; und kopiere die DefaultValues.exe in das Bin-Verzeichnis der TestApp. Wenn ich nun die TestApp.exe starte erhalte ich folgende Ausgabe:</p>
<pre class="brush: plain; title: ; notranslate">Zusammengesetzt: Ich bin ein String</pre>
<p>Allerdings haben wir den Standardwert für die Ausgabe auf true gesetzt, daher müsste die Ausgabe doppelt erscheinen, einmal direkt über den Methodenaufruf und einmal durch die manuelle Ausgabe.</p>
<h3>Problem beheben</h3>
<p>Dieses Problem resultiert daher, dass der Standardwert nicht &#8220;on-the-fly&#8221; aus der DefaultValue.exe geholt wird, sondern vom Compiler in der TestApp.exe gesetzt wurde.<br />
Die Methode aus der DefaultValues.exe wird also immer noch mit &#8220;AddValues(&#8220;Ich bin ein&#8221;, &#8220;String&#8221;, <strong>false</strong>);&#8221; aufgerufen. Und so lange wir das TestApp-Projekt nicht neu kompilieren, wird sich an der Ausgabe nichts ändern. </p>
<h3>Fazit</h3>
<p>Default Values sind eine nette Sache, um sich Überladungen zu sparen, den Code leserlicher zu machen und dem Programmierer das Leben leichter. Aber eigentlich gibt es keine Default Value, der Compiler setzt einfach nur die Werte, die man vorher manuell gesetzt hat. Wenn man diesen Aspekt nicht vergisst, können DefaultValues eine schöne Sache sein, ansonsten sucht man sich wahrscheinlich dumm und dämlich, bis man den Fehler gefunden hat.</p>
<p>Vielen Dank hier noch mal an <a href="http://www.sturmnet.org/blog/">Oliver Sturm</a>, welcher die Problematik auf der Basta kurz aber verständlich erklärt hat.</p>
<p>Beispielsolution: <a href='http://welt-held.de/files/BeispielSolutionDefaultValues.zip'>DefaultValues.zip</a></p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.welt-held.de%2F1715-c4-0-problematik-bei-default-values.html&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://www.welt-held.de/1715-c4-0-problematik-bei-default-values.html"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.welt-held.de/1715-c4-0-problematik-bei-default-values.html"  data-text="C#4.0 &#8211; Problematik bei Default Values" data-count="horizontal" data-via="trashar">Tweet</a>
			</div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div> <p><a href="http://welt-held.de/?flattrss_redirect&amp;id=1715&amp;md5=e4971f6553803c5035b2e9dac05704c5" title="Flattr" target="_blank"><img src="http://welt-held.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.welt-held.de/1715-c4-0-problematik-bei-default-values.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<atom:link rel="payment" href="http://welt-held.de/?flattrss_redirect&amp;id=1715&amp;md5=e4971f6553803c5035b2e9dac05704c5" type="text/html" />
	</item>
		<item>
		<title>ShowDialog() verzögert Applikation</title>
		<link>http://www.welt-held.de/1710-showdialog-verzogert-applikation.html</link>
		<comments>http://www.welt-held.de/1710-showdialog-verzogert-applikation.html#comments</comments>
		<pubDate>Wed, 10 Mar 2010 21:38:45 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[problem]]></category>
		<category><![CDATA[showdialog]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.welt-held.de/?p=1710</guid>
		<description><![CDATA[Gestern bin ich mal wieder über das selbe Problem wie damals gestoßen. Ich hab es damals nicht weiter erläutert. Und zwar sollte auf Knopfdruck eine Form erscheinen, welche über den ganzen Bildschirm geht, womit der Benutzer interagieren kann. Im Prinzip bestand die Form nur aus einer PictureBox  [...]]]></description>
			<content:encoded><![CDATA[<p>Gestern bin ich mal wieder über das <a href="http://www.welt-held.de/720-showdialog-umbauen.html">selbe Problem</a> wie damals gestoßen. Ich hab es damals nicht weiter erläutert. Und zwar sollte auf Knopfdruck eine Form erscheinen, welche über den ganzen Bildschirm geht, womit der Benutzer interagieren kann. Im Prinzip bestand die Form nur aus einer PictureBox und er sollte dort einen Bereich auswählen.<br />
Lasse ich mir die Form per Show() anzeigen habe ich keine Probleme, per ShowDialog() hängt er jeweils 4 Sekunden (geschätzt).<br />
Diese 4 Sekunden reichen aber dem normalen Benutzer schon aus, um sich darüber zu beschweren.<br />
Gelöst habe ich es wieder einmal mit einem Show() und einen Closed-Event. Zusammen mit TopMost hatte ich den gewünschten Effekt. Erklären kann ich es mir dennoch und vor allem immer noch nicht.</p>
<p>(Wenn Interesse besteht, lade ich mal eine Beispielsolution hoch).</p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.welt-held.de%2F1710-showdialog-verzogert-applikation.html&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://www.welt-held.de/1710-showdialog-verzogert-applikation.html"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.welt-held.de/1710-showdialog-verzogert-applikation.html"  data-text="ShowDialog() verzögert Applikation" data-count="horizontal" data-via="trashar">Tweet</a>
			</div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div> <p><a href="http://welt-held.de/?flattrss_redirect&amp;id=1710&amp;md5=01c3b3c10f968199bdc7a2589cd778cf" title="Flattr" target="_blank"><img src="http://welt-held.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.welt-held.de/1710-showdialog-verzogert-applikation.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="http://welt-held.de/?flattrss_redirect&amp;id=1710&amp;md5=01c3b3c10f968199bdc7a2589cd778cf" type="text/html" />
	</item>
		<item>
		<title>File Transfer Planer &#8211; FTP</title>
		<link>http://www.welt-held.de/1698-file-transfer-planer-ftp.html</link>
		<comments>http://www.welt-held.de/1698-file-transfer-planer-ftp.html#comments</comments>
		<pubDate>Fri, 05 Mar 2010 22:09:54 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[File-Transfer-Planer]]></category>
		<category><![CDATA[Programmierung]]></category>
		<category><![CDATA[ftp]]></category>
		<category><![CDATA[programm]]></category>
		<category><![CDATA[programmieren]]></category>

		<guid isPermaLink="false">http://www.welt-held.de/?p=1698</guid>
		<description><![CDATA[Aktuell arbeite ich an eine kleinen Applikation, welche ich &#8220;File Transfer Planer&#8221; getauft habe. Mit dieser wird es möglich sein, zeitgesteuert Dateien auf einen FTP zu schieben oder eben herunter zu laden.
Das Backend steht zum Teil, einen Teil der GUI ebenfalls, daher mal ein paar Screenshots.
   [...]]]></description>
			<content:encoded><![CDATA[<p>Aktuell arbeite ich an eine kleinen Applikation, welche ich &#8220;File Transfer Planer&#8221; getauft habe. Mit dieser wird es möglich sein, zeitgesteuert Dateien auf einen FTP zu schieben oder eben herunter zu laden.<br />
Das Backend steht zum Teil, einen Teil der GUI ebenfalls, daher mal ein paar Screenshots.</p>
<div style="text-align:center"><a href="http://welt-held.de/files/ftpplaner1.jpg"><img src="http://welt-held.de/files/ftpplaner1-150x150.jpg" alt="" title="File Transfer Planer - Grundeinstellungen" width="150" height="150" class="alignnone size-thumbnail wp-image-1699" /></a> <a href="http://welt-held.de/files/ftpplaner2.jpg"><img src="http://welt-held.de/files/ftpplaner2-150x150.jpg" alt="" title="File Transfer Planer - Task: Zum FTP Verbinden" width="150" height="150" class="alignnone size-thumbnail wp-image-1700" /></a> <a href="http://welt-held.de/files/ftpplaner3.jpg"><img src="http://welt-held.de/files/ftpplaner3-150x150.jpg" alt="" title="File Transfer Planer - Task: Lokales Verzeichnis auswählen" width="150" height="150" class="alignnone size-thumbnail wp-image-1701" /></a></div>
<p>Die GUI ist nicht mehr ganz so aktuell. Aktuell bin ich mir noch nicht so sicher, wie ich die Daten speicher, momentan tendiere ich dazu, die Daten als XML-Datei auf der Platte zu speichern.</p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.welt-held.de%2F1698-file-transfer-planer-ftp.html&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://www.welt-held.de/1698-file-transfer-planer-ftp.html"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.welt-held.de/1698-file-transfer-planer-ftp.html"  data-text="File Transfer Planer &#8211; FTP" data-count="horizontal" data-via="trashar">Tweet</a>
			</div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div> <p><a href="http://welt-held.de/?flattrss_redirect&amp;id=1698&amp;md5=074c321e2fd6f03958c988ca04f12f08" title="Flattr" target="_blank"><img src="http://welt-held.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.welt-held.de/1698-file-transfer-planer-ftp.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="http://welt-held.de/?flattrss_redirect&amp;id=1698&amp;md5=074c321e2fd6f03958c988ca04f12f08" type="text/html" />
	</item>
	</channel>
</rss>

