<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>SeeSharp</title><link>http://www.hightech.ir:80/SeeSharp</link><description>SeeSharp</description><item><title>Mindscape WinRT Controls</title><link>http://www.hightech.ir:80/SeeSharp/mindscape-winrt-controls</link><description>&lt;p&gt;As a part of my adventures on porting my suite of &lt;a href="http://www.hightech.ir/products/farsilibrary"&gt;Calendar&lt;/a&gt; controls to Windows 8 and &lt;a href="http://en.wikipedia.org/wiki/Windows_Runtime"&gt;WinRT&lt;/a&gt;, I set to see how other companies are doing in providing components for Windows 8 development. Considering WinRT is a new market for component providers there are not so many companies with WinRT controls around. &lt;a href="http://www.mindscapehq.com"&gt;Mindscape&lt;/a&gt; is among very few others providing a promising suite of controls. Although still in Beta the controls have great feature set, astonishing look and feel and more importantly a good time to market which is a key factor at this stage if you're working on a Windows 8 application.&lt;/p&gt;
&lt;p&gt;The controls are currently in Beta version and I also went an extra mile and downloaded their nightly build. The only issue I had was that I had to fix some references in the sample project to get it running (could be an issue with the nightly build I downloaded). Other than that the sample app ran just fine.&lt;/p&gt;
&lt;div class="center"&gt;&lt;img src="/Media/Default/BlogImages/Mindscape-WinRT-01.png" alt="" width="500" height="285" /&gt;&lt;/div&gt;
&lt;p&gt;&lt;br /&gt;There are not so many user controls available in the suite yet. There is a Calendar and a DateTime Picker and a few text boxes with Autocomplete, Numeric, Integer, Up/Down support. I would have liked to see just one textbox control with all these features instead of having completely separate controls. Among other controls there is a Transition Control that you can use to have nifty animations when changing a content of a ContentControl, without going through the trouble of creating any complex animation. The Coverflow and Book controls would also provide similar functionality, but I don't see myself using them that much.&lt;/p&gt;
&lt;p&gt;On the other hand wide range of Chart controls are available for you to pick from: Bar, Area, Pie, Line, Stock and a few more are all there and they look great. There's even a "Pallette" feature that allows you select a set of color that would match your corporate / application profile without having to style the chart control.&lt;/p&gt;
&lt;div class="center"&gt;&lt;img src="/Media/Default/BlogImages/Mindscape-WinRT-02.png" alt="" width="500" height="285" /&gt;&lt;/div&gt;
&lt;p&gt;&lt;br /&gt;Even though I expected to see more controls, this is still in beta and I'm happy with where this is headed to. If you're into Windows 8 development, I recommend you grab the &lt;a href="http://www.mindscapehq.com/products/metroelements"&gt;trial version&lt;/a&gt; and take a look for yourself.&lt;/p&gt;
&lt;div&gt;&lt;/div&gt;</description><pubDate>Thu, 20 Dec 2012 14:34:05 GMT</pubDate><guid isPermaLink="true">http://www.hightech.ir:80/SeeSharp/mindscape-winrt-controls</guid></item><item><title>Android Development for .NET Programmers</title><link>http://www.hightech.ir:80/SeeSharp/android-development-for-net-programmers</link><description>&lt;p&gt;When it comes to mobile programming, &lt;a href="http://www.android.com"&gt;Android&lt;/a&gt; is one of the vastly spread mobile OSes around, so how would you as a .NET programmer write android applications? It turns out there is a &lt;a href="http://mono-android.net/"&gt;Monodroid&lt;/a&gt; project (currently in beta) which you can use to write android applications in C# and managed .NET environment and you can reuse your existing knowledge. Pretty cool, except it is a commercial framework once released. The alternative is to use freely available android tools and SDK, but the catch is that you need to be familiar with Java language instead of C#. But how different is that? Should it matter for a programmer at all? Let's find out.&lt;br /&gt; &lt;br /&gt; &lt;span class="subtitle"&gt;Java Language&lt;/span&gt;&lt;br /&gt; For a C# programmer, the language should be very similar as they are more similar and different. There are some differences in Generics, Iterators, etc. but those are easy to master. Of course you don't have C# 3.0 syntactic sugar luxuries in Java world. One thing that may seem odd for a .NET developer is the notion of inline classes which are non existing in .NET world. This construct allows you to specify an interface implementation inline, instead of creating a full blown class. This comes in handy for example, when you implement click listener interfaces on your class. Here's an example:&lt;/p&gt;
&lt;pre class="brush:java"&gt;public class MyActivity extends Activity {
    protected void wireEventHandlers() {
        this.mybutton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                showMessage();
            }
        });
    }
}
&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt; In above example, "OnClickListener" is actually an interface where implementation (merely a method) is implemented inline. A .NET developer also may write the above snippet as this, which of course does the same job:&lt;/p&gt;
&lt;pre class="brush:java"&gt;public class MyActivity extends Activity 
                            implements View.OnClickListener {
    
    protected void wireEventHandlers() {
        this.mybutton.setOnClickListener(this);
    }

    public void onClick(View view) {
        showMessage();
    }
}
&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt; The C# goodies I missed when developing in Java were mostly delegates and inability to use them as functional blocks of code, and also the most argued &lt;a href="http://www.ben-morris.com/implicitly-unreadable-the-c-var-keyword-and-lazy-code"&gt;"var" keyword&lt;/a&gt;.&lt;br /&gt; &lt;br /&gt; &lt;span class="subtitle"&gt;Tools of the Trade&lt;/span&gt;&lt;br /&gt; There are two choices when you start developing Android applications. What most people use is the &lt;a href="http://www.eclipse.org/"&gt;Eclipse IDE&lt;/a&gt; which is one of the worst IDEs I have ever worked with. Eclipse allows development for different platforms and languages: C/C++, Java, PHP and now Android. The good thing about it is that it is free and has a lot of plugins but that's about it.&lt;br /&gt; &lt;br /&gt; It caused a lot of pain for me during the development and the IDE seems immature at best when compared with other IDEs or probably in your case, comparing to Visual Studio with all its bells and whistles.&lt;br /&gt; &lt;br /&gt; Is there a better alternative? Fortunately, yes. Good guys at &lt;a href="http://www.jetbrains.com"&gt;JetBrains&lt;/a&gt; have added Android development support to their Java IDE called &lt;a href="http://www.jetbrains.com/idea/"&gt;IntelliJ Idea&lt;/a&gt; and if you have happened to use their &lt;a href="http://www.jetbrains.com/resharper"&gt;Resharper&lt;/a&gt; plugin for Visual Studio, specially with IntelliJ Keyboard shortcuts, you'll feel right at home. IntelliJ Idea has a &lt;a href="http://www.jetbrains.com/idea/free_java_ide.html"&gt;Community Edition&lt;/a&gt; that is free and open-source.&lt;br /&gt; &lt;br /&gt; Other than an IDE you need to get &lt;a href="http://developer.android.com/sdk/"&gt;Android SDK&lt;/a&gt; and emulator. You can download the SDK manager from &lt;a href="http://developer.android.com/sdk/"&gt;this&lt;/a&gt; google web page and once downloaded you need to download a specific version of SDK for the android platform you plan to develop your application on, from within the SDK Manager.&lt;/p&gt;
&lt;p&gt;Now that you have an IDE and downloaded the necessary SDK you're all set. In next post we'll start to write a small app that works with a REST API so that we see how things are easily done and how a regular .NET developer is able to write full blown Android application in no time.&lt;/p&gt;</description><pubDate>Sun, 18 Nov 2012 18:57:09 GMT</pubDate><guid isPermaLink="true">http://www.hightech.ir:80/SeeSharp/android-development-for-net-programmers</guid></item><item><title>Cracking .NET Assemblies</title><link>http://www.hightech.ir:80/SeeSharp/cracking-net-assemblies</link><description>&lt;p&gt;As a part of working in a &lt;a href="https://github.com/ayende/rhino-licensing"&gt;Licensing&lt;/a&gt; component codebase, I'm checking commercial components to see how they implement licensing and the result, as you guess, is that mostly in-house (read dumb) lousy solutions are used for licensing and trial versioning. So if you see the key-gen for your application spread on the internet a couple of days after releasing a new version, maybe this post is meant for you.&lt;br /&gt; &lt;br /&gt; If you've been a .NET developer for long enough, you probably know that your high level .NET Language (C# / VB.NET, etc.) is converted to &lt;a href="http://en.wikipedia.org/wiki/Common_Intermediate_Language"&gt;Common Intermediate Language&lt;/a&gt; (CIL). That is true for all languages converting to &lt;a href="http://en.wikipedia.org/wiki/Intermediate_language"&gt;Intermediate Langauge&lt;/a&gt; so the discussion here is not limited to .NET, nor it is a weakness of .NET languages per se.&lt;br /&gt; &lt;br /&gt; So what's the big deal? The problem is that your assembly, can be converted &lt;strong&gt;BACK&lt;/strong&gt; to IL, modified and saved, so malicious crackers can remove your copy protection pretty easily, so you need to take extra precautions to make it harder for cracker to do that.&lt;/p&gt;
&lt;p&gt;You may think changing the IL code needs extensive amount of IL knowledge, but that is not true. To have better idea what to do, you need to put yourself in the cracker's shoe. Let's see a real world component and see how it can easily be cracked (I've removed/changed the names/namespaces to protect the innocent).&lt;br /&gt; &lt;br /&gt; &lt;em&gt;&lt;strong&gt;Disclaimer: This is to show software vendors and providers how to protected (or not protect) their intellectual property. Author is not responsible or liable for any misuse of the information provided here.&lt;/strong&gt;&lt;/em&gt;&lt;br /&gt; &lt;br /&gt; Chances are, when a cracker wants to remove the copy protection, he opens your assembly in &lt;a href="http://www.red-gate.com/products/dotnet-development/reflector/"&gt;Reflector&lt;/a&gt; to find out how the internals are working.&lt;br /&gt; &lt;br /&gt; &lt;img alt="" src="http://www.hightech.ir/Images/BlogPics/Cracking_AssemblyInternals.png" style="width: 251px; height: 280px;" /&gt;&lt;br /&gt; &lt;br /&gt; As you can see, this is the worst case scenario because the cracker can isolate the protection mechanism instantly just by looking at namespaces! It helps to put that code somewhere that is not so obvious, or even better, spread the protection code to a couple of places! Upon further investivation, he will find out that a simple Date object is used to track compilation date of the assembly and make it stop working after a predefined days are passed:&lt;/p&gt;
&lt;pre class="brush:c-sharp"&gt;internal static class TrialSystem
{
    public static DateTime CompilationDate
    {
        get { return new DateTime(2011, 1, 1); }
    }
}
&lt;/pre&gt;
&lt;p&gt;The easiest crack would be to change the CompilationDate to return DateTime.Now everytime accessed, so the application would never expire! But how'd you do that? Supposing the cracker has&lt;br /&gt; limited knowledge of IL, he fires up the VisualStudio, writes the replacing code in C# / VB.NET and opens the output assembly in Reflector in IL language!&lt;br /&gt; &lt;br /&gt; &lt;img alt="" src="http://www.hightech.ir/Images/BlogPics/Cracking_MethodIL.png" style="width: 650px; height: 193px;" /&gt;&lt;br /&gt; &lt;br /&gt; All needed is to replace this code with the one inside the assembly. Believe it or not, the tools needed are accompanied in .NET SDK! Open the &lt;em&gt;VisualStudio 2010 Command Prompt&lt;/em&gt; and type the following on the same folder the assembly resides in:&lt;/p&gt;
&lt;pre&gt;ILDASM /OUT=SourceCode.il TheAssemblyName.dll
&lt;/pre&gt;
&lt;p&gt;This dumps the IL code into SourceCode.il file and places the rest of the resources at the same folder so later all these files can be stitched back together. Cracker can now open the IL file in any text editor, replace old IL code with the one shown above and save the IL code back to disk. Now time to convert the IL back to regular assembly. The following command creates a .NET Assembly from the IL code:&lt;/p&gt;
&lt;pre&gt;ILASM /DLL SourceCode.il /OUT=NewAssembly.dll
&lt;/pre&gt;
&lt;p&gt;Now he can use the new assembly without any limitation. If you think signing the assembly will prevent crackers, you're completely wrong. It may make it a little bit more laborious but the assembly is still vulnerable.&lt;/p&gt;
&lt;p&gt;In next post, I'll show you some techniques to make this process a little harder for crackers, but remember, as a general rule of thumb if your application is worth more than couple of hundred dollars or has more than hundred users, chances are it WILL get cracked at some point.&lt;/p&gt;</description><pubDate>Sun, 09 Sep 2012 05:42:17 GMT</pubDate><guid isPermaLink="true">http://www.hightech.ir:80/SeeSharp/cracking-net-assemblies</guid></item><item><title>DevExpress Scheduler and Hijri Shamsi Calendar</title><link>http://www.hightech.ir:80/SeeSharp/devexpress-scheduler-and-hijri-shamsi-calendar</link><description>&lt;p&gt;The level of customization that Silverlight comes with - even when you don't have access to the source code of the control you are using - is simply amazing. Those who experienced WinForms control customization or control centric web frameworks like ASP.NET already know how much trouble they face when customizing a 3rd party control, if there is any customization support at all. In fact people have been asking &lt;a href="http://www.devexpress.com" target="_blank"&gt;DevExpress&lt;/a&gt; to add RightToLeft support to their WinForms suite of controls, which is &lt;a href="https://twitter.com/JMBucknall/status/202179721969143808" target="_blank"&gt;not going to happen&lt;/a&gt; for the same reason: it is hard to modify how a control looks without touching the other behavioral logics inside because those two are mixed together. Since in Silverlight and WPF the logic is completely kept separate from the presentation, you could twist the look and feel and make the control look how you want it to look.&lt;/p&gt;
&lt;p&gt;A good example would be adding &lt;a href="http://en.wikipedia.org/wiki/Iranian_calendars" target="_blank"&gt;Hijri Shamsi calendar&lt;/a&gt; support to DevExpress scheduler controls. This now can be done by retemplating the whole Scheduler control and using date calculation support of my &lt;a href="https://github.com/HEskandari/FarsiLibrary" target="_blank"&gt;FarsiLibrary&lt;/a&gt; project. The best part is that unlike WinForms, the source code is not needed at all and you can apply this to the out of the box control directly.&lt;br /&gt;&amp;nbsp;&lt;/p&gt;
&lt;div class="center"&gt;&lt;img src="/Media/Default/BlogImages/Calendar.png" alt="DevExpress Scheduler control with Farsi / Hijri Shamsi calendar support" width="780" height="478" /&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;br /&gt;Microsoft abandoning Silverlight platform in favour of HTML 5 makes my heart ache. Will there be that level of customization support in HTML 5 applications (and controls, maybe someday) is left to be seen.&lt;br /&gt;&amp;nbsp;&lt;/div&gt;</description><pubDate>Wed, 11 Jul 2012 04:19:24 GMT</pubDate><guid isPermaLink="true">http://www.hightech.ir:80/SeeSharp/devexpress-scheduler-and-hijri-shamsi-calendar</guid></item><item><title>Deferred Message Processing in NServiceBus</title><link>http://www.hightech.ir:80/SeeSharp/deferred-message-processing-in-nservicebus</link><description>&lt;p&gt;When working on a project using &lt;a href="nservicebus.com" target="_blank"&gt;NServiceBus&lt;/a&gt;, we came up with an interesting requirement. The messages in the queue should be processed only in certain time frames. The reason is that message handler is making a webservice call and the other party is only available at certain times and system is not even allowed to make a call during the outage window. You can easily achieve this using Bus.Defer feature in version 3.0 of NServiceBus, but that would put the message at the back of the queue and would change the order of the messages which was very important from business perspective in our case. So we had to roll up our sleeves and dig a bit deeper. It turned out NServiceBus is using an ITransport interface to process the messages in the queue. The implementation that comes with NServiceBus is named TransactionalTransport. This is the class that handles the processing threads under the hood, so what if we set the number of processing threads to zero for a while, and when we need to resume processing, set it back to the default value (one or more threads)?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.udidahan.com/" target="_blank"&gt;Udi&lt;/a&gt; suggests that you shouldn't actually use this, if possible. Instead send the message to the remote queue and let the other end worry about how and when to process it, but this may not work if you're working in a locked down environment or your customer would simply play it by their rules.&lt;/p&gt;
&lt;p&gt;Okay here's the code snippet if you're interested.&lt;/p&gt;
&lt;pre class="brush:c-sharp"&gt;public abstract class BaseCommandHandler&amp;lt;T&amp;gt; : IHandleMessages&amp;lt;T&amp;gt;
{
    private TimeSpan _wait = TimeSpan.FromSeconds(30);

    public TimeSpan DefaultWait
    {
        get { return _wait; }
        set { _wait = value; }
    }

    public virtual IBus Bus { get; set; }

    public virtual ITransport Transport { get; set; }

    public virtual void Handle(T message)
    {
        if (CanProcessMessage())
        {
            ProcessMessage(message);
        }
        else
        {
            PauseProcessing(DefaultWait);
        }
    }

    protected abstract void ProcessMessage(T message);

    protected virtual bool CanProcessMessage()
    {
        return true;
    }

    private void PauseProcessing(double interval)
    {
        Transport.PauseProcessing();
        Spin(interval);
    }

    private void Spin(double interval)
    {
        var timer = new Timer(interval) { Enabled = true };
        timer.Elapsed += OnSpinnigFinished;
        timer.Start();
    }

    private void OnSpinnigFinished(object sender, ElapsedEventArgs elapsedEventArgs)
    {
        var timer = (Timer) sender;
        timer.Enabled = false;
        timer.Dispose();
        Transport.ResumeProcessing();
    }
}

public static class TransportExtensions
{
    public static void PauseProcessing(this ITransport transport)
    {
        transport.AbortHandlingCurrentMessage();
        transport.ChangeNumberOfWorkerThreads(0);
    }

    public static void ResumeProcessing(this ITransport transport)
    {
        transport.ChangeNumberOfWorkerThreads(1);
    }
}

&lt;/pre&gt;</description><pubDate>Wed, 27 Jun 2012 15:54:25 GMT</pubDate><guid isPermaLink="true">http://www.hightech.ir:80/SeeSharp/deferred-message-processing-in-nservicebus</guid></item><item><title>Distributed Transactions Tweaks in NServiceBus</title><link>http://www.hightech.ir:80/SeeSharp/distributed-transactions-tweaks-in-nservicebus</link><description>&lt;p&gt;While using &lt;a href="http://nservicebus.com/"&gt;NServiceBus&lt;/a&gt; on the first engagement at &lt;a href="http://readify.net/"&gt;Readify&lt;/a&gt;, we had an interesting configuration. Development environment has a shared database which runs on a server but when creating the backend application, we're running NServiceBus on our local developer machines. When handling messages, NServiceBus creates an &lt;a href="http://msdn.microsoft.com/en-us/library/ms172152(v=vs.90).aspx"&gt;ambient transaction&lt;/a&gt; using MSDTC which spans multiple resources/machines and is of course a valuable feature because if an exception is thrown somewhere in your code when a message is being processed, database transactions (or any other DTC enlisted transactions for that matter) will automatically rollback so you won't have to write boilerplate code. This was problematic for us because DTC was not enabled on the database server so we couldn't test the application at all. We needed to tell NServiceBus not to use DTC around message consumers. You gotta love open-source projects because just by &lt;a href="https://github.com/NServiceBus/NServiceBus/blob/master/src/impl/unicast/transport/NServiceBus.Unicast.Transport.Transactional/TransactionalTransport.cs" target="_blank"&gt;looking at the code&lt;/a&gt;&amp;nbsp;we found out there is a property on TransactionalTransport named SuppressDTC which exactly does that, but how to set that? &lt;br /&gt;&lt;br /&gt;You see, NServiceBus uses &lt;a href="http://en.wikipedia.org/wiki/Inversion_of_control" target="_blank"&gt;IoC containers&lt;/a&gt; to find its components, so in this case TransactionalTransport (an ITransport implementation) is created by the container, so we'd have limited access to where it is created or how it is being registered in the container and have no elegant way to set this property, but luckily we were using &lt;a href="http://www.castleproject.org/container/index.html" target="_blank"&gt;Castle Windsor&lt;/a&gt;&amp;nbsp;container we could do much better with its extensibility model.&lt;br /&gt;&lt;br /&gt;In case you don't know, Castle Windsor allows you to tap into &lt;a href="http://stw.castleproject.org/Windsor.Lifecycle.ashx" target="_blank"&gt;creation of an object&lt;/a&gt; using ICommissionConcern (and a similar thing for when destroying an object). So all you needed to do to get called when an object of a certain type is created is to create a class implementing ICommissionConcern, which has only one method to implement. You also need to plug this class in and let the container know which component type is bound to this commission concern. This is done by implementing IContributeComponentModelConstruction interface and checking the interface or concrete type of the component that is being created. Too much said, you can see it all in one piece of code.&lt;/p&gt;
&lt;pre class="brush:c-sharp"&gt;public class TransportTransactionConfig : IContributeComponentModelConstruction
{
    public void ProcessModel(IKernel kernel, ComponentModel model)
    {
        if (model.Implementation != typeof(TransactionalTransport))
            return;
	
        var concern = new TransactionSuppressConcern();
        model.Lifecycle.Add(concern);
    }
	
    private class TransactionSuppressConcern : ICommissionConcern
    {
        public void Apply(ComponentModel model, object component)
        {
            ((TransactionalTransport)component).SupressDTC = ShouldSuppressDTC;
        }

        private bool ShouldSuppressDTC
        {
            get { return bool.Parse(ConfigurationManager.AppSettings["SuppressDTC"]); }
        }
    }
}&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;</description><pubDate>Tue, 29 May 2012 02:00:10 GMT</pubDate><guid isPermaLink="true">http://www.hightech.ir:80/SeeSharp/distributed-transactions-tweaks-in-nservicebus</guid></item><item><title>Fun with Expression Trees</title><link>http://www.hightech.ir:80/SeeSharp/fun-with-expression-trees</link><description>&lt;p&gt;Logging is easy. We've all been there and done that, but when how do you log a request/response object of a webservice, specially when the WSDLs are being changed constantly? The requirements were easy, just log all the property names along with their values. The first obvious approach is the good old fashioned style:&lt;/p&gt;
&lt;pre class="brush:c-sharp"&gt;public static string GetRequestLog(this ServiceRequest request)
{
    var sb = new StringBuilder();
    sb.AppendFormat("FirstProperty:{0}", request.FirstProperty);
    sb.AppendFormat("SecondProperty:{0}", request.FirstProperty);
    ... 
    sb.AppendFormat("LastProperty:{0}", request.LastProperty);
    return sb.ToString();
}
&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;The problem is you code includes name and value of the property in two separate places and when you get an updated WSDL with most of the property names changed, you have to update two places, one of them being the property name in a string which makes it just harder to refactor and rename, but what can you do? You can shrug and say so be it, that is the problem at hand, until the next day you'll be handled the newer version of the WSDL, or you can do something about it.&lt;/p&gt;
&lt;p&gt;If performance is not an issue (well you should know better to turn the debugging on in production), you can get away by passing in an expression of the property. This was you're passing in the property as well as it's value!&lt;/p&gt;
&lt;pre class="brush:c-sharp"&gt;public static string GetRequestLog(this ServiceRequest request) 
{
    var sb = new StringBuilder();
    sb.AppendProperty(() =&amp;gt; request.FirstProperty);
    sb.AppendProperty(() =&amp;gt; request.SecondProperty);
    ...
    sb.AppendProperty(() =&amp;gt; request.HundredthProperty);
    return sb.ToString();
}
    
public static class StringBuilderExtension
{
    public static void AppendProperty&amp;lt;T&amp;gt;(this StringBuilder sb, Expression&amp;lt;Func&amp;lt;T&amp;gt;&amp;gt; property)
    {
        var memberInfo = GetMemberInfo(property);
        sb.AppendFormat("{0}: {1}", memberInfo.Name, SafeToString(property.Compile().Invoke()));
    }

    private static MemberInfo GetMemberInfo(Expression expression)
    {
        var lambda = (LambdaExpression)expression;
        MemberExpression memberExpression;
        if (lambda.Body is UnaryExpression)
        {
            var unaryExpression = (UnaryExpression)lambda.Body;
            memberExpression = (MemberExpression)unaryExpression.Operand;
        }
        else
        {
            memberExpression = (MemberExpression)lambda.Body;
        }
        return memberExpression.Member;
    }

    private static string SafeToString(object obj)
    {
        return obj == null ? ("null") : obj.ToString();
    }
}
&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;This of course is no magic these days, you probably have seen this when raising &lt;a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged.aspx"&gt;NotifyPropertyChange&lt;/a&gt; event in &lt;a href="http://caliburn.codeplex.com/"&gt;Caliburn&lt;/a&gt; or reading my &lt;a href="http://www.hightech.ir/SeeSharp/enhanced-inotifypropertychanged-revisited"&gt;blog post&lt;/a&gt; back in September 2008.&lt;/p&gt;</description><pubDate>Mon, 21 May 2012 07:00:21 GMT</pubDate><guid isPermaLink="true">http://www.hightech.ir:80/SeeSharp/fun-with-expression-trees</guid></item><item><title>God Class and Helpers</title><link>http://www.hightech.ir:80/SeeSharp/god-class-and-helpers</link><description>&lt;p&gt;While code reviewing a client's code base I found this gem.&lt;/p&gt;
&lt;p&gt;&lt;img src="/Media/Default/BlogImages/GodClass.png" alt="" width="890" height="2131" /&gt;&lt;/p&gt;
&lt;p&gt;Enough has been said about &lt;a target="_blank" href="http://en.wikipedia.org/wiki/God_object"&gt;God Classes&lt;/a&gt; and &lt;a target="_blank" href="en.wikipedia.org/wiki/Separation_of_concerns"&gt;Separation of Concerns&lt;/a&gt; but I still wonder how putting everything in one place and call it "Helper" can help you. Their argument? It is easier to find the function we are looking for if everything is in one class.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;</description><pubDate>Tue, 31 Jan 2012 14:29:24 GMT</pubDate><guid isPermaLink="true">http://www.hightech.ir:80/SeeSharp/god-class-and-helpers</guid></item><item><title>My Geek Origin Story</title><link>http://www.hightech.ir:80/SeeSharp/my-geek-origin-story</link><description>&lt;p&gt;While spending my last days at my country and not working on an interesting project to blog about, I thought a post about how I happen to be what I am today is in order. While reading a blog post by &lt;a target="_blank" href="http://www.richard-banks.org/"&gt;Richard Banks&lt;/a&gt;, I was inspired to write my Geek Origin Story, a movement initially started by &lt;a target="_blank" href="http://delicategeniusblog.com/?p=1292"&gt;Michael Kordahi&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;My dad used to work in department of power as an engineer as far as I can remember. I used to go with him to all power stations all around the country so eating out with other engineers and playing around gas turbines was something I was used to. Later when personal computers were taking off they grabbed one of the Siemens computers - they already had a lot of contracts with Siemens - and it was sitting there collecting dust in an office at the same floor as my dad's. The curious geek in me was getting itchy.&lt;br /&gt;&lt;br /&gt;When I was only nine years old, on his visit to Italy my father brought home the best gift ever! A Casio PB-700 computer with four 4 KB memory modules, and it was attachable to an extension unit with a tape drive and a printer. With BASIC programming language built-in opportunities seemed endless. Ain't that a beaut?&lt;/p&gt;
&lt;div class="center"&gt;&lt;img src="/Media/Default/BlogImages/GeekStory_Casio.jpg" alt="Cassio PB-700" height="331" width="441" /&gt;&lt;/div&gt;
&lt;p&gt;&lt;br /&gt;&lt;br /&gt;Unfortunately the manual was in Italian, but I started pushing the program samples into it and somehow deciphered how it worked. Soon I was heading to my cousin's computer bookshop - almost one and the only bookshop dedicate to selling computer books in the capital city - to borrow or read a book or two. Around that time ZX-Spectrum were becoming more common and it supported another variation of Basic language. I had very hard time adjusting the samples for ZX-Spectrum books to run on my Casio computer but I managed to do it to some good extent and did a lot of PEEK / POKE in the making.&lt;br /&gt;&lt;br /&gt;My next big computer was an Amiga 500. This one had a lot more juice in it and you could program it with C/C++, various Basic dialects, Pascal or other languages such as Oberon and Fortran - I barely knew any of them - but it also had a giant GPU so it suited very good for graphic applications. You see, personal computers back then mostly had a monochrome display and a command base OS while Amiga 500 had Graphical User Interface (GUI), a very rich music channels and a decent full-color monitor, so I was in for a good ride. This meant lots of Games, Music and Graphics, and did I mention games?&lt;/p&gt;
&lt;div class="center"&gt;&lt;img src="/Media/Default/BlogImages/GeekStory_Amigo.jpg" alt="Amigo 500" height="367" width="438" /&gt;&lt;/div&gt;
&lt;p&gt;&lt;br /&gt;&lt;br /&gt;Once I was in high school my father ordered a 80-386 PC computer, with a 5 &amp;frac14;&amp;rdquo; and 3 &amp;frac12;&amp;rdquo; floppy drives and 10 MB of hard disk! No it didn&amp;rsquo;t even have a mouse and no UI based OS. It ran MS-DOS 3.0 and it looked archaic comparing to my Amiga 500, but from the looks of how things were moving forward it seemed to be the future so I started reading more books and my cousin&amp;rsquo;s bookstore was a more common place. One of the best professional books I read was Dennis Ritchie's C programming language that put some sense into my brain.&lt;br /&gt;&amp;nbsp;&lt;br /&gt;By the time I was finishing high school, I helped the school's network administrator in removing the viruses or setup networking. After high school, being so fond of languages, I decided to study English language at university and learned French and Spanish - although not as good as I intended - in the process. Now although some find it strange and some other find it flat unacceptable, I see studying [real] languages has helped me lean computer languages and achieving my principal goal, which would have been next to impossible otherwise.&lt;br /&gt;&lt;br /&gt;Well that was my geek story&amp;hellip;what is yours?&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;</description><pubDate>Thu, 19 Jan 2012 20:16:50 GMT</pubDate><guid isPermaLink="true">http://www.hightech.ir:80/SeeSharp/my-geek-origin-story</guid></item><item><title>Caliburn Meets TPL / Async</title><link>http://www.hightech.ir:80/SeeSharp/caliburn-meets-tpl-async</link><description>&lt;p&gt;With C# and Async integration in the language, you'll wonder how this fits in your current application infrastructure. I have started porting an old application into Silverlight 5.0 which comes with new C# 5.0 and Async features and I needed a way to integrate this with the &lt;a target="_blank" href="caliburn.codeplex.com"&gt;Calibrun&lt;/a&gt; framework I had in place.&lt;/p&gt;
&lt;p&gt;&lt;span class="subtitle"&gt;Caliburn Async Abstractions&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;In Caliburn you could expose your ViewModel actions as IResult / IEnumerable&amp;lt;IResult&amp;gt;. I have &lt;a target="_blank" href="http://www.hightech.ir/SeeSharp/wpf-application-with-caliburn-part-four"&gt;blogged&lt;/a&gt; about this before, but in short, it is a good way to abstract away the whole async stuff you have in your ViewModel and it made testing async actions in the view model much easier. Here's a typical action I had on a ViewModel:&lt;/p&gt;
&lt;pre class="brush:c-sharp"&gt;public IEnumerable&amp;lt;IResult&amp;gt; LoadEmployee()
{
    yield return Show.Busy();

    yield return new ServiceResult().Invoke(new EmployeeServiceClient().GetEmployeeAsync, SelectedEmployee.Id);

    yield return Show.NotBusy();
} 
&lt;/pre&gt;
&lt;p&gt;By using &lt;a target="_blank" href="caliburn.codeplex.com/wikipage?title=IResult"&gt;IResult&lt;/a&gt; we have modified the whole async and continuation into &lt;a target="_blank" href="en.wikipedia.org/wiki/Coroutine"&gt;coroutines&lt;/a&gt; which is much cleaner to read and easier to follow.&lt;/p&gt;
&lt;p&gt;&lt;span class="subtitle"&gt;Hello Async&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Now with async stuff in the horizon, how would async / await fit this scenario? Let's suppose we have the following async method in our View Model:&lt;/p&gt;
&lt;pre class="brush:c-sharp"&gt;private void LoadEmployeeAsync()
{
    var service = new EmployeeServiceClient();
    service.GetEmployeeCompleted += (s, e) =&amp;gt; { CurrentEmployee = e.Result };
    var employee = service.GetEmployee(SelectedEmployee.Id);
}
&lt;/pre&gt;
&lt;p&gt;At first we should convert this service call into the new async pattern:&lt;/p&gt;
&lt;pre class="brush:c-sharp"&gt;private async Task&amp;lt;Employee&amp;gt; LoadEmployeeAsync()
{
    IEmployeeSevice service = new EmployeeServiceClient();

    return await Task.Factory.FromAsync&amp;lt;Employee&amp;gt;(client.BeginGetEmployee(SelectedEmployee.Id, null, null), ar =&amp;gt; client.EndGetEmployee(ar));
}
&lt;/pre&gt;
&lt;p&gt;A couple of things to notice: We are now using the interface of the generated service, which exposes &lt;a target="_blank" href="msdn.microsoft.com/en-us/library/system.iasyncresult.aspx"&gt;IAsyncResult&lt;/a&gt; and we're returning the method call with a Task&amp;lt;TResult&amp;gt;. With the new async pattern, your method should either return void or Task / Task&amp;lt;T&amp;gt; before you can use the async keyword.&lt;/p&gt;
&lt;p&gt;&lt;span class="subtitle"&gt;There's an IResult for that&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Now the question is how to call the async method in a sequence of IResults. This would be the first attempt:&lt;/p&gt;
&lt;pre class="brush:c-sharp"&gt;public IEnumerable&amp;lt;IResult&amp;gt; LoadEmployee()
{
    yield return Show.Busy();

    yield return new ActionResult(() =&amp;gt; LoadEmployeeAsync());

    yield return Show.NotBusy();
} 

public class ActionResult : IResult
{
        public ActionResult(Action action)
        {
            ToExecute = action;
        }

        public Action ToExecute { get; set; }

        public override void Execute(ResultExecutionContext context)
        {
            ToExecute.Invoke();
            RaiseCompleted();
        }
}
&lt;/pre&gt;
&lt;p&gt;Apparently this won't work as expected because as soon as we call the async method it will return and we'll fire the Completed event on IResult which will move to execution of the next IResult in the sequence. What we want to do is to wait for the completion of the Task and then raise the Completed event, so I came up with this implementation:&lt;/p&gt;
&lt;pre class="brush:c-sharp"&gt;public class TaskResult : IResult
{
    public TaskResult(Func&amp;lt;Task&amp;gt; task)
    {
        ToExecute = task;
    }

    public Func&amp;lt;Task&amp;gt; ToExecute { get; set; }

    public override void Execute(ResultExecutionContext context)
    {
        ToExecute.Invoke().ContinueWith(task =&amp;gt; 
         {
             Execute.OnUIThread(() =&amp;gt; RaiseCompleted(task.IsCanceled, task.Exception));
         });
    }
}
&lt;/pre&gt;
&lt;p&gt;This is just the same API that is available today on TPL, so nothing fancy, the only thing worth mentioning here is that we're raising the Completed event on the UI thread using Execute class of Caliburn. The Execute class uses IDispatcher interface that wraps Silverlight / WPF dispatcher object. The final version of the TaskResult can be used like this:&lt;/p&gt;
&lt;pre class="brush:c-sharp"&gt;public IEnumerable&amp;lt;IResult&amp;gt; LoadEmployee()
{
    yield return Show.Busy();

    yield return new TaskResult&amp;lt;Employee&amp;gt;().Invoke(LoadEmployeeAsync).ContinueWith(task =&amp;gt; CurrentEmployee = task.Result);

    yield return Show.NotBusy();
} 
&lt;/pre&gt;
&lt;p&gt;This now fully supports calling Task or Task&amp;lt;T&amp;gt; methods and also has its own continuation support. This works right alongside other IResult implementations. Ideas?&lt;/p&gt;</description><pubDate>Tue, 18 Oct 2011 06:35:56 GMT</pubDate><guid isPermaLink="true">http://www.hightech.ir:80/SeeSharp/caliburn-meets-tpl-async</guid></item><item><title>Introduction to WF Designer Rehosting - Part Three</title><link>http://www.hightech.ir:80/SeeSharp/introduction-to-wf-designer-rehosting-part-three</link><description>&lt;p&gt;In &lt;a href="http://hightech.ir/SeeSharp/introduction-to-wf-designer-rehosting-part-two"&gt;previous posts&lt;/a&gt; we saw how to bind our designer properties to our activity and use VB.NET syntax for more complex values. In this post let's see how to show variables and work with namespaces.&lt;/p&gt;
&lt;p&gt;&lt;span class="subtitle"&gt;Importing Namespaces&lt;/span&gt;&lt;br /&gt; If you want to use certain types in your Xaml, you need to import necessary namespaces, as an example our List&amp;lt;T&amp;gt; type is in Sysem.Collections.Generic namespace which needs to be imported for a valid WF Xaml. Let's see how this is done.  When creating the WorkflowDesigner control, you initially need to create an empty workflow, like an empty &lt;a target="_blank" href="http://msdn.microsoft.com/en-us/library/system.workflow.activities.sequenceactivity%28v=vs.90%29.aspx"&gt;Sequence&lt;/a&gt; or &lt;a target="_blank" href="http://msdn.microsoft.com/en-us/library/system.activities.statements.flowchart.aspx"&gt;Flowchart&lt;/a&gt; and feed it to the Load method of the &lt;a target="_blank" href="http://msdn.microsoft.com/en-us/library/system.activities.presentation.workflowdesigner.aspx"&gt;WorkflowDesigner&lt;/a&gt;:&lt;/p&gt;
&lt;pre class="brush:c-sharp"&gt;private void CreateDesigner()
{
    designer = new WorkflowDesigner();
    designer.Load(CreateDefaultSequence());
    designer.Flush();
}

public Sequence CreateDefaultSequence()
{
    var seq = new Sequence {DisplayName = "Empty Sequence"};
    var settings = new VisualBasicSettings();
    var references = new VisualBasicImportReference {Assembly = "System", Import = "System.Collections.Generic"};
	
    settings.ImportReferences.Add(x));
    VisualBasic.SetSettings(seq, settings);

    return seq;
}
&lt;/pre&gt;
&lt;p&gt;Although user can import necessary namespaces using the designer, it'd be ideal to automatically import mostly used namespaces upon designer startup.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Note: Load method of designer accepts "Object" which is ambiguous as the only type of objects I managed to feed it was ActivityBuilder, Sequence and Flowchart.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class="subtitle"&gt;Displaying Variables&lt;/span&gt;&lt;br /&gt; Sometimes you need to allow user to select an existing variable name and bind it to a property of your Activity. How do you do that? Remember the &lt;a target="_blank" href="http://msdn.microsoft.com/en-us/library/system.activities.presentation.model.modelitem.aspx"&gt;ModelItem&lt;/a&gt; property on your designer? The ModelItem property is hierarchical so traversing this you can gain access to the root element of your workflow (here we use a SequenceActivity) where defined variables can be found. ModelItem also has information about the type of the property so you can just select properties of certain type. The following extension method finds all available variables, regardless of their types:&lt;/p&gt;
&lt;pre class="brush:c-sharp"&gt;public static IEnumerable&amp;lt;ModelItem&amp;gt; FindAllVariables(this ModelItem selectedItem)
{
    var variables = new List&amp;lt;ModelItem&amp;gt;();
    while (selectedItem.Parent != null)
    {
        Type parentType = selectedItem.Parent.ItemType;
        if (typeof(System.Activities.Activity).IsAssignableFrom(parentType))
        {
            var mp = selectedItem.Parent.Properties["Variables"];
            if (mp != null &amp;amp;&amp;amp; mp.Collection != null &amp;amp;&amp;amp; mp.PropertyType == typeof(Collection&amp;lt;Variable&amp;gt;))
            {
                mp.Collection.ToList().ForEach(variables.Add);
            }
        }
		
        var dels = selectedItem.Properties.Where(p =&amp;gt; typeof(ActivityDelegate).IsAssignableFrom(p.PropertyType));
        foreach (var actdel in dels)
        {
            if (actdel.Value != null)
            {
                foreach (var innerProp in actdel.Value.Properties)
                {
                    if (typeof(DelegateArgument).IsAssignableFrom(innerProp.PropertyType) &amp;amp;&amp;amp; null != innerProp.Value)
                    {
                        variables.Add(innerProp.Value);
                    }
                }
            }
        }
        selectedItem = selectedItem.Parent;
    }

    return variables;
}
&lt;/pre&gt;
&lt;p&gt;Now to make this easier, let's think what is it that we want to select? We need the name of the variable, along with related ModelItem information, so let's create a Model class to contain this information:&lt;/p&gt;
&lt;pre class="brush:c-sharp"&gt;public class VariableItem : Observable
{
    public VariableItem(string name, ModelItem variable)
    {
        Name = name;
        Variable = variable;
    }

    public string Name { get; set; }

    public ModelItem Variable { get; set; }
}
&lt;/pre&gt;
&lt;p&gt;It is easier now to bind a &lt;a target="_blank" href="http://msdn.microsoft.com/en-us/library/system.windows.controls.combobox.aspx"&gt;ComboBox&lt;/a&gt; to a list of VariableItem instances. All we need to do is to get all the variable of certain types (or all the variables, regardless of their types) as a list of VariableItems and bind it in the designer. This extension method will do the trick for you and has both generic and non-generic flavors:&lt;/p&gt;
&lt;pre class="brush:c-sharp"&gt;public static IEnumerable&amp;lt;VariableItem&amp;gt; FindVariableOfType(this ModelItem selectedItem, Type typeToFind)
{
	var variables = FindAllVariables(selectedItem);
	var found = new Dictionary&amp;lt;string, ModelItem&amp;gt;();

	variables.ForEach(x =&amp;gt;
	{
		var name = x.Properties.GetValue&amp;lt;string&amp;gt;("Name");
		var type = x.Properties.GetValue&amp;lt;Type&amp;gt;("Type");

		if (type == typeToFind)
		{
			found.Add(name, x);
		}
	});

	return found.Select(x =&amp;gt; new VariableItem(x.Key, x.Value));
}

