<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>IgorShare Weblog &#187; Software</title>
	<atom:link href="http://igorshare.wordpress.com/category/software/feed/" rel="self" type="application/rss+xml" />
	<link>http://igorshare.wordpress.com</link>
	<description>Practical Engineering</description>
	<lastBuildDate>Thu, 31 Dec 2009 16:39:30 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='igorshare.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/3e81c82619fe2ddae5ef1340b5d57788?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>IgorShare Weblog &#187; Software</title>
		<link>http://igorshare.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://igorshare.wordpress.com/osd.xml" title="IgorShare Weblog" />
		<item>
		<title>Upcoming Northeast developer events and talks</title>
		<link>http://igorshare.wordpress.com/2008/07/07/upcoming-northeast-developer-events-and-talks/</link>
		<comments>http://igorshare.wordpress.com/2008/07/07/upcoming-northeast-developer-events-and-talks/#comments</comments>
		<pubDate>Tue, 08 Jul 2008 01:40:18 +0000</pubDate>
		<dc:creator>igormoochnick</dc:creator>
				<category><![CDATA[Alt.Net]]></category>
		<category><![CDATA[Community]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Thoughts]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://igorshare.wordpress.com/2008/07/07/upcoming-northeast-developer-events-and-talks/</guid>
		<description><![CDATA[
Hartford, CT CodeCamp &#8211; August 16
I’m planning to bring an agile-development-related presentation. I think it’s a time to start razing a bar for the community’s developer skills level.
Let me know if there are any other requests for the presentations.
I’ve never been to Hatford, CT – what are the favorite places and to-do things there?
For more [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=igorshare.wordpress.com&blog=2434376&post=142&subd=igorshare&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /></p>
<p>Hartford, CT CodeCamp &#8211; August 16</p>
<p>I’m planning to bring an agile-development-related presentation. I think it’s a time to start razing a bar for the community’s developer skills level.</p>
<p>Let me know if there are any other requests for the presentations.</p>
<p>I’ve never been to Hatford, CT – what are the favorite places and to-do things there?</p>
<p>For more Northeast developer events see <a href="http://blogs.msdn.com/cbowen/archive/2008/06/30/upcoming-northeast-developer-events-july.aspx">Chris Bowen’s post</a>.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/igorshare.wordpress.com/142/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/igorshare.wordpress.com/142/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/igorshare.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/igorshare.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/igorshare.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/igorshare.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/igorshare.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/igorshare.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/igorshare.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/igorshare.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/igorshare.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/igorshare.wordpress.com/142/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=igorshare.wordpress.com&blog=2434376&post=142&subd=igorshare&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://igorshare.wordpress.com/2008/07/07/upcoming-northeast-developer-events-and-talks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/96b0fd2825bdeb9f9039b1259156b91b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">IgorM</media:title>
		</media:content>
	</item>
		<item>
		<title>CodeCamp (Waltham, MA) was a great success</title>
		<link>http://igorshare.wordpress.com/2008/04/06/codecamp-waltham-ma-was-a-great-success/</link>
		<comments>http://igorshare.wordpress.com/2008/04/06/codecamp-waltham-ma-was-a-great-success/#comments</comments>
		<pubDate>Mon, 07 Apr 2008 03:44:51 +0000</pubDate>
		<dc:creator>igormoochnick</dc:creator>
				<category><![CDATA[Pash]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Presentations]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Thoughts]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Workflows]]></category>

		<guid isPermaLink="false">http://igorshare.wordpress.com/2008/04/06/codecamp-waltham-ma-was-a-great-success/</guid>
		<description><![CDATA[The last 2 days we had CodeCamp #9 in Waltham. It was a great success &#8211; 555 registered  participants (I swear it was 5 more than allowed 550). A lot of great presentations and presenters. I want personally thank the organizers and the participants.
I&#8217;ve given 4 presentations &#8211; 2 intro sessions and 2 in-depth session. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=igorshare.wordpress.com&blog=2434376&post=117&subd=igorshare&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>The last 2 days we had CodeCamp #9 in Waltham. It was a great success &#8211; 555 registered  participants (I swear it was 5 more than allowed 550). A lot of <a href="http://thedevcommunity.org/Events/PresentationList.aspx?id=6">great presentations and presenters</a>. I want personally thank the organizers and the participants.</p>
<p>I&#8217;ve given 4 presentations &#8211; 2 intro sessions and 2 in-depth session. Audience was great, engaging, friendly and asked a lot of good questions.</p>
<p>You&#8217;re welcome to download the presentations and the source code. Feel free to ask questions over the e-mail.</p>
<ol>
<li><a href="http://igor.moochnick.googlepages.com/CodeCamp_PowerShell.ppsx">PowerShell &#8211; extending your projects with PowerShell &#8220;To Infinity &#8230; and Beyond&#8221;</a> (samples <a href="http://igor.moochnick.googlepages.com/CodeCamp_PoSH_Extend.zip">source code</a>)</li>
<li><a href="http://igor.moochnick.googlepages.com/CodeCamp_Workflows.ppsx">Workflows are &#8230; <em>not only</em> for Business</a> (samples <a href="http://igor.moochnick.googlepages.com/CodeCamp_Workflows.zip">source code</a>)</li>
</ol>
<p>I hope to see all of you next CodeCamp or during User Group meetings.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/igorshare.wordpress.com/117/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/igorshare.wordpress.com/117/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/igorshare.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/igorshare.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/igorshare.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/igorshare.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/igorshare.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/igorshare.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/igorshare.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/igorshare.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/igorshare.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/igorshare.wordpress.com/117/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=igorshare.wordpress.com&blog=2434376&post=117&subd=igorshare&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://igorshare.wordpress.com/2008/04/06/codecamp-waltham-ma-was-a-great-success/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/96b0fd2825bdeb9f9039b1259156b91b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">IgorM</media:title>
		</media:content>
	</item>
		<item>
		<title>Pash &#8211; cross platform PowerShell is out in the wild! Announcement.</title>
		<link>http://igorshare.wordpress.com/2008/04/06/pash-cross-platform-powershell-is-out-in-the-wild-announcement/</link>
		<comments>http://igorshare.wordpress.com/2008/04/06/pash-cross-platform-powershell-is-out-in-the-wild-announcement/#comments</comments>
		<pubDate>Mon, 07 Apr 2008 01:13:07 +0000</pubDate>
		<dc:creator>igormoochnick</dc:creator>
				<category><![CDATA[Pash]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://igorshare.wordpress.com/2008/04/06/pash-cross-platform-powershell-is-out-in-the-wild-announcement/</guid>
		<description><![CDATA[
Pash &#8211; http://pash.sourceforge.net/
PowerShell open source reimplementation for &#8220;others&#8221; (Mac, Linux, Solaris, etc&#8230;) and Windows (including Windows Mobile and Windows CE)
About the name
Pash = PoSH (PowerShell) + bash (one of the Unix shells)
Goals
The main goal is to provide a rich shell environment for other operating systems as well as to provide a hostable scripting engine for [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=igorshare.wordpress.com&blog=2434376&post=116&subd=igorshare&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><h3>
<p>Pash &#8211; <a href="http://pash.sourceforge.net/">http://pash.sourceforge.net/</a></h3>
<p>PowerShell open source reimplementation for &#8220;others&#8221; (Mac, Linux, Solaris, etc&#8230;) and Windows (including Windows Mobile and Windows CE)<br />
<h2>About the name</h2>
<p>Pash = PoSH (PowerShell) + bash (one of the Unix shells)<br />
<h2>Goals</h2>
<p>The main goal is to provide a rich shell environment for other operating systems as well as to provide a hostable scripting engine for rich applications. The user experience should be seamless for people who are used to Windows version of PowerShell. The scrips, cmdlets and providers should runs AS-IS (<strong><u>if they are not using Windows-specific functionality</u></strong>). The rich applications that host PowerShell should run on any other operating system AS-IS. Secondary goal: the scripts should run across the machines and different OS&#8217;s seamlesly (but following all the security guidelines).<br />
<h2>Environment</h2>
<p>The current implementation of Pash is written using pure .Net 2.0. It compiles on VS 2008 as well as on Mono. So all the developers can choose the environment that fits their needs and preferences. The produced assemblies can be executed &#8220;right out of the box&#8221; on Windows, <a href="http://www.go-mono.com/mono-downloads/download.html">Linux, Mac (or others)</a> without any additional recompilation. <b>Note:</b> for Windows Mobile and Windows CE the produced code should be recompiled against the .NET Compact Framework.<br />
<h2>Progress</h2>
<p>You&#8217;re welcome to get the source code and contribute to the Pash public effort @ <a title="http://sourceforge.net/projects/pash" href="http://sourceforge.net/projects/pash">http://sourceforge.net/projects/pash</a>.
<p>~50% of public PowerShell classes defined.
<p>~40% of framework functionality operational.
<p>Stay tuned for more detailed info. Trying to figure out how to produce the similar class <a href="http://www.mono-project.com/Generating_class_status_pages">diff that Mono project is using</a>.<br />
<h2>Screenshots</h2>
<h3>Windows (duh !..)</h3>
<h3><img src="http://pash.sourceforge.net/images/windows.png"> </h3>
<h3>Pash on Mono + SuSE Linux</h3>
<p><img src="http://pash.sourceforge.net/images/linux_suse.png"> </p>
<h3>Pash on Compact .NET Framework</h3>
<p><img src="http://pash.sourceforge.net/images/windows_mobile.png"> </p>
<h3>and (drum roll &#8230;) Pash on Mac</h3>
<p><img src="http://pash.sourceforge.net/images/mac_mono.png"> </p>
<hr />
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/igorshare.wordpress.com/116/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/igorshare.wordpress.com/116/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/igorshare.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/igorshare.wordpress.com/116/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/igorshare.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/igorshare.wordpress.com/116/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/igorshare.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/igorshare.wordpress.com/116/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/igorshare.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/igorshare.wordpress.com/116/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/igorshare.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/igorshare.wordpress.com/116/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=igorshare.wordpress.com&blog=2434376&post=116&subd=igorshare&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://igorshare.wordpress.com/2008/04/06/pash-cross-platform-powershell-is-out-in-the-wild-announcement/feed/</wfw:commentRss>
		<slash:comments>44</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/96b0fd2825bdeb9f9039b1259156b91b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">IgorM</media:title>
		</media:content>

		<media:content url="http://pash.sourceforge.net/images/windows.png" medium="image" />

		<media:content url="http://pash.sourceforge.net/images/linux_suse.png" medium="image" />

		<media:content url="http://pash.sourceforge.net/images/windows_mobile.png" medium="image" />

		<media:content url="http://pash.sourceforge.net/images/mac_mono.png" medium="image" />
	</item>
		<item>
		<title>Custom Event Log trace listener/writer</title>
		<link>http://igorshare.wordpress.com/2008/02/05/custom-event-log-trace-listenerwriter/</link>
		<comments>http://igorshare.wordpress.com/2008/02/05/custom-event-log-trace-listenerwriter/#comments</comments>
		<pubDate>Tue, 05 Feb 2008 19:05:03 +0000</pubDate>
		<dc:creator>igormoochnick</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://igorshare.wordpress.com/2008/02/05/custom-event-log-trace-listenerwriter/</guid>
		<description><![CDATA[Ever wanted to route a bunch of your trace events to an event log for IT administrator to see? In .NET you can do this without even changing a single line of your code. I&#8217;m sure a lot of you already seen the default event trace listener, but, if you used it you&#8217;ve noticed, it [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=igorshare.wordpress.com&blog=2434376&post=77&subd=igorshare&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Ever wanted to route a bunch of your trace events to an event log for IT administrator to see? In .NET you can do this without even changing a single line of your code. I&#8217;m sure a lot of you already seen the default event trace listener, but, if you used it you&#8217;ve noticed, it doesn&#8217;t allow you much control of how and where these events are landed. In my project I needed such control to tell what events, to what event log and with what event source they&#8217;ll find their way in. So, to do this, I needed a new EventLogListenerEx (see the code below). This new EventLogListenrEx can be put easily into your configuration by the standard means:</p>
<div>
<div style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   1:</span> <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">sharedListeners</span><span style="color:#0000ff;">&gt;</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   2:</span>   <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">add</span> <span style="color:#ff0000;">name</span><span style="color:#0000ff;">="eventLogListener"</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="Yosemite.Utilities.EventLogListenerEx,Yosemite.Utilities"</span> </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   3:</span>        <span style="color:#ff0000;">initializeData</span><span style="color:#0000ff;">="Log=Application;Source=MyServer"</span><span style="color:#0000ff;">&gt;</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   4:</span>     <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">filter</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="System.Diagnostics.EventTypeFilter"</span> <span style="color:#ff0000;">initializeData</span><span style="color:#0000ff;">="Warning"</span> <span style="color:#0000ff;">/&gt;</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   5:</span>   <span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">add</span><span style="color:#0000ff;">&gt;</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   6:</span> <span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">sharedListeners</span><span style="color:#0000ff;">&gt;</span></pre>
</div>
</div>
<p> </p>
<p> Note the &#8220;initializeData&#8221; attribute &#8211; it allows you to control to what Log and with what Source the events will be routed. This new event listener will create a new event source on demand if it&#8217;ll not find one, but, of cause, it should have enough privileges to do so. BTW: you can always create a required event source when needed from a stand-alone command line tool where you can have as much privileges as needed. </p>
<p> Enjoy!</p>
<p><pre class="brush: csharp;">
    public class EventLogListenerEx : TraceListener
    {
        private string _EventLogName = &quot;Application&quot;;
        private string _EventLogSource = &quot;Application&quot;;
        private string _EventLogType = &quot;Information&quot;;
        private EventLog _eventLog;
        private EventLogEntryType _logType;

        public EventLogListenerEx(string logType)
            : base()
        {
            System.Diagnostics.Trace.WriteLine(&quot;Event log processing&quot;);

            try
            {
                string[] parts = logType.Split(';');

                foreach (string part in parts)
                {
                    string[] settings = part.Split('=');

                    if (settings[0].ToLower() == &quot;log&quot;)
                    {
                        _EventLogName = settings[1];
                    }
                    else if (settings[0].ToLower() == &quot;source&quot;)
                    {
                        _EventLogSource = settings[1];
                    }
                    else if (settings[0].ToLower() == &quot;type&quot;)
                    {
                        _EventLogType = settings[1];
                    }
                }

                _eventLog = new EventLog(_EventLogName);
                bool bRet = false;
                try
                {
                    bRet = EventLog.SourceExists(_EventLogSource);
                }
                catch (SecurityException)
                {
                    System.Diagnostics.Trace.WriteLine(&quot;Not enough credentials to create an event source - switching to Application.&quot;);
                    bRet = true;
                    _EventLogSource = &quot;Application&quot;;
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Trace.WriteLine(&quot;Unexpected exception while checking for an event source: &quot; + ex.ToString());
                    bRet = true;
                    _EventLogSource = &quot;Application&quot;;
                }
                if (! bRet)
                {
                    try
                    {
                        EventLog.CreateEventSource(_EventLogSource, _EventLogName);
                    }
                    catch (SecurityException)
                    {
                        System.Diagnostics.Trace.WriteLine(&quot;Not enough credentials to create an event source - switching to Application.&quot;);
                        _EventLogSource = &quot;Application&quot;;
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Trace.WriteLine(&quot;Unexpected exception while creating an event source: &quot; + ex.ToString());
                        _EventLogSource = &quot;Application&quot;;
                    }
                }

                _eventLog.Source = _EventLogSource;
                _logType = (EventLogEntryType)Enum.Parse(typeof(EventLogEntryType), _EventLogType);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.ToString());

                throw;
            }
        }

        public override void Write(string message)
        {
            string str = message.Trim();

            // Just in case - we'll log the event if it's not a Trace header
            if (str[str.Length - 1] != ':')
            {
                WriteLine(str);
            }
        }

        public override void WriteLine(string message)
        {
            _eventLog.WriteEntry(message, _logType);
        }
    }
</pre></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/igorshare.wordpress.com/77/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/igorshare.wordpress.com/77/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/igorshare.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/igorshare.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/igorshare.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/igorshare.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/igorshare.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/igorshare.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/igorshare.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/igorshare.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/igorshare.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/igorshare.wordpress.com/77/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=igorshare.wordpress.com&blog=2434376&post=77&subd=igorshare&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://igorshare.wordpress.com/2008/02/05/custom-event-log-trace-listenerwriter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/96b0fd2825bdeb9f9039b1259156b91b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">IgorM</media:title>
		</media:content>
	</item>
		<item>
		<title>Did you know: using ToLower on a Unicode text can cause a security problem?</title>
		<link>http://igorshare.wordpress.com/2008/01/26/did-you-know-using-tolower-on-a-unicode-text-can-cause-a-security-problem/</link>
		<comments>http://igorshare.wordpress.com/2008/01/26/did-you-know-using-tolower-on-a-unicode-text-can-cause-a-security-problem/#comments</comments>
		<pubDate>Sat, 26 Jan 2008 06:28:37 +0000</pubDate>
		<dc:creator>igormoochnick</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Thoughts]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://igorshare.wordpress.com/2008/01/26/did-you-know-using-tolower-on-a-unicode-text-can-cause-a-security-problem/</guid>
		<description><![CDATA[Recently watched the latest DnrTV show #97 (love them!) with Kathleen Dollard (check her blog Leaning Into Windows). Great show! Kathleen went through a lot of things that are rarely used in the day-to-day projects but, if overlooked, can cause a serious problem and put the whole project/product at risk. Here are 2 that are [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=igorshare.wordpress.com&blog=2434376&post=70&subd=igorshare&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a href="http://dnrtv.com/default.aspx?showID=97"><img style="margin:5px 20px 5px 5px;" src="http://www.intellectualhedonism.com/content/binary/dnrtv.jpg" align="left" border="0"></a>Recently watched the latest <a href="http://dnrtv.com/default.aspx?showID=97">DnrTV show #97</a> (love them!) with Kathleen Dollard (check her blog <a href="http://msmvps.com/blogs/kathleen/">Leaning Into Windows</a>). <a href="http://msmvps.com/blogs/kathleen/archive/2008/01/18/dnr-tv-on-net-3-5-languages-part-1-posted.aspx">Great show</a>! Kathleen went through a lot of things that are rarely used in the day-to-day projects but, if overlooked, can cause a serious problem and put the whole project/product at risk. Here are 2 that are really worth remembering:</p>
<p>1. In a product that works with Unicode strings (Localized) and do a lot of string comparisons, it&#8217;s better to use ToUpper than ToLower. ToUpper will not work correctly for a couple of languages, but ToLower, not only fail for more languages, but, also, can expose a bunch of security problems within Unicode implementation.</p>
<p>2. Do not write ANY code that changes variables in a partial method call. If a partial method implementation will be removed &#8211; such code will be removed as well and will cause an unpredictable result. To understand this check out the following code snippet:</p>
<div>
<div style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   1:</span> <span style="color:#0000ff;">partial</span> <span style="color:#0000ff;">void</span> PrintNum(<span style="color:#0000ff;">int</span> n);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   2:</span>&nbsp; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   3:</span> <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">int</span> AddWithIncrement(<span style="color:#0000ff;">int</span> a, <span style="color:#0000ff;">int</span> b)</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   4:</span> {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   5:</span>    PrintNum(a++);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   6:</span>    <span style="color:#0000ff;">return</span> a+b;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   7:</span> }</pre>
</div>
</div>
<p>&nbsp;</p>
<p>Let&#8217;s say that a=1 and b=2. If the PrintNum method will have a declaration, then the AddWithIncrement function will return 4. On the other hand, if the declaration of PrintNum will be removed, the compiler will remove (ignore) the whole line #5 (PrintNum(a++)), hence the a++ will not be executed and AddWithIncrement function will return 3.</p>
<p>So, be careful, you have been warned!</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/igorshare.wordpress.com/70/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/igorshare.wordpress.com/70/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/igorshare.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/igorshare.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/igorshare.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/igorshare.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/igorshare.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/igorshare.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/igorshare.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/igorshare.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/igorshare.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/igorshare.wordpress.com/70/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=igorshare.wordpress.com&blog=2434376&post=70&subd=igorshare&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://igorshare.wordpress.com/2008/01/26/did-you-know-using-tolower-on-a-unicode-text-can-cause-a-security-problem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/96b0fd2825bdeb9f9039b1259156b91b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">IgorM</media:title>
		</media:content>

		<media:content url="http://www.intellectualhedonism.com/content/binary/dnrtv.jpg" medium="image" />
	</item>
		<item>
		<title>.NET Source Code is available for public</title>
		<link>http://igorshare.wordpress.com/2008/01/17/net-source-code-is-available-for-public/</link>
		<comments>http://igorshare.wordpress.com/2008/01/17/net-source-code-is-available-for-public/#comments</comments>
		<pubDate>Thu, 17 Jan 2008 15:58:27 +0000</pubDate>
		<dc:creator>igormoochnick</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://igorshare.wordpress.com/2008/01/17/net-source-code-is-available-for-public/</guid>
		<description><![CDATA[You can find all the details of how to configure your Visual Studio in a detailed Shawn Burke&#8217;s article. It looks like the WPF source can be in there too according to Bart hints on his B#.NET blog.
       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=igorshare.wordpress.com&blog=2434376&post=67&subd=igorshare&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>You can find all the details of how to configure your Visual Studio in a <a href="http://blogs.msdn.com/sburke/archive/2008/01/16/configuring-visual-studio-to-debug-net-framework-source-code.aspx">detailed Shawn Burke&#8217;s article</a>. It looks like the WPF source can be in there too according to <a href="http://bartdesmet.net/blogs/bart/archive/2008/01/16/net-framework-library-source-code-now-available.aspx">Bart hints</a> on his B#.NET blog.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/igorshare.wordpress.com/67/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/igorshare.wordpress.com/67/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/igorshare.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/igorshare.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/igorshare.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/igorshare.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/igorshare.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/igorshare.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/igorshare.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/igorshare.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/igorshare.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/igorshare.wordpress.com/67/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=igorshare.wordpress.com&blog=2434376&post=67&subd=igorshare&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://igorshare.wordpress.com/2008/01/17/net-source-code-is-available-for-public/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/96b0fd2825bdeb9f9039b1259156b91b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">IgorM</media:title>
		</media:content>
	</item>
		<item>
		<title>Free Silverlight training at Lynda.com</title>
		<link>http://igorshare.wordpress.com/2008/01/12/free-silverlight-training-at-lyndacom/</link>
		<comments>http://igorshare.wordpress.com/2008/01/12/free-silverlight-training-at-lyndacom/#comments</comments>
		<pubDate>Sat, 12 Jan 2008 03:26:00 +0000</pubDate>
		<dc:creator>igormoochnick</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://igorshare.wordpress.com/2008/01/12/free-silverlight-training-at-lyndacom/</guid>
		<description><![CDATA[Thanks to Mike Taulty&#8217;s post, I can add yet another great training video collection to my library &#8211; Silverlight Essential Training on Lynda.com.
I&#8217;ve already pointed your attention to Lynda.com&#8217;s free WPF training videos in one of my previous posts, so keep an eye on evergrowing great training resource.
       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=igorshare.wordpress.com&blog=2434376&post=65&subd=igorshare&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a href="http://movielibrary.lynda.com/"><img style="margin:5px 20px 5px 5px;" height="88" alt="lynda.com" src="http://movielibrary.lynda.com/assets/shared/images/ui/nav/logo.gif" width="90" align="left" border="0"></a>Thanks to <a href="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2007/11/21/9959.aspx">Mike Taulty&#8217;s post</a>, I can add yet another great training video collection to my library &#8211; <a href="http://movielibrary.lynda.com/html/modPage.asp?ID=473">Silverlight Essential Training</a> on Lynda.com.</p>
<p>I&#8217;ve already pointed your attention to Lynda.com&#8217;s free <a href="http://movielibrary.lynda.com/html/modPage.asp?ID=384">WPF training videos</a> in one of my <a href="http://igorshare.wordpress.com/2007/12/31/wpf-training-video-library/">previous posts</a>, so keep an eye on evergrowing great training resource.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/igorshare.wordpress.com/65/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/igorshare.wordpress.com/65/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/igorshare.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/igorshare.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/igorshare.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/igorshare.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/igorshare.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/igorshare.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/igorshare.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/igorshare.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/igorshare.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/igorshare.wordpress.com/65/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=igorshare.wordpress.com&blog=2434376&post=65&subd=igorshare&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://igorshare.wordpress.com/2008/01/12/free-silverlight-training-at-lyndacom/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/96b0fd2825bdeb9f9039b1259156b91b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">IgorM</media:title>
		</media:content>

		<media:content url="http://movielibrary.lynda.com/assets/shared/images/ui/nav/logo.gif" medium="image">
			<media:title type="html">lynda.com</media:title>
		</media:content>
	</item>
		<item>
		<title>CodeDom extensions and dynamic LINQ (string/script to LINQ emitting)</title>
		<link>http://igorshare.wordpress.com/2008/01/11/codedom-extensions-and-dynamic-linq-stringscript-to-linq-emitting/</link>
		<comments>http://igorshare.wordpress.com/2008/01/11/codedom-extensions-and-dynamic-linq-stringscript-to-linq-emitting/#comments</comments>
		<pubDate>Fri, 11 Jan 2008 07:53:18 +0000</pubDate>
		<dc:creator>igormoochnick</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://igorshare.wordpress.com/2008/01/11/codedom-extensions-and-dynamic-linq-stringscript-to-linq-emitting/</guid>
		<description><![CDATA[Ah&#8230; Don&#8217;t you like these method extensions?!!!
Recently I&#8217;ve developed a certain taste for method extensions. They allow to create shorter code, but you should always keep in your head the dangers of such freedom &#8211; code can become complicated and unnatural. On the other hand, new set of extensions, it&#8217;s like to learn a new [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=igorshare.wordpress.com&blog=2434376&post=63&subd=igorshare&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p align="justify">Ah&#8230; Don&#8217;t you like these method extensions?!!!</p>
<p align="justify">Recently I&#8217;ve developed a certain taste for method extensions. They allow to create shorter code, but you should always keep in your head the dangers of such freedom &#8211; code can become complicated and unnatural. On the other hand, new set of extensions, it&#8217;s like to learn a new language, new classes, new techniques. So, currently, I have a mixed feeling &#8211; great thing, but not for free (some overhead attached).</p>
<p align="justify">In my previous post (<a href="http://igorshare.wordpress.com/2008/01/09/intellisense-like-method-selection-pop-up-window/">Intellisense-like method selection pop-up window</a>) I&#8217;ve shown how to create a LINQ editor (or any editor of your choice). You can ask &#8211; what&#8217;s the point of such script? What can we do with it?</p>
<p align="justify">.NET answer &#8211; the sky is your limit. The .NET framework allows you dynamically convert any string (correctly formatted) into a code and immediately execute it. You can do this in-memory, in-file, from-file, to-file, from-string, to-string, and any other combination of your choice.</p>
<p align="justify">Here are a couple of example of what you can do with a correctly formatted string:</p>
<ol>
<li>
<div align="justify">Generate a full code file</div>
</li>
<li>
<div align="justify">Generate an assembly in-memory</div>
</li>
<li>
<div align="justify">Create an assembly in file for future use</div>
</li>
<li>
<div align="justify">etc &#8230;</div>
</li>
</ol>
<p align="justify">As well you have a wide choice of code providers:</p>
<ol>
<li>
<div align="justify">C#</div>
</li>
<li>
<div align="justify">VB.NET</div>
</li>
<li>
<div align="justify">C++</div>
</li>
<li>
<div align="justify">JavaScript</div>
</li>
<li>
<div align="justify">and any other code provider that is installed on your machine and inherits from System.CodeDom.Compiler.CodeDomProvider class.</div>
</li>
</ol>
<p align="justify">To simplify the use of CodeDom (it requires a wide knowledge of how the build process works), I&#8217;ve created a very basic library that extends CodeDom functionality and provides a nice and slick way of generating code-on-the-fly. Here are a couple of small examples, before we&#8217;ll dive into how it&#8217;s done (find them in the attached test project):</p>
<p align="justify"><strong>A) The following snippet prints Hello World! to the console:</strong></p>
<div align="justify">
<div style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   1:</span> var c = <span style="color:#0000ff;">new</span> CodeDom();</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   2:</span> c.AddNamespace(<span style="color:#006080;">"Samples"</span>).Imports(<span style="color:#006080;">"System"</span>)</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   3:</span>     .AddClass(</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   4:</span>       c.Class(<span style="color:#006080;">"TestClass"</span>)</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   5:</span>         .AddMethod(c.Method(<span style="color:#006080;">"Print"</span>, <span style="color:#006080;">"Console.WriteLine(\"Hello World\");"</span>)));</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   6:</span> </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   7:</span> var methodPrint = c.Compile().GetType(<span style="color:#006080;">"Samples.TestClass"</span>).GetMethod(<span style="color:#006080;">"Print"</span>);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   8:</span> methodPrint.Invoke();</pre>
</div>
</div>
<p align="justify"><strong>B) And here is the example of how to call a function with parametes (it&#8217;ll add 2 numbers):</strong></p>
<div align="justify">
<div style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   1:</span> var c = <span style="color:#0000ff;">new</span> CodeDom();</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   2:</span> c.AddNamespace(<span style="color:#006080;">"Samples"</span>).Imports(<span style="color:#006080;">"System"</span>)</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   3:</span>     .AddClass(</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   4:</span>       c.Class(<span style="color:#006080;">"TestClass"</span>)</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   5:</span>         .AddMethod(c.Method(<span style="color:#006080;">"int"</span>, <span style="color:#006080;">"AddNumbers"</span>, <span style="color:#006080;">"int a, int b"</span>, <span style="color:#006080;">"return a + b;"</span>)));</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   6:</span> </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   7:</span> var methodAddNumbers = c.Compile().GetType(<span style="color:#006080;">"Samples.TestClass"</span>).GetMethod(<span style="color:#006080;">"AddNumbers"</span>);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   8:</span> <span style="color:#0000ff;">int</span> retVal = Converter.To&lt;<span style="color:#0000ff;">int</span>&gt;(methodAddNumbers.Invoke(2, 3), 0);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   9:</span> // retVal = 5</pre>
</div>
</div>
<p align="justify"><strong>C) and here is the BEST &#8211; dynamic LINQ (compiled and executed in memory):</strong></p>
<div align="justify">
<div style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   1:</span> var c = <span style="color:#0000ff;">new</span> CodeDom();</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   2:</span> c.AddReference(<span style="color:#006080;">@"System.Core.dll"</span>)</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   3:</span>     .AddNamespace(<span style="color:#006080;">"Samples"</span>)</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   4:</span>     .Imports(<span style="color:#006080;">"System.Collections.Generic"</span>)</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   5:</span>     .Imports(<span style="color:#006080;">"System.Linq"</span>)</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   6:</span>     .AddClass(</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   7:</span>       c.Class(<span style="color:#006080;">"TestClass"</span>)</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   8:</span>         .AddMethod(c.Method(<span style="color:#006080;">"IEnumerable&lt;string&gt;"</span>, <span style="color:#006080;">"FilterCollection"</span>, <span style="color:#006080;">"IEnumerable&lt;string&gt; items"</span>,</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   9:</span>              <span style="color:#006080;">"return from item in items where item.StartsWith(\"a\") select item; "</span>)));</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  10:</span> </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  11:</span> var method = c.Compile().GetType(<span style="color:#006080;">"Samples.TestClass"</span>).GetMethod(<span style="color:#006080;">"FilterCollection"</span>);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  12:</span> </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  13:</span> var items = <span style="color:#0000ff;">new</span> List&lt;<span style="color:#0000ff;">string</span>&gt;() { <span style="color:#006080;">"apple"</span>, <span style="color:#006080;">"banana"</span>, <span style="color:#006080;">"ananas"</span>, <span style="color:#006080;">"mango"</span> };</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  14:</span> IEnumerable&lt;<span style="color:#0000ff;">string</span>&gt; retVal = (IEnumerable&lt;<span style="color:#0000ff;">string</span>&gt;)method.Invoke(items);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  15:</span> // retVal contains: <span style="color:#006080;">"apple"</span>, <span style="color:#006080;">"ananas"</span></pre>
</div>
</div>
<p align="justify">Obviously you can start mix and match these extensions and create more namespaces, classes with more methods, etc &#8230; I don&#8217;t want to get too much into the details (see attached test project for more samples), but rather I want to tell how it works.</p>
<p align="justify"><strong>NOTE:</strong> Yes, I know about the Dynamic LINQ library and I&#8217;ve read ScottGu&#8217;s blog <a href="http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx">article</a>, but, so far, I&#8217;ve seen only that you can create filters with this technique. It is using tokenized parser behind the scenes and reflects expression tree based on the results. This has somewhat limited functionality and can&#8217;t emit expression tree solely based on a string LINQ query. May be in the future it&#8217;ll be expanded, but, at this moment, my solution is the only way to convert LINQ string to an executable code.</p>
<p align="justify">Extension methods are the key. CodeDom class just provides a set of factories to create the CodeDom classes like CompileUnit, CodeTypeDeclaration, CodeSnippetTypeMember, etc&#8230; It collects all the namespaces, referenced assemblies, constructed code and, at the end, it allows you to decide what is a final product of your actions. The beauty of the code ensured by the extension methods.</p>
<p align="justify">I will not go too much into details of how to create extension methods themselves (a lot of information can be found on the net), but rather talk about the most important one: Method.Invoke.</p>
<div align="justify">
<div style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   1:</span> <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">static</span> <span style="color:#0000ff;">object</span> Invoke(<span style="color:#0000ff;">this</span> MethodInfo methodInfo, <span style="color:#0000ff;">params</span> <span style="color:#0000ff;">object</span>[] parameters)</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   2:</span> {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   3:</span>     <span style="color:#0000ff;">return</span> methodInfo.Invoke(<span style="color:#0000ff;">null</span>, parameters);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   4:</span> }</pre>
</div>
</div>
<p align="justify">This extension method makes the constructs like &#8220;method.Invoke()&#8221; and &#8220;method.Invoke(2, 3)&#8221; possible. It hides the complexity of the reflection from the users and allows him to use the newly constructed method as if it&#8217;s a real method of the application.</p>
<p align="justify">At the end I want to mention, yet another, beauty of .NET &#8211; dynamic type converter. Such converter allows you to  take control over your untyped objects without second-guessing your type conversion assumptions and skipping all the error check logic. I&#8217;ve used such technique very extensively with untyped DataSets in all my middle tier applications (I&#8217;ll be posting about it soon). For example, Method.Invoke always returns an object. If you want to use the returned value as a strongly typed object &#8211; you have to cast it to the required type either by &#8220;()&#8221; or &#8220;as&#8221; constructs. Then you need to check for a &#8220;null&#8221; or an exception. In my case you can do something like this:</p>
<div>
<div style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   1:</span> <span style="color:#0000ff;">int</span> retVal = Converter.To&lt;<span style="color:#0000ff;">int</span>&gt;(methodAddNumbers.Invoke(2, 3), 0);</pre>
</div>
</div>
<p>Note the last &#8220;0&#8243; in the converter&#8217;s call &#8211; this is a default value that will be returned in case the conversion has failed. This is how it works:</p>
<div>
<div style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   1:</span> <span style="color:#008000;">/// &lt;summary&gt;</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   2:</span> <span style="color:#008000;">/// Converts from "object" general type to a concrete type</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   3:</span> <span style="color:#008000;">/// &lt;/summary&gt;</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   4:</span> <span style="color:#008000;">/// &lt;remarks&gt;</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   5:</span> <span style="color:#008000;">/// The class is working with .Net 2.0 and above</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   6:</span> <span style="color:#008000;">/// &lt;/remarks&gt;</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   7:</span> <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> Converter</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   8:</span> {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   9:</span>     <span style="color:#008000;">/// &lt;summary&gt;</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  10:</span>     <span style="color:#008000;">/// Returns True if the type can get Null as a value (is a reference type and not a value one)</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  11:</span>     <span style="color:#008000;">/// &lt;/summary&gt;</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  12:</span>     <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">static</span> <span style="color:#0000ff;">bool</span> IsNullable(Type t)</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  13:</span>     {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  14:</span>         <span style="color:#0000ff;">if</span> (!t.IsGenericType) <span style="color:#0000ff;">return</span> <span style="color:#0000ff;">false</span>;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  15:</span>         Type g = t.GetGenericTypeDefinition();</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  16:</span>         <span style="color:#0000ff;">return</span> (g.Equals(<span style="color:#0000ff;">typeof</span>(Nullable&lt;&gt;)));</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  17:</span>     }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  18:</span> </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  19:</span>     <span style="color:#008000;">/// &lt;summary&gt;</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  20:</span>     <span style="color:#008000;">/// Returns a real type of a first generic argument</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  21:</span>     <span style="color:#008000;">/// &lt;/summary&gt;</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  22:</span>     <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">static</span> Type UnderlyingTypeOf(Type t)</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  23:</span>     {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  24:</span>         <span style="color:#0000ff;">return</span> t.GetGenericArguments()[0];</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  25:</span>     }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  26:</span> </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  27:</span>     <span style="color:#008000;">/// &lt;summary&gt;</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  28:</span>     <span style="color:#008000;">/// Converter</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  29:</span>     <span style="color:#008000;">/// &lt;/summary&gt;</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  30:</span>     <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">static</span> T To&lt;T&gt;(<span style="color:#0000ff;">object</span> <span style="color:#0000ff;">value</span>, T defaultValue)</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  31:</span>     {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  32:</span>         <span style="color:#0000ff;">if</span> (<span style="color:#0000ff;">value</span> == DBNull.Value) <span style="color:#0000ff;">return</span> defaultValue;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  33:</span>         Type t = <span style="color:#0000ff;">typeof</span>(T);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  34:</span>         <span style="color:#0000ff;">if</span> (IsNullable(t))</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  35:</span>         {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  36:</span>             <span style="color:#0000ff;">if</span> (<span style="color:#0000ff;">value</span> == <span style="color:#0000ff;">null</span>) <span style="color:#0000ff;">return</span> <span style="color:#0000ff;">default</span>(T);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  37:</span>             t = UnderlyingTypeOf(t);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  38:</span>         }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  39:</span>         <span style="color:#0000ff;">else</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  40:</span>         {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  41:</span>             <span style="color:#0000ff;">if</span> ((<span style="color:#0000ff;">value</span> == <span style="color:#0000ff;">null</span>) &amp;&amp; (t.IsValueType))</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  42:</span>             {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  43:</span>                 <span style="color:#0000ff;">return</span> defaultValue;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  44:</span>             }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  45:</span>         }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  46:</span> </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  47:</span>         <span style="color:#0000ff;">return</span> (T)Convert.ChangeType(<span style="color:#0000ff;">value</span>, t);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  48:</span>     }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  49:</span> }</pre>
</div>
</div>
<p>I&#8217;ll be talking about this converter in more detail in the future posts, so stay tuned &#8230;</p>
<p>The full <a href="http://igor.moochnick.googlepages.com/CodeDomExtender.zip">source code with tests/examples</a> you can find as usual on my web site: <a href="http://igor.moochnick.googlepages.com">http://igor.moochnick.googlepages.com</a>.</p>
<p><strong>DISCLAMER:</strong> The provided libraries are a work in progress and do not contain 100% wrapped CodeDom. There are a lot of things that can be added to make the whole user experience easier. You are welcome to use them AS-IS and to extend them to any degree you with. You&#8217;re welcome to send me your updates and I&#8217;ll be more than happy to post them for everybody else to use.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/igorshare.wordpress.com/63/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/igorshare.wordpress.com/63/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/igorshare.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/igorshare.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/igorshare.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/igorshare.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/igorshare.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/igorshare.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/igorshare.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/igorshare.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/igorshare.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/igorshare.wordpress.com/63/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=igorshare.wordpress.com&blog=2434376&post=63&subd=igorshare&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://igorshare.wordpress.com/2008/01/11/codedom-extensions-and-dynamic-linq-stringscript-to-linq-emitting/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/96b0fd2825bdeb9f9039b1259156b91b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">IgorM</media:title>
		</media:content>
	</item>
		<item>
		<title>Intellisense-like method selection pop-up window</title>
		<link>http://igorshare.wordpress.com/2008/01/09/intellisense-like-method-selection-pop-up-window/</link>
		<comments>http://igorshare.wordpress.com/2008/01/09/intellisense-like-method-selection-pop-up-window/#comments</comments>
		<pubDate>Wed, 09 Jan 2008 17:31:54 +0000</pubDate>
		<dc:creator>igormoochnick</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://igorshare.wordpress.com/2008/01/09/intellisense-like-method-selection-pop-up-window/</guid>
		<description><![CDATA[Today the intellisense becomes a must in a whole range of different applications. Applications becomes smarter due to this enormous unharvested CPU power that is idling on your desktops and the applications find a way to use it.
The technique, I&#8217;m going to explain here, is a user-friendly way to hint or help user with their [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=igorshare.wordpress.com&blog=2434376&post=61&subd=igorshare&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p align="justify">Today the intellisense becomes a must in a whole range of different applications. Applications becomes smarter due to this enormous unharvested CPU power that is idling on your desktops and the applications find a way to use it.</p>
<p align="justify">The technique, I&#8217;m going to explain here, is a user-friendly way to hint or help user with their next actions while he works on his primary task. For example:</p>
<ol>
<li>
<div align="justify">user types a text, a spell checker (which is at your fingertips in WPF) finds the misspelled words and the application can suggest the user a choice</div>
<li>
<div align="justify">user types a script and the application let&#8217;s the user to choice a next command from a list of possibilities</div>
<li>
<div align="justify">etc&#8230;</div>
</li>
</ol>
<p align="justify"><a href="http://igorshare.files.wordpress.com/2008/01/clip-image0012.png"></a>&nbsp;</p>
<p align="justify">We can go with the list, but, I hope, you got the idea. In my case, I&#8217;ll show you how help the user construct a LINQ query.</p>
<p align="justify"><a href="http://igorshare.files.wordpress.com/2008/01/clip-image0012.png"><img style="border-right:0;border-top:0;border-left:0;border-bottom:0;margin:5px 5px 5px 20px;" height="152" alt="clip_image001" src="http://igorshare.files.wordpress.com/2008/01/clip-image001-thumb1.png?w=274&#038;h=152" width="274" border="0"></a></p>
<p align="justify">To make the explanation short and to the point, let&#8217;s scope the problem: the application will show a pop-up only when he types a predefined keyword and presses a &#8220;.&#8221; (dot). The popup will contain a list of possible methods that can be applied to the object.</p>
<p align="justify">Let&#8217;s create a class that will provide a list of item&#8217;s methods. Let&#8217;s say that item is of type SyndicationItem. So we&#8217;ll use reflection methods (if you don&#8217;t know what reflections it &#8211; you should look into it, it&#8217;s very useful in a whole range of applications) to find all the methods of the SyndicationItem type. You can use a &#8220;.GetType()&#8221; of an object or you can use a simple typeof(&#8230;) construct. The following code snippet does just this:</p>
<div align="justify">
<div style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   1:</span> <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> ItemMethods</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   2:</span> {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   3:</span>     <span style="color:#0000ff;">public</span> IEnumerable&lt;<span style="color:#0000ff;">string</span>&gt; Methods</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   4:</span>     {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   5:</span>         get</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   6:</span>         {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   7:</span>             Type type = <span style="color:#0000ff;">typeof</span>(SyndicationItem);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   8:</span>&nbsp; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   9:</span>             var methods = (from method <span style="color:#0000ff;">in</span> </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  10:</span>                                type.GetMethods(System.Reflection.BindingFlags.Public | </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  11:</span>                                                System.Reflection.BindingFlags.Instance)</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  12:</span>                           select method.Name).ToList&lt;<span style="color:#0000ff;">string</span>&gt;();</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  13:</span>&nbsp; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  14:</span>             <span style="color:#0000ff;">return</span> methods;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  15:</span>         }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  16:</span>     }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  17:</span> }</pre>
</div>
</div>
<p align="justify">Now let&#8217;s go to blend and create our pop-up. Select a Popup control from the controls list and drop it anywhere on the form (better to put it on the object that it&#8217;ll be binded to or, at least, to on its parent layout element). You can put any single control on the pop-up, but, if you&#8217;d like to extend your functionality later, put some layout element. In my example you can see that I&#8217;ve put a Grid element. The ListBox that will be populated with our methods is positioned on the Grid. You have to set the following properties on the Popup:</p>
<ol>
<li>
<div align="justify">Placement=&#8221;Bottom&#8221; &#8211; this tells the system to position the pop-up at the bottom of the element it&#8217;ll be referring to. The same way as VS shows methods intellisense below and to the right of the &#8220;.&#8221; that you press.</div>
<li>
<div align="justify">StaysOpen =&#8221;False&#8221; &#8211; this tells the WPF to close the Popup if it looses a focus</div>
<li>
<div align="justify">IsOpen=&#8221;False&#8221; &#8211; hides the Popup on form initialization</div>
</li>
</ol>
<p align="justify">To make the ListBox to display method names correctly you have to bind it to the ItemMethods class, we&#8217;ve defined previously. Don&#8217;t forget to compile your code &#8211; this will allow the Expression Blend to find it and help you with binding. </p>
<ol>
<li>
<div align="justify">Go to the advanced properties of the ItemsSource property (small rectangle to the right of the property value box) and click on Data Binding.</div>
<li>
<div align="justify">Add the ItemMethods object from the list that will be presented to you after you press &#8220;+ CLR Object&#8221; button. This will add your new Data Source.</div>
<li>
<div align="justify">On the Fields tree (on the right side) select the Methods collection.</div>
</li>
</ol>
<p align="justify">If you did everything right &#8211; you&#8217;ll see a list of SyndicationItem methods in the Popup. Note that Expression Bled has added a new data source for you:</p>
<div align="justify">
<div style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   1:</span> <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">ObjectDataProvider</span> <span style="color:#ff0000;">x:Key</span><span style="color:#0000ff;">="ItemMethodsDS"</span> </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   2:</span>     <span style="color:#ff0000;">d:IsDataSource</span><span style="color:#0000ff;">="True"</span> </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   3:</span>     <span style="color:#ff0000;">ObjectType</span><span style="color:#0000ff;">="{x:Type Castile:ItemMethods}"</span><span style="color:#0000ff;">/&gt;</span></pre>
</div>
</div>
<p align="justify">and added a bind source to your ListBox: ItemsSource=&#8221;{Binding Path=Methods, Mode=OneWay, Source={StaticResource ItemMethodsDS}}</p>
<p align="justify">I&#8217;m preparing a big article about data binding (it&#8217;s a huge, powerful and extremely important part of WPF you should now), but in a nutshell this specific strings tell WPF to take the items from ItemMethodsDS data source from a proporty Methods.</p>
<p align="justify">At this point you&#8217;re free to customize your list box. For example I&#8217;ve decided to remove the scrollbars (HorizontalScrollBarVisibility=&#8221;Hidden&#8221; and&nbsp; VerticalScrollBarVisibility=&#8221;Hidden&#8221;) and make the ListBox searchable (when you start type the letters it&#8217;ll jump to the item that starts with these letters).</p>
<div align="justify">
<div style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   1:</span> <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">Popup</span> <span style="color:#ff0000;">x:Name</span><span style="color:#0000ff;">="popupLinqMethods"</span> <span style="color:#ff0000;">Height</span><span style="color:#0000ff;">="Auto"</span> <span style="color:#ff0000;">Width</span><span style="color:#0000ff;">="150"</span> </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   2:</span>        <span style="color:#ff0000;">StaysOpen</span><span style="color:#0000ff;">="False"</span> <span style="color:#ff0000;">Placement</span><span style="color:#0000ff;">="Bottom"</span> <span style="color:#ff0000;">IsOpen</span><span style="color:#0000ff;">="false"</span> </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   3:</span>        <span style="color:#ff0000;">d:LayoutOverrides</span><span style="color:#0000ff;">="Width, Margin"</span> </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   4:</span>        <span style="color:#ff0000;">HorizontalAlignment</span><span style="color:#0000ff;">="Left"</span><span style="color:#0000ff;">&gt;</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   5:</span>     <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">Grid</span> <span style="color:#ff0000;">Width</span><span style="color:#0000ff;">="Auto"</span> <span style="color:#ff0000;">Height</span><span style="color:#0000ff;">="Auto"</span><span style="color:#0000ff;">&gt;</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   6:</span>         <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">ListBox</span> <span style="color:#ff0000;">x:Name</span><span style="color:#0000ff;">="lstMethodsSelection"</span> </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   7:</span>              <span style="color:#ff0000;">ScrollViewer</span>.<span style="color:#ff0000;">HorizontalScrollBarVisibility</span><span style="color:#0000ff;">="Hidden"</span> </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   8:</span>              <span style="color:#ff0000;">ScrollViewer</span>.<span style="color:#ff0000;">VerticalScrollBarVisibility</span><span style="color:#0000ff;">="Hidden"</span> </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   9:</span>              <span style="color:#ff0000;">KeyDown</span><span style="color:#0000ff;">="OnMethodsSelectionKeyDown"</span> </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  10:</span>              <span style="color:#ff0000;">SelectedIndex</span><span style="color:#0000ff;">="0"</span> </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  11:</span>              <span style="color:#ff0000;">IsTextSearchEnabled</span><span style="color:#0000ff;">="True"</span> </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  12:</span>              <span style="color:#ff0000;">ItemsSource</span><span style="color:#0000ff;">="{Binding Path=Methods, Mode=OneWay, Source={StaticResource ItemMethodsDS}}"</span> </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  13:</span>              <span style="color:#ff0000;">ItemTemplate</span><span style="color:#0000ff;">="{DynamicResource ListSyndicationObjectMethodsTemplate}"</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  14:</span>          <span style="color:#0000ff;">/&gt;</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  15:</span>     <span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">Grid</span><span style="color:#0000ff;">&gt;</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  16:</span> <span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">Popup</span><span style="color:#0000ff;">&gt;</span></pre>
</div>
</div>
<p align="justify">To make the Popup to disappear when you press Enter (after selecting a desirable item) or when you press Escape, we need to let the ListBox to handle these events. Hence you need an event handler (note the KeyDown=&#8221;OnMethodsSelectionKeyDown&#8221; property in the XAML above). To do this you have to put an event handler name in the KeyDown event on the event&#8217;s list of the ListBox. After you&#8217;ll press Enter, you&#8217;ll be taken back to the VS to edit your event handler. Here how it can look like:</p>
<div align="justify">
<div style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   1:</span> <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">void</span> OnMethodsSelectionKeyDown(<span style="color:#0000ff;">object</span> sender, System.Windows.Input.KeyEventArgs e)</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   2:</span> {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   3:</span>     <span style="color:#0000ff;">switch</span> (e.Key)</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   4:</span>     {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   5:</span>         <span style="color:#0000ff;">case</span> System.Windows.Input.Key.Enter:</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   6:</span>             <span style="color:#008000;">// Hide the Popup</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   7:</span>             popupLinqMethods.IsOpen = <span style="color:#0000ff;">false</span>;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   8:</span>&nbsp; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   9:</span>             ListBox lb = sender <span style="color:#0000ff;">as</span> ListBox;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  10:</span>             <span style="color:#0000ff;">if</span> (lb == <span style="color:#0000ff;">null</span>)</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  11:</span>                 <span style="color:#0000ff;">return</span>;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  12:</span>&nbsp; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  13:</span>             <span style="color:#008000;">// Get the selected item value</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  14:</span>             <span style="color:#0000ff;">string</span> methodName = lb.SelectedItem.ToString();</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  15:</span>&nbsp; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  16:</span>             <span style="color:#008000;">// Save the Caret position</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  17:</span>             <span style="color:#0000ff;">int</span> i = txtFilterText.CaretIndex;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  18:</span>             </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  19:</span>             <span style="color:#008000;">// Add text to the text</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  20:</span>             txtFilterText.Text = txtFilterText.Text.Insert(i, methodName);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  21:</span>&nbsp; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  22:</span>             <span style="color:#008000;">// Move the caret to the end of the added text</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  23:</span>             txtFilterText.CaretIndex = i + methodName.Length;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  24:</span>&nbsp; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  25:</span>             <span style="color:#008000;">// Move focus back to the text box. This will auto-hide the PopUp due to StaysOpen="false"</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  26:</span>             txtFilterText.Focus();</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  27:</span>             <span style="color:#0000ff;">break</span>;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  28:</span>&nbsp; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  29:</span>         <span style="color:#0000ff;">case</span> System.Windows.Input.Key.Escape:</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  30:</span>             <span style="color:#008000;">// Hide the Popup</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  31:</span>             popupLinqMethods.IsOpen = <span style="color:#0000ff;">false</span>;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  32:</span>             <span style="color:#0000ff;">break</span>;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  33:</span>     }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  34:</span> }</pre>
</div>
</div>
<p align="justify">All what we did so far was the control of the behavior and the content of the Popup, but we did nothing to trigger it appearance. Here your imagination is your limit. To make this sample work I&#8217;ve decided to show the Popup when the user will type the word &#8220;item.&#8221; in the script editor. As soon as he&#8217;ll press &#8220;.&#8221;&nbsp; &#8211; the Popup will appear, allowing him to insert the selected method back to the script. The following KeyUp text box event handler&#8217;s code allows me to do just that. Note that the Key.OemPeriod value is used to identify the pressed &#8220;.&#8221; (dot). It wasn&#8217;t that obvious to me. Note, as well, the hardcoded &#8220;item.&#8221; hot-word. This is done to simplify the explanation. In your code it should be modified to reflect your needs.</p>
<div align="justify">
<div style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   1:</span> <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">void</span> OnFilterTextKeyUp(<span style="color:#0000ff;">object</span> sender, System.Windows.Input.KeyEventArgs e)</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   2:</span> {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   3:</span>     TextBox txtBox = sender <span style="color:#0000ff;">as</span> TextBox;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   4:</span>     <span style="color:#0000ff;">if</span> ((txtBox == <span style="color:#0000ff;">null</span>) || (txtBox.CaretIndex == 0))</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   5:</span>         <span style="color:#0000ff;">return</span>;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   6:</span>&nbsp; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   7:</span>     <span style="color:#008000;">// Check for a predefined hot-key</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   8:</span>     <span style="color:#0000ff;">if</span> (e.Key != System.Windows.Input.Key.OemPeriod)</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   9:</span>         <span style="color:#0000ff;">return</span>;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  10:</span>&nbsp; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  11:</span>     <span style="color:#008000;">// Get the last word in the text (preceding the ".")</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  12:</span>     <span style="color:#0000ff;">string</span> txt = txtBox.Text;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  13:</span>     <span style="color:#0000ff;">int</span> wordStart = txt.LastIndexOf(<span style="color:#006080;">' '</span>, txtBox.CaretIndex - 1);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  14:</span>     <span style="color:#0000ff;">if</span> (wordStart == -1)</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  15:</span>         wordStart = 0;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  16:</span>&nbsp; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  17:</span>     <span style="color:#0000ff;">string</span> lastWord = txt.Substring(wordStart, txtBox.CaretIndex - wordStart);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  18:</span>&nbsp; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  19:</span>     <span style="color:#008000;">// Check if the last word equal to the one we're waiting</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  20:</span>     <span style="color:#0000ff;">if</span> (lastWord.Trim().ToLower() != <span style="color:#006080;">"item."</span>)</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  21:</span>         <span style="color:#0000ff;">return</span>;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  22:</span>&nbsp; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  23:</span>     ShowMethodsPopup(txtBox.GetRectFromCharacterIndex(txtBox.CaretIndex, <span style="color:#0000ff;">true</span>));</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  24:</span> }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  25:</span>&nbsp; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  26:</span> <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">void</span> ShowMethodsPopup(Rect placementRect)</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  27:</span> {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  28:</span>     popupLinqMethods.PlacementTarget = txtFilterText;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  29:</span>     popupLinqMethods.PlacementRectangle = placementRect;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  30:</span>     popupLinqMethods.IsOpen = <span style="color:#0000ff;">true</span>;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  31:</span>     lstMethodsSelection.SelectedIndex = 0;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  32:</span>     lstMethodsSelection.Focus();</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  33:</span> }</pre>
</div>
</div>
<p align="justify">It&#8217;s a little tricky to place the Popup exactly at the desired place &#8211; it has almost unlimited selection of different placement combinations (see MSDN help for the Placement property. In my case I needed, as I&#8217;ve mentioned above, to open it to the lower right from the pressed &#8220;.&#8221;. So my Popup has the Placement=&#8221;Bottom&#8221; &#8211; this will make it appear under the &#8220;.&#8221;. </p>
<p align="justify">How to find the &#8220;.&#8221; location &#8211; you&#8217;ll ask? That&#8217;s a great question!</p>
<p align="justify">It&#8217;s not that easy in Windows forms, but was super easy in WPF. The character location in a TextBox can be found by calling the GetrectFromCharacterIndex method. But this will give you the coordinates of the character inside the TextBox and the Popup will open in the incorrect place, because it&#8217;ll calculate it&#8217;s location relative to it&#8217;s parent Layout element. This is not what we need. To compensate the calculation we need to point the Popup PlacementTarget to our TextBox (see code above: PlacementTarget = txtFilterText).</p>
<p align="justify">Now we&#8217;re done! Start your script editor and start typing. You should see something very similar to the picture I&#8217;ve posted at the beginning of the post.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/igorshare.wordpress.com/61/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/igorshare.wordpress.com/61/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/igorshare.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/igorshare.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/igorshare.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/igorshare.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/igorshare.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/igorshare.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/igorshare.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/igorshare.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/igorshare.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/igorshare.wordpress.com/61/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=igorshare.wordpress.com&blog=2434376&post=61&subd=igorshare&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://igorshare.wordpress.com/2008/01/09/intellisense-like-method-selection-pop-up-window/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/96b0fd2825bdeb9f9039b1259156b91b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">IgorM</media:title>
		</media:content>

		<media:content url="http://igorshare.files.wordpress.com/2008/01/clip-image001-thumb1.png" medium="image">
			<media:title type="html">clip_image001</media:title>
		</media:content>
	</item>
		<item>
		<title>Creating custom shaped windows in WPF</title>
		<link>http://igorshare.wordpress.com/2008/01/08/creating-custom-shaped-windows-in-wpf/</link>
		<comments>http://igorshare.wordpress.com/2008/01/08/creating-custom-shaped-windows-in-wpf/#comments</comments>
		<pubDate>Tue, 08 Jan 2008 05:39:12 +0000</pubDate>
		<dc:creator>igormoochnick</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://igorshare.wordpress.com/2008/01/08/creating-custom-shaped-windows-in-wpf/</guid>
		<description><![CDATA[The unleashed power of WPF can do wonders, but be very carefull while creating custom shaped windows &#8211; keep the usability in mind. It should be clear to a user what each control represents and what the presented information means.
So, if you are planning to make you window cool, you have to drop the chains [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=igorshare.wordpress.com&blog=2434376&post=57&subd=igorshare&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>The unleashed power of WPF can do wonders, but be very carefull while creating custom shaped windows &#8211; keep the usability in mind. It should be clear to a user what each control represents and what the presented information means.</p>
<p>So, if you are planning to make you window cool, you have to drop the chains of the Windows themes. To do so you have to set the WindowStyle=&#8221;None&#8221;. This removed the window&#8217;s title bar, borders, control, maximize, minimize and close buttons &#8211; in simple words, EVERYTHING. This means you have to take control of the window into your hands. You have to give a user a way to close and move the window around. Don&#8217;t forget about the resize, if applicable.</p>
<p>To make your button close your window, you should set its Command property to ApplicationCommand.Close. If you&#8217;ll type &#8220;Close&#8221; in the Command property &#8211; Expression Blend will generate correct code for you. This is how this will look in Blend:</p>
<p><a href="http://igorshare.files.wordpress.com/2008/01/image3.png"><img style="border-right:0;border-top:0;border-left:0;border-bottom:0;" height="244" alt="image" src="http://igorshare.files.wordpress.com/2008/01/image-thumb2.png?w=460&#038;h=244" width="460" border="0"></a>
<p>Setting the Command property will not do the all job. You need to bind the command to the actual action Window.Close() by using a CommandBinding class and assigning a new event handler. Here you can use Lambda notation to make the code simple.
<div>
<div style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   1:</span> <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">partial</span> <span style="color:#0000ff;">class</span> MainWindow</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   2:</span> {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   3:</span>     <span style="color:#0000ff;">public</span> MainWindow()</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   4:</span>     {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   5:</span>         <span style="color:#0000ff;">this</span>.InitializeComponent();</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   6:</span>&nbsp; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   7:</span>         <span style="color:#008000;">// Bind the Close command to the close action</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   8:</span>         CommandBindings.Add(<span style="color:#0000ff;">new</span> CommandBinding(ApplicationCommands.Close,</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   9:</span>             <span style="color:#0000ff;">new</span> ExecutedRoutedEventHandler(( sender, args) =&gt; Close() )));</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  10:</span>&nbsp; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  11:</span>         <span style="color:#008000;">// NOTE: for those who is not familiar with lambda expressions</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  12:</span>         <span style="color:#008000;">// ( sender, args) =&gt; Close()   is literally equivalent to</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  13:</span>         <span style="color:#008000;">// delegate(object sender, ExecutedRoutedEventArgs args) { this.Close(); }</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  14:</span>     }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  15:</span>&nbsp; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  16:</span>     <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">void</span> DragWindow(<span style="color:#0000ff;">object</span> sender, MouseButtonEventArgs e)</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  17:</span>     {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  18:</span>         DragMove();</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  19:</span>     }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  20:</span> }</pre>
</div>
</div>
<p>To make my window draggable, I&#8217;ve associated the MouseLeftButtonDown event of the orange window corner to the DragWindow event.</p>
<p>You see, it&#8217;s easy. So go and experiment &#8211; unleash your imaginations.</p>
<p>Stay tuned for more WPF tips and tricks.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/igorshare.wordpress.com/57/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/igorshare.wordpress.com/57/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/igorshare.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/igorshare.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/igorshare.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/igorshare.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/igorshare.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/igorshare.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/igorshare.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/igorshare.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/igorshare.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/igorshare.wordpress.com/57/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=igorshare.wordpress.com&blog=2434376&post=57&subd=igorshare&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://igorshare.wordpress.com/2008/01/08/creating-custom-shaped-windows-in-wpf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/96b0fd2825bdeb9f9039b1259156b91b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">IgorM</media:title>
		</media:content>

		<media:content url="http://igorshare.files.wordpress.com/2008/01/image-thumb2.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
	</channel>
</rss>