public static IEnumerable&amp;lt;VariableItem&amp;gt; FindVariableOfType&amp;lt;T&amp;gt;(this ModelItem selectedItem)
{
	return FindVariableOfType(selectedItem, typeof (T));
}
&lt;/pre&gt;
&lt;p&gt;Notice ModelItem has information about the variable, like name of the variable and the underlying type of the variable. In next post we'll see how to use complex objects in our activities and how to fill and serialize them to / from xaml from our custom designers.&lt;/p&gt;</description><pubDate>Mon, 26 Sep 2011 18:06:04 GMT</pubDate><guid isPermaLink="true">http://www.hightech.ir:80/SeeSharp/introduction-to-wf-designer-rehosting-part-three</guid></item><item><title>Introduction to WF Designer Rehosting - Part Two</title><link>http://www.hightech.ir:80/SeeSharp/introduction-to-wf-designer-rehosting-part-two</link><description>&lt;p&gt;In &lt;a href="http://hightech.ir/SeeSharp/introduction-to-wf-designer-hosting"&gt;first part&lt;/a&gt; of this serie we saw how to bind our designer properties to activity properties and create a custom designer for our activity. Let's see how to bind to activity properties through the designer and allow user to enter values in the designer.&lt;br /&gt;&lt;br /&gt;If you have some experience with WF Activities you know that input properties are of type &lt;a href="http://msdn.microsoft.com/en-us/library/dd465965.aspx"&gt;InArgument&amp;lt;T&amp;gt;&lt;/a&gt; so how do we convert and bind our regular types to a InArgument&amp;lt;T&amp;gt;?&lt;br /&gt;&lt;br /&gt;Let's go with simple types like String, supposing our SendTo activity has an Enabled property of type InArgument&amp;lt;bool&amp;gt; and we have a CheckBox on our designer. First approach would be to bind directly through ModelItem property of the designer, inherited from the base class by using a &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.data.ivalueconverter.aspx"&gt;ValueConverter&lt;/a&gt;:&lt;/p&gt;
&lt;pre class="brush:xml"&gt;&amp;lt;CheckBox IsChecked="{Binding Path=ModelItem.IsEnabled, Mode=TwoWay, Converter={StaticResource ValueToInArgumentLiteralConverter}}" /&amp;gt;
&lt;/pre&gt;
&lt;pre class="brush:csharp"&gt;public class ValueToInArgumentLiteralConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value != null)
        {
            var modelItem = value as ModelItem;
            if (modelItem != null)
            {
                var expr = modelItem.Properties["Expression"];
                if(expr != null)
                {
                    return expr.Value;
                }
            }
        }

        return null;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value == null) return null;

        var type = typeof (InArgument&amp;lt;&amp;gt;);
        var genericArgument = type.MakeGenericType(value.GetType());
        var argument = Activator.CreateInstance(genericArgument, value);
			
        return argument;
    }
}
&lt;/pre&gt;
&lt;p&gt;This approach works fine but only for simple scenarios. If you want more control on selected properties, changing values, having dependent properties or if your designer UI is complex, I advise using a ViewModel instead. You can access current ModelItem from your view:&lt;/p&gt;
&lt;pre class="brush:csharp"&gt;public interface ISendToDesigner
{
    ModelItem ModelItem { get; }
}

public class SendToViewModel 
{
    public virtual dynamic SelectedModelItem
    {
        get { return View != null ? View.ModelItem : null; }
    }

    public virtual bool IsEnabled
    {
        get { return isEnabled; }
        set
        {
            isEnabled = value;
            RaisePropertyChanged(() =&amp;gt; IsEnabled);
            UpdateModelProperties();
        }
    }

    private void UpdateModelProperties()
    {
        SelectedModelItem.IsEnabled = IsEnabled.ToInArgument();
    }
}
&lt;/pre&gt;
&lt;p&gt;Did you see SelectedModelItem is of &lt;a href="http://msdn.microsoft.com/en-us/library/dd264736.aspx"&gt;dynamic&lt;/a&gt; type? Exposing underlying ModelItem as dynamic allows us to directly assign properties without going through indexers. This trick results in much cleaner and better maintainable code, supposing you have unit tests for your view models! Also I'm using an extension method named &lt;em&gt;ToInArgument&lt;/em&gt; which converts the primitive values to InArgument. Here's the extension method:&lt;/p&gt;
&lt;pre class="brush:csharp"&gt;public static InArgument&amp;lt;T&amp;gt; ToInArgument&amp;lt;T&amp;gt;(this T value)
{
    return new InArgument&amp;lt;T&amp;gt;(value);
} 
&lt;/pre&gt;
&lt;p&gt;This works for primitive values but what if you have Enums, Guids, Lists or Dictionary properties on your Activity? Unfortunately though this seem to work, it won't and designer shows an error. The alternative would be to use &lt;a href="http://msdn.microsoft.com/en-us/library/dd782058.aspx"&gt;VisualBasicValue&amp;lt;T&amp;gt;&lt;/a&gt; instead. If you are a C# developer, welcome yourself to the world of VB.NET!&lt;br /&gt;&lt;br /&gt;Seems VisualBasicValue&amp;lt;T&amp;gt; can be assigned as InArgument&amp;lt;T&amp;gt; so you just need to convert your values to a VisualBasicValue. This approach works file with Enums as well, too bad you can not create an extension method with Enum constraint. Here's an extension method that converts your enum to VisualBasicValue:&lt;/p&gt;
&lt;pre class="brush:csharp"&gt;public static InArgument&amp;lt;T&amp;gt; ToExpression&amp;lt;T&amp;gt;(this T value)
{
    return new VisualBasicValue&amp;lt;T&amp;gt;(string.Format("{0}.{1}", typeof(T).Name, value));
}
&lt;/pre&gt;
&lt;p&gt;Now List and Dictionaries are a little bit different. Let's see how I convert List&amp;lt;Guid&amp;gt; to a VisualBasicValue and you can use the same approach to make it work for all generic types:&lt;/p&gt;
&lt;pre class="brush:csharp"&gt;public static InArgument&amp;lt;List&amp;lt;Guid&amp;gt;&amp;gt; ToExpression(this List&amp;lt;Guid&amp;gt; list)
{
    var expr = "New List(Of Guid) From {{{0}}}";
    var item = list.Select(i =&amp;gt; string.Format("New Guid(\"{0}\")", i));
    var items = string.Join(",", item);

    return new VisualBasicValue&amp;lt;List&amp;lt;Guid&amp;gt;&amp;gt;(string.Format(expr, items));
}
&lt;/pre&gt;
&lt;p&gt;On the &lt;a href="http://hightech.ir/SeeSharp/introduction-to-wf-designer-rehosting-part-three"&gt;next part&lt;/a&gt; of this post, we'll see how to allow user to select existing variables (of a specific types) and import needed namespaces into our workflow xaml.&lt;/p&gt;</description><pubDate>Mon, 26 Sep 2011 18:05:53 GMT</pubDate><guid isPermaLink="true">http://www.hightech.ir:80/SeeSharp/introduction-to-wf-designer-rehosting-part-two</guid></item><item><title>Introduction to WF Designer Rehosting - Part One</title><link>http://www.hightech.ir:80/SeeSharp/introduction-to-wf-designer-hosting</link><description>&lt;p&gt;I've recently been creating custom designer for Workflow Activities and hosting the whole WF designer in a web application. As there is very limited documentation and guide other than Microsoft Forums, here I'll try to shed some lights to some of the problems I have encountered. &lt;br /&gt;&lt;br /&gt;WF 4.0 designer is a set of WPF controls and classes designed with re-hosting in mind, so hosting the designer in an &lt;a target="_blank" href="http://msdn.microsoft.com/en-us/library/aa970060.aspx"&gt;XBAP application&lt;/a&gt; works to some extent without any pain. To start create a WPF (either browser or desktop) application that will be used as your WF Designer. There are a couple of controls you can add to your main window that make it look like out of the box designer:&lt;br /&gt;&lt;br /&gt;Toolbox Control: Is the toolbox control that contains your activities. You can create Categories and place your own and system activities into separate categories.&lt;br /&gt;&lt;br /&gt;Workflow Designer: Is the control that does all the heavy lifting like hosting the activities, generating xaml, loading and saving, etc.&lt;br /&gt;&lt;br /&gt;Property Editor: Workflow designer has a UIElement that is the property editor you can use to edit properties of the workflow/activity.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;div class="center"&gt;&lt;img src="/Media/Default/BlogImages/WF-Designer.jpg" height="415" width="623" /&gt;&lt;/div&gt;
&lt;p&gt;&lt;br /&gt;Let's say you have a &lt;em&gt;Send&lt;/em&gt; activity that sends out an email to selected recipients. You need to create a custom designer for the activity. The good thing is you don't need to anything to the source code of the activity, thanks to &lt;a target="_blank" href="http://msdn.microsoft.com/en-us/library/microsoft.windows.design.metadata.iregistermetadata(v=vs.90).aspx"&gt;IRegisterMetadata&lt;/a&gt; interface, you can add attributes to your activities from the outside. For those familiar with &lt;a target="_blank" href="http://www.hightech.ir/SeeSharp/wpf-controls-design-time-integration"&gt;WPF Design Time integrations&lt;/a&gt;, this is the same thing. To add necessary designer attribute to your Activity, you should do something like this:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;pre class="brush:c-sharp"&gt;public class SendToRegisterer : IRegisterMetadata
{
    [SecurityCritical]
    public void Register()
    {
        var builder = new AttributeTableBuilder();

        builder.AddCustomAttributes(typeof(SendTo), new DesignerAttribute(typeof(SendToDesigner)));
        builder.AddCustomAttributes(typeof(SendTo), "Receiver", new BrowsableAttribute(false));
        builder.AddCustomAttributes(typeof(SendTo), "Subject", new BrowsableAttribute(false));
			
        MetadataStore.AddAttributeTable(builder.CreateTable());
    }
}
&lt;/pre&gt;
&lt;p&gt;There are two things happening here: First we set the designer of &lt;em&gt;SendTo&lt;/em&gt; activity to &lt;em&gt;SendToDesigner&lt;/em&gt;, then we set &lt;a target="_blank" href="http://msdn.microsoft.com/en-us/library/system.componentmodel.browsableattribute.aspx"&gt;BrowsableAttribute&lt;/a&gt; with &lt;em&gt;False&lt;/em&gt; value to the properties of &lt;em&gt;SendTo&lt;/em&gt;. This makes the properties hidden on the property editor so you can make sure user can only interact with your activity through the designer.&lt;br /&gt;&lt;br /&gt;To create the designer class you need to create a WPF UserControl and make it derive from &lt;a target="_blank" href="http://msdn.microsoft.com/en-us/library/system.workflow.componentmodel.design.activitydesigner.aspx"&gt;ActivityDesigner&lt;/a&gt; in http://schemas.microsoft.com/netfx/2009/xaml/activities/presentation namespace. Among many things, this base class has a &lt;a target="_blank" href="http://msdn.microsoft.com/en-us/library/system.activities.presentation.model.modelitem.aspx"&gt;ModelItem&lt;/a&gt; property that allows interacting with the activity that is being displayed. You can bind activity properties to your designer directly using this property or alternatively bind the designer UI to your ViewModel and update the ModelItem property when you want to replicate the changes to the Model Item and update / generate WF Xaml.&lt;br /&gt;&lt;br /&gt;On the &lt;a href="http://hightech.ir/SeeSharp/introduction-to-wf-designer-rehosting-part-two"&gt;next post&lt;/a&gt;, we'll see how to bind designer UI to our activity properties.&lt;/p&gt;</description><pubDate>Mon, 15 Aug 2011 17:32:53 GMT</pubDate><guid isPermaLink="true">http://www.hightech.ir:80/SeeSharp/introduction-to-wf-designer-hosting</guid></item><item><title>Installing Microsoft Dynamics on a XP machine</title><link>http://www.hightech.ir:80/SeeSharp/installing-microsoft-dynamics-on-a-xp-machine</link><description>&lt;p&gt;The other day, I was starting a new gig to integrate an in-house sales system with Microsft Dynamics and naturally I needed to install MSDynamics on my machine. The best option was to install it on a VM so that I get rid of it after the project is done. I decided to install it on a Windows XP machine that needs less resource to run, but I bumped into something interesting:&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;div class="center"&gt;&lt;img src="/Media/Default/BlogImages/MSDynamics-Error.png" alt="Error Message" class="center" width="485" height="125" /&gt;&lt;/div&gt;
&lt;p&gt;&lt;br /&gt;It seems Micorosft Dynamics only installs on your machine if you have connected to a domain controller. But I don't have any domain controller, now what?&lt;/p&gt;
&lt;p&gt;The first solution is to download and install a [trial] version of Windows Server 2003/2008, add your XP machine to the domain, install, and then you are free to kill the domain controller altogether, but all these efforts just to install an application seems ridiculous.&lt;br /&gt;&lt;br /&gt;A better solution was to modify registery keys to fool your OS and make it think you are connected to a domain controller, but the server is not reachable at the moment! To do this, go to this registery key:&lt;/p&gt;
&lt;pre class="brush:text"&gt;HKLM\System\CurrentControlSet\Control\ComputerName\ActiveComputerName
&lt;/pre&gt;
&lt;p&gt;Enter any new name e.g. "VM" into this registery key. Now you also need to set an environment variable. You can do this using command prompt or by going to Control Panel, System, System Properties, Environment Variables. Add a new environment variable under System variables. The variable key is "UserDnsDomain" and you need to enter the same value you have entered in the registery key. You are all set. Run the installation and it will work this time. Remember to revert the registery key back to its original value when you are finished installing.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description><pubDate>Wed, 06 Jul 2011 09:10:42 GMT</pubDate><guid isPermaLink="true">http://www.hightech.ir:80/SeeSharp/installing-microsoft-dynamics-on-a-xp-machine</guid></item><item><title>One day in Kanban Land (Farsi)</title><link>http://www.hightech.ir:80/SeeSharp/one-day-in-kanban-land-farsi</link><description>&lt;p&gt;If you are into &lt;a href="http://en.wikipedia.org/wiki/Agile_software_development"&gt;agile&lt;/a&gt; methodologies, you probably have seen the comic strips "One Day In Kanban Land" by &lt;a href="http://crisp.se/henrik.kniberg"&gt;Henrik Kniberg&lt;/a&gt;. He discussed it in mode depth with us in his Scrum Master course a while ago. This is the Farsi translated version. If you have seen the &lt;a href="http://blog.crisp.se/henrikkniberg/2009/06/26/1246053060000.html"&gt;original one&lt;/a&gt;, or don't speak Farsi, you may skip this post.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div class="center"&gt;&lt;img src="/Media/Default/BlogImages/Kanban1.png" width="516" height="636" /&gt;&lt;br /&gt; &lt;img src="/Media/Default/BlogImages/Kanban2.png" /&gt;&lt;br /&gt; &lt;img src="/Media/Default/BlogImages/Kanban3.png" /&gt;&lt;br /&gt; &lt;img src="/Media/Default/BlogImages/Kanban4.png" /&gt;&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description><pubDate>Mon, 20 Jun 2011 08:39:12 GMT</pubDate><guid isPermaLink="true">http://www.hightech.ir:80/SeeSharp/one-day-in-kanban-land-farsi</guid></item><item><title>WPF Application with Caliburn - Part Four</title><link>http://www.hightech.ir:80/SeeSharp/wpf-application-with-caliburn-part-four</link><description>&lt;p&gt;This is the next serie in the Caliburn tutorials. You can find previous post: &lt;a href="http://hightech.ir/SeeSharp/wpf-application-with-caliburn-part-one"&gt;Part One&lt;/a&gt;, &lt;a href="http://hightech.ir/SeeSharp/wpf-composite-application-with-caliburn-part-two"&gt;Part Two&lt;/a&gt;, &lt;a href="http://hightech.ir/SeeSharp/wpf-applications-with-caliburn-part-three"&gt;Part Three&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;One of the best features of Caliburn framework that I haven't seen in other MVVM frameworks, is a feature called Coroutines. Coroutines are according to Wikipedia:&lt;/p&gt;
&lt;blockquote&gt;In computer science, coroutines are program components that generalize subroutines to allow multiple entry points for suspending and resuming execution at certain locations. Coroutines are well-suited for implementing more familiar program components such as cooperative tasks, iterators,infinite lists and pipes.&lt;/blockquote&gt;
&lt;p&gt;This feature is extremely useful if you do async programming like accessing data over a webservice or execution of long running tasks on the background thread. Let's take a closer look on how to use this feature and how it helps us developing better applications and results in more maintainable code.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Note: This post will work equally on Caliburn 1.1 and 2.0.&lt;br /&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt; &lt;span class="subtitle"&gt;A Recap on Actions&lt;/span&gt;&lt;br /&gt;If you have seen other parts of Caliburn posts, Caliburn facilitates implementing MVVM by eliminating usage of ICommands. Forget about implementing ICommand interface or using RelayCommands. You can not directly bind your events to public actions on your ViewModel class. You no longer are limited by controls having commands, you can bind any arbitrary event to any public method on your ViewModel. Caliburn also checks for any existing preconditions based on the convention. The precondition, called Filters, are properties name the same as your action, but with a "Can" prefix. Here's how it looks to bind:&lt;/p&gt;
&lt;pre class="brush:xml"&gt;&amp;lt;Button cal:Message.Attach="[Event Click] = [Action ShowCustomers]"&amp;gt;
&lt;/pre&gt;
&lt;pre class="brush:c-sharp"&gt;public virtual bool CanShowOrders 
{
    get { return _canShowOrders; }
    set 
    {
        _canShowOrders = value;
        NotifyOfPropertyChanged(() =&amp;gt; CanShowOrders);    
    }
}

public virtual void ShowOrders()
{
    CurrentPresenter = ViewModelFactory.Create&amp;lt;IOrderViewModel&amp;gt;();
}
&lt;/pre&gt;
&lt;p&gt;&lt;span class="subtitle"&gt;&lt;br /&gt;Using Coroutines&lt;/span&gt;&lt;br /&gt;Your action that used to return &lt;em&gt;void&lt;/em&gt; can return a special return type that will be handeld by Caliburn upon execution. If your method returns an instance of &lt;em&gt;IResult &lt;/em&gt;interface it will be treated differently. First let us look at IResult interface:&lt;/p&gt;
&lt;pre class="brush:c-sharp"&gt;public interface IResult  
{  
    void Execute(ActionExecutionContext context);  
    event EventHandler&amp;lt;ResultCompletionEventArgs&amp;gt; Completed;  
}
&lt;/pre&gt;
&lt;p&gt;Very simple to implement! Basically, Execute method is called by Caliburn and this is where you implement the execution logic of this action. Caliburn then pauses unitl your action fires "Completed" event at which point it understands that action has compeleted and is finished. Where's the power, you may ask? Well you can send multiple IResults instanced from your action method by returning an IEnumerable&amp;amp;lt;IResult&amp;amp;gt; and since Caliburn waits for each action to fire its Completed event, all IResult instances are processed sequentially. An example is displaying a progress window, firing up a background worker to do a long running process data and stop progress window when the background worker is finished, let's see how:&lt;/p&gt;
&lt;pre class="brush:c-sharp"&gt;public IEnumerable&amp;lt;IResult&amp;gt; LoadOrders()
{
    yield return ProgressResult.Show("Loading Orders");
    yield return new ServiceFetchResult(...);
    yield return ProgressResult.Hide();
}
&lt;/pre&gt;
&lt;p&gt;And the outcome is that the progress window is still showing until ServiceFetchResult has finished the long running procedure.&lt;/p&gt;
&lt;div class="center"&gt;&lt;img src="/Media/Default/BlogImages/iSales-Progress.png" alt="Progress Window" width="516" height="338" /&gt;&lt;/div&gt;
&lt;p&gt;Remember how specially IResults are treated. In the above example, enumerable items are only processed if the previous one's Completed event is fired. This helps a lot when you do async style programming, specially in Silverlight which almost every outgoing request should run asynchronously. &lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class="subtitle"&gt;Testability&lt;/span&gt;&lt;br /&gt;If you have used an async service, you know how painful it is when it comes down to testing. The problem is how the Async model works, and the easiest way is the same way you connect to webservices in Silverlight: First you subscribe to the event that is called when operation is completed, then you call the async method and wait for it to call you back on the callback handler. If you want to abstract it in an interface, it'd be something like this:&lt;/p&gt;
&lt;pre class="brush:c-sharp"&gt;public class FetchOrdersCompletedEventArgs : AsyncCompletedEventArgs
{
    public FetchOrdersCompletedEventArgs(Exception error, bool cancelled, object userState) 
        : base(error, cancelled, userState)
    {
    }
}

public class OrdersDataClient
{
    public void FetchOrdersAsync()
    {
        //some stuff
    }

    public event EventHandler&amp;lt;FetchOrdersCompletedEventArgs&amp;gt; FetchOrdersCompleted;
}&lt;/pre&gt;
&lt;p&gt;The problem with this code which makes it unsuitable for testing is that you usually generate proxies for your services and this piece of generated code has numerous problems: there's no clean interface and even generated methods are not virtual, making the whole thing unreplaceable in testing (at least by conventional tools). Notice that this implemnentation of async pattern which uses events is much cleaner than the one using IAsyncResult and callbacks, but still not much good in unit testing.&lt;/p&gt;
&lt;p&gt;Now lets sit back and see what is it that we want to test? Let's suppose we want to test that LoadOrders will load orders from the correct service operation, how would we do that?&lt;/p&gt;
&lt;pre class="brush:c-sharp"&gt;[Test]
public void Orders_Are_Loaded_From_Service()
{
    var mockService = Mock&amp;lt;OrdersServiceClient&amp;gt;();

    var vm = new OrderViewModel(mockService);

    vm.LoadOrders();

    mockService.AssertWasCalled(x =&amp;gt; x.FetchOrdersAsync());
}
&lt;/pre&gt;
&lt;p&gt;This code would have worked unless you can't mocked out the service that easily, remember? Now here's how using IResult would help you test the same thing, but with a changed mindset:&lt;/p&gt;
&lt;pre class="brush:c-sharp"&gt;[Test]
public void Orders_Are_Loaded_From_Service()
{
    var vm = new OrderViewModel();

    var results = vm.LoadOrders().ToList();
    var fetchRequest = results[1] as ServiceFetchResult;
            
    Assert.NotNull(fetchRequest);
    Assert.That(fetchRequest.Action.Method.Name, Is.EqualTo("FetchOrdersAsync"));
}
&lt;/pre&gt;
&lt;p&gt;&lt;span class="subtitle"&gt;&lt;br /&gt;Conclusion&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;If you need to go through this in more detail, feel free to grab the &lt;a target="_blank" href="/Files/iSales - Using IResults.zip"&gt;source code&lt;/a&gt; of this part from here. This one uses the latest Caliburn 2.x version. We'll cover how to migrate from version 1.5 in the next post.&lt;/p&gt;</description><pubDate>Mon, 06 Jun 2011 05:27:30 GMT</pubDate><guid isPermaLink="true">http://www.hightech.ir:80/SeeSharp/wpf-application-with-caliburn-part-four</guid></item><item><title>Farsi Library - Version 2.0 now available</title><link>http://www.hightech.ir:80/SeeSharp/farsi-library-version-20-now-available</link><description>&lt;p&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_Z5KTIfnfuNs/SAM_56lN6GI/AAAAAAAAACU/DdSClSDHBkc/s1600-h/FAMonthView.png"&gt;&lt;img style="margin: 0pt 0pt 10px 10px; float: right; cursor: pointer;" src="http://2.bp.blogspot.com/_Z5KTIfnfuNs/SAM_56lN6GI/AAAAAAAAACU/DdSClSDHBkc/s320/FAMonthView.png" id="BLOGGER_PHOTO_ID_5189061459871393890" border="0" /&gt;&lt;/a&gt;Version 2.0 of FarsiLibrary is now available. The following changes are made in this release :&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="color: #ff0000;"&gt;Modified &lt;/span&gt;: Migrated to Visual Studio .NET 2008. Still using .NET Framework 2.0, so you just need the new IDE to compile. Might affect clients using old .NET Framework 2.0 (without the new SP Installed).&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="color: #ff0000;"&gt;Modified &lt;/span&gt;: IComparer and IComparer
&lt;persiandate&gt; are converted to explicit implementation in PersianDate class.&lt;/persiandate&gt;&lt;br /&gt;
&lt;persiandate&gt;&lt;br /&gt;&lt;/persiandate&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="color: #ff0000;"&gt;Modified &lt;/span&gt;: ICloneable interface implementation is converted to explicit implementation in PersianDate class.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="color: #ff0000;"&gt;Modified &lt;/span&gt;: Assign method of PersianDate to internal.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="color: #ff0000;"&gt;Modified &lt;/span&gt;: Changed the Day/Month/Year change eventhandler type to EventHandler&lt;datechangedeventargs&gt;. You can use the New/Old value properties to access the underlying values.&lt;br /&gt;&lt;br /&gt;&lt;/datechangedeventargs&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="color: #ff0000;"&gt;Modified &lt;/span&gt;: FALocalizeManager now is a singleton class. Use the Instance property instead of static methods.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="color: #ff0000;"&gt;Modified &lt;/span&gt;: FAMessageBoxManager.Delete method now returns boolean value based on whether the delete operation was successful or not.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="color: #3366ff;"&gt;Added &lt;/span&gt;: Implementation of IsLeapMonth method in PersianCalendar.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="color: #3366ff;"&gt;Added &lt;/span&gt;: Solution Items folder.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="color: #3366ff;"&gt;Added &lt;/span&gt;: Partial Office 2007 Blue theme. Drawing of dropdown buttons of FADatePicker control need a better visualization.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="color: #3366ff;"&gt;Added &lt;/span&gt;: PainterFactory to create painters based on the state of BaseStyledControl.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="color: #3366ff;"&gt;Added &lt;/span&gt;: FAMessageBox now implementes IDisposable interface explicitly. Dispose method is made internal.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="color: #006600;"&gt;Fixed &lt;/span&gt;: When changing the culture, Year value didn't change, e.g. when in Farsi culture in year 1385 culture is set to english, the year remain 1385 (which was a valid year in English calendar).&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="color: #006600;"&gt;Fixed &lt;/span&gt;: When changing the DefaultCulture property, Day and Month properties did not return the culture-specific values.&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="color: #006600;"&gt;Fixed&lt;/span&gt;&lt;span style="color: #006600;"&gt; &lt;/span&gt;: A bug when accessing Now property of PersianDate class.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;br /&gt;Please report any bug you might encounter. You can download the source code from &lt;a href="http://blog.hightech.ir/BlogFiles/FarsiLibrary_2.0_Src.zip"&gt;here&lt;/a&gt; and the binary (including test project executables) from &lt;a href="http://blog.hightech.ir/BlogFiles/FarsiLibrary_2.0_Release.zip"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;More information about this project can be found on my Code Project article at &lt;a href="http://www.codeproject.com/KB/selection/FarsiLibrary.aspx"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;div class="blogger-post-footer"&gt;&lt;img src="https://blogger.googleusercontent.com/tracker/6069495622049300789-5588888989458478956?l=heskandari.blogspot.com" height="1" width="1" /&gt;&lt;/div&gt;</description><pubDate>Fri, 27 May 2011 12:08:12 GMT</pubDate><guid isPermaLink="true">http://www.hightech.ir:80/SeeSharp/farsi-library-version-20-now-available</guid></item><item><title>Resharper 4.0 Released</title><link>http://www.hightech.ir:80/SeeSharp/resharper-40-released</link><description>&lt;p&gt;You need to wait no longer! Resharper 4.0 is here.&lt;br /&gt;&lt;br /&gt;Besides Support for C# 3.0, LINQ and XAML, which is great, there are lots of other enhancements in this release which makes it a "Must Have". Did I mention my little favorite feature, &lt;a href="http://www.jetbrains.com/resharper/features/newfeatures.html"&gt;CamelHumps&lt;/a&gt; is also there? To get your hands dirty and know what's new in this release, check the Product's overview page &lt;a href="http://www.jetbrains.com/resharper/"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;div class="blogger-post-footer"&gt;&lt;img src="https://blogger.googleusercontent.com/tracker/6069495622049300789-5424385764723577835?l=heskandari.blogspot.com" height="1" width="1" /&gt;&lt;/div&gt;</description><pubDate>Fri, 27 May 2011 11:57:18 GMT</pubDate><guid isPermaLink="true">http://www.hightech.ir:80/SeeSharp/resharper-40-released</guid></item><item><title>NHibernate 2.0 Released</title><link>http://www.hightech.ir:80/SeeSharp/nhibernate-20-released</link><description>&lt;p&gt;The good news, after not-so-good news about &lt;a href="http://www.simple-talk.com/the_future_of_reflector" target="_blank"&gt;Reflector&lt;/a&gt;, is that NHibernate 2.0 is finally released. This version's feature is comparable with Java Hibernate 3.2 so, this might be a giant step forward. If you're new to NHibernate, you definitely want to check out the &lt;a href="http://www.summerofnhibernate.com"&gt;http://www.summerofnhibernate.com&lt;/a&gt; web site, which contains screencasts that will minimize your learning curve. There'll be some sessions regarding new features of NHibernate 2.0, so keep an eye out.&lt;/p&gt;
&lt;div class="blogger-post-footer"&gt;&lt;img src="https://blogger.googleusercontent.com/tracker/6069495622049300789-2482576446643553449?l=heskandari.blogspot.com" height="1" width="1" /&gt;&lt;/div&gt;</description><pubDate>Fri, 27 May 2011 11:56:43 GMT</pubDate><guid isPermaLink="true">http://www.hightech.ir:80/SeeSharp/nhibernate-20-released</guid></item><item><title>Enhanced INotifyPropertyChanged - Revisited</title><link>http://www.hightech.ir:80/SeeSharp/enhanced-inotifypropertychanged-revisited</link><description>&lt;p&gt;A while a go, I had a post regarding how to implement the INotifyPropertyChanged event in a more proper fashion. You didn't have to hard-code the property name, and could instead use a linq expression, which with a help of an extension method, the name of the property is easily extracted, and passed to raise the PropertyChanged event. Simple, right?&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue;"&gt;public static class &lt;/span&gt;&lt;span style="color: #2b91af;"&gt;EventExtension&lt;br /&gt;&lt;/span&gt;{&lt;br /&gt;  &lt;span style="color: blue;"&gt;public static void &lt;/span&gt;Notify&amp;lt;T, TValue&amp;gt;(&lt;span style="color: blue;"&gt;this &lt;/span&gt;T instance, &lt;span style="color: #2b91af;"&gt;PropertyChangedEventHandler &lt;/span&gt;handler, &lt;span style="color: #2b91af;"&gt;Expression&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af;"&gt;Func&lt;/span&gt;&amp;lt;T, TValue&amp;gt;&amp;gt; selector)&lt;br /&gt;     &lt;span style="color: blue;"&gt;where &lt;/span&gt;T : &lt;span style="color: #2b91af;"&gt;INotifyPropertyChanged&lt;br /&gt;  &lt;/span&gt;{&lt;br /&gt;      &lt;span style="color: blue;"&gt;if &lt;/span&gt;(handler != &lt;span style="color: blue;"&gt;null&lt;/span&gt;)&lt;br /&gt;      {&lt;br /&gt;          &lt;span style="color: blue;"&gt;var &lt;/span&gt;memberExpression = selector.Body &lt;span style="color: blue;"&gt;as &lt;/span&gt;&lt;span style="color: #2b91af;"&gt;MemberExpression&lt;/span&gt;;&lt;br /&gt;          &lt;span style="color: blue;"&gt;if &lt;/span&gt;(memberExpression == &lt;span style="color: blue;"&gt;null&lt;/span&gt;)&lt;br /&gt;              &lt;span style="color: blue;"&gt;throw new &lt;/span&gt;&lt;span style="color: #2b91af;"&gt;InvalidOperationException&lt;/span&gt;(&lt;span style="color: #a31515;"&gt;"selector should be a MemberExpression."&lt;/span&gt;);&lt;br /&gt;&lt;br /&gt;          handler(instance, &lt;span style="color: blue;"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af;"&gt;PropertyChangedEventArgs&lt;/span&gt;(memberExpression.Member.Name));&lt;br /&gt;      }&lt;br /&gt;  }&lt;br /&gt;}&lt;/pre&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue;"&gt;public abstract class &lt;/span&gt;&lt;span style="color: #2b91af;"&gt;NotificationAwareBase &lt;/span&gt;: &lt;span style="color: #2b91af;"&gt;INotifyPropertyChanged&lt;br /&gt;&lt;/span&gt;{&lt;br /&gt;  &lt;span style="color: blue;"&gt;public event &lt;/span&gt;&lt;span style="color: #2b91af;"&gt;PropertyChangedEventHandler &lt;/span&gt;PropertyChanged;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue;"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af;"&gt;Customer &lt;/span&gt;: &lt;span style="color: #2b91af;"&gt;NotificationAwareBase&lt;br /&gt;&lt;/span&gt;{&lt;br /&gt;  &lt;span style="color: blue;"&gt;private string &lt;/span&gt;_Name;&lt;br /&gt;&lt;br /&gt;  &lt;span style="color: blue;"&gt;public string &lt;/span&gt;Name&lt;br /&gt;  {&lt;br /&gt;      &lt;span style="color: blue;"&gt;get &lt;/span&gt;{ &lt;span style="color: blue;"&gt;return &lt;/span&gt;_Name; }&lt;br /&gt;      &lt;span style="color: blue;"&gt;set&lt;br /&gt;      &lt;/span&gt;{&lt;br /&gt;          _Name = &lt;span style="color: blue;"&gt;value&lt;/span&gt;;&lt;br /&gt;          &lt;span style="color: blue;"&gt;this&lt;/span&gt;.Notify(base.PropertyChanged, o =&amp;gt; o.Name);&lt;br /&gt;      }&lt;br /&gt;  }&lt;br /&gt;}&lt;/pre&gt;
&lt;p&gt;Should work like a charm, right? WRONG! you'll end up with a compile time error. It is like the extension method does not like my inherited PropertyChanged event. The drawback to the latter method was that you could not use it in inheritance context.&lt;/p&gt;
&lt;p&gt;I need to implement INotifyPropertyChanged only once (&lt;a href="http://www.martinfowler.com/eaaCatalog/layerSupertype.html"&gt;Layer Supertype&lt;/a&gt;, anyone?). I had to come up with something to be able to work in inheritance context. Finally, here's it :&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue;"&gt;public abstract class &lt;/span&gt;&lt;span style="color: #2b91af;"&gt;NotificationAware &lt;/span&gt;: &lt;span style="color: #2b91af;"&gt;INotifyPropertyChanged&lt;br /&gt;&lt;/span&gt;{&lt;br /&gt;  &lt;span style="color: blue;"&gt;private event &lt;/span&gt;&lt;span style="color: #2b91af;"&gt;PropertyChangedEventHandler &lt;/span&gt;propertyChangedEvent;&lt;br /&gt;&lt;br /&gt;  &lt;span style="color: blue;"&gt;public event &lt;/span&gt;&lt;span style="color: #2b91af;"&gt;PropertyChangedEventHandler &lt;/span&gt;PropertyChanged&lt;br /&gt;  {&lt;br /&gt;      &lt;span style="color: blue;"&gt;add&lt;br /&gt;      &lt;/span&gt;{&lt;br /&gt;          propertyChangedEvent += &lt;span style="color: blue;"&gt;value&lt;/span&gt;;&lt;br /&gt;      }&lt;br /&gt;      &lt;span style="color: blue;"&gt;remove&lt;br /&gt;      &lt;/span&gt;{&lt;br /&gt;          propertyChangedEvent -= &lt;span style="color: blue;"&gt;value&lt;/span&gt;;&lt;br /&gt;      }&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;&lt;span style="color: gray;"&gt;   &lt;/span&gt;&lt;span style="color: blue;"&gt;protected void &lt;/span&gt;Notify&amp;lt;T&amp;gt;(T obj, &lt;span style="color: #2b91af;"&gt;Expression&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af;"&gt;Func&lt;/span&gt;&amp;lt;T, &lt;span style="color: blue;"&gt;object&lt;/span&gt;&amp;gt;&amp;gt; selector)&lt;br /&gt;  {&lt;br /&gt;      &lt;span style="color: blue;"&gt;if &lt;/span&gt;(propertyChangedEvent != &lt;span style="color: blue;"&gt;null&lt;/span&gt;)&lt;br /&gt;      {&lt;br /&gt;          &lt;span style="color: #2b91af;"&gt;MemberExpression &lt;/span&gt;memberExpression = selector.Body &lt;span style="color: blue;"&gt;as &lt;/span&gt;&lt;span style="color: #2b91af;"&gt;MemberExpression&lt;/span&gt;;&lt;br /&gt;          &lt;span style="color: blue;"&gt;if &lt;/span&gt;(memberExpression == &lt;span style="color: blue;"&gt;null&lt;/span&gt;)&lt;br /&gt;          {&lt;br /&gt;              &lt;span style="color: #2b91af;"&gt;UnaryExpression &lt;/span&gt;unary = selector.Body &lt;span style="color: blue;"&gt;as &lt;/span&gt;&lt;span style="color: #2b91af;"&gt;UnaryExpression&lt;/span&gt;;&lt;br /&gt;              &lt;span style="color: blue;"&gt;if &lt;/span&gt;(unary != &lt;span style="color: blue;"&gt;null&lt;/span&gt;)&lt;br /&gt;              {&lt;br /&gt;                  memberExpression = unary.Operand &lt;span style="color: blue;"&gt;as &lt;/span&gt;&lt;span style="color: #2b91af;"&gt;MemberExpression&lt;/span&gt;;&lt;br /&gt;              }&lt;br /&gt;          }&lt;br /&gt;&lt;br /&gt;          &lt;span style="color: blue;"&gt;if&lt;/span&gt;(memberExpression == &lt;span style="color: blue;"&gt;null&lt;/span&gt;)&lt;br /&gt;              &lt;span style="color: blue;"&gt;throw new &lt;/span&gt;&lt;span style="color: #2b91af;"&gt;ArgumentException&lt;/span&gt;(&lt;span style="color: #a31515;"&gt;"member should be of MemberExpression type"&lt;/span&gt;, &lt;span style="color: #a31515;"&gt;"selector"&lt;/span&gt;);&lt;br /&gt;        &lt;br /&gt;&lt;br /&gt;          propertyChangedEvent(&lt;span style="color: blue;"&gt;this&lt;/span&gt;, &lt;span style="color: blue;"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af;"&gt;PropertyChangedEventArgs&lt;/span&gt;(memberExpression.Member.Name));&lt;br /&gt;      }&lt;br /&gt;  }&lt;br /&gt;}&lt;/pre&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue;"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af;"&gt;Customer &lt;/span&gt;: &lt;span style="color: #2b91af;"&gt;NotificationAware&lt;br /&gt;&lt;/span&gt;{&lt;br /&gt;  &lt;span style="color: blue;"&gt;private string &lt;/span&gt;_Name;&lt;br /&gt;  &lt;span style="color: blue;"&gt;public string &lt;/span&gt;Name&lt;br /&gt;  {&lt;br /&gt;      &lt;span style="color: blue;"&gt;get &lt;/span&gt;{ &lt;span style="color: blue;"&gt;return &lt;/span&gt;_Name; }&lt;br /&gt;      &lt;span style="color: blue;"&gt;set&lt;br /&gt;      &lt;/span&gt;{&lt;br /&gt;          _Name = &lt;span style="color: blue;"&gt;value&lt;/span&gt;;&lt;br /&gt;          Notify(&lt;span style="color: blue;"&gt;this&lt;/span&gt;, o =&amp;gt; o.Name);&lt;br /&gt;      }&lt;br /&gt;  }&lt;br /&gt;}&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;Happy coding!&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;div class="blogger-post-footer"&gt;&lt;img src="https://blogger.googleusercontent.com/tracker/6069495622049300789-2182640116127663255?l=heskandari.blogspot.com" height="1" width="1" /&gt;&lt;/div&gt;</description><pubDate>Fri, 27 May 2011 11:55:02 GMT</pubDate><guid isPermaLink="true">http://www.hightech.ir:80/SeeSharp/enhanced-inotifypropertychanged-revisited</guid></item></channel></rss>