江南白衣

陌上發花,可以緩緩醉矣
忍把浮名,換了淺斟低唱
我不是聖賢豪士,我衹有一腔熱血
posts - 112, comments - 418, trackbacks - 14, articles - 0
  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理

2008年7月11日

     摘要: 刚刚出炉的,暂时放首页:) Microsoft Visual Studio 2008 Service Pack 1 (iso) http://www.microsoft.com/downloads/details.aspx?displaylang=zh-cn&FamilyID=27673c47-b3b5-4c67-bd99-84e525b5ce61 Visual Studio 2008 Team Foundation Server Service Pack 1(iso) http://www.microsoft.com/downloads/details.aspx?displaylang=zh-cn&FamilyID=9e40a5b6-da41-43a2-a06d-3cee196bfe3d Microsoft .NET Framework 3.5 Service Pack 1 http://www.microsoft.com/downloads/details.aspx?displaylang=zh-cn&FamilyID=ab99342f-5d1a-413d-8  阅读全文

posted @ 2008-08-12 00:27 江南白衣 阅读(3701) | 评论 (75)编辑

     摘要: Alright, I've purposely hid the View to Presenter communication in my previous posts on Supervising Controller and Passive View because I thought that subject was worthy of its own post. As I see it, there are 2 1/2 basic ways to communicate screen events back to the Presenter. Expose events off of the IView interface. Jeffrey Palermo has told me before that he will do something very similar, but attaches delegates through setter properties instead. I'm calling that technique the "1/2" bec  阅读全文

posted @ 2008-08-02 19:40 江南白衣 阅读(78) | 评论 (0)编辑

原文:http://www.ayende.com/Blog/archive/2006/07/25/7397.aspx

 

Let us assume that you have the following class hierarchy:

(Image from clipboard).png

Now, what do you think the result of this code will be?

 

BindingList<Animal> animals = new BindingList<Animal>();

animals.Add(new Dog());

animals.Add(new Cat());

GridView gridView = new GridView();

gridView.DataSource = animals;

gridView.DataBind();

 

Ten points goes to the lady on the right that said that it will produce the following error:

Unhandled Exception: System.Reflection.TargetInvocationException: Property accessor 'Name' on object 'AnimalDesc.Cat' threw the following exception:'Object does not match target type.' ---> System.Reflection.TargetException: Object does not match target type.

The reason for this bug is that the TypeDescriptors in .Net are not aware of polymorphism. Even though both Cat and Dog inherit from Animal and has a Name property, and that the list that I passed to the DataSource is BindingList<T>, the TypeDescriptor only looks at the first item in the list, and uses it to describe all types in the list. This can cause problems when the collection that you pass to the GridView contains an inheritance hierarchy.

After butting my head against this issue for too long, I finally came up with this solution:

 

public class AnimalTypeDescriptionProvider : TypeDescriptionProvider

{

    public AnimalTypeDescriptionProvider() 

        :base(TypeDescriptor.GetProvider(typeof(Animal)))

    {

    }

 

    public override Type GetReflectionType(Type objectType, object instance)

    {

        return base.GetReflectionType(typeof(Animal), instance);

    }

 

    public override ICustomTypeDescriptor GetTypeDescriptor(Type objectType, object instance)

    {

        return base.GetTypeDescriptor(typeof(Animal), instance);

    }

   

    public static void Register()

    {

        TypeDescriptor.AddProvider(new AnimalTypeDescriptionProvider(), typeof(Animal));

    }

}

 

Then, I call the AnimalTypeDescriptionProvider.Register(); method in the start of the application.

What this does is it lies to the data binding infrastructure, and tells them that any type that inherits from Animal is actually an Animal, and should be treated appropriately.

This solution is good enough for now, but it will prevent me from databinding a list of Dogs, for instance.

posted @ 2008-08-02 18:46 江南白衣 阅读(32) | 评论 (0)编辑

     摘要: In the development of the Composite Application Guidance one area that we have labored intensely was around documentation. Documentation was so high on our priority list, that we deliberately reduced the number of bells and whistles in order to allow us to properly document what we had. As part of this we put in a significant effort to provide overview level information. We heard a lot of feedback from customers on the need for us to provide much more of the "Why" rather than the "What". Our hop  阅读全文

posted @ 2008-08-02 14:13 江南白衣 阅读(34) | 评论 (0)编辑

     摘要: Occasionally this question pops up on the CAB message boards: How do I prevent my application from closing if the user has unsaved changes? Turns out that there’s a very simple pattern you can utilize to handle this situation. It’s called the Notification Pattern. Jeremy Miller, .Net guru, has a very good blog post on this pattern. He uses it to illustrate a standard way to handle validation on domain objects, but it’s a valuable pattern in other cases too, as I’ll show.   阅读全文

posted @ 2008-08-02 02:34 江南白衣 阅读(41) | 评论 (0)编辑

     摘要: This article is all about using the .NET 3.5 System.Addin namespace. This article owes much to the fabulous WPF book by Mathew McDonald (Who is an uber genius in my opinion).   阅读全文

posted @ 2008-07-15 21:07 江南白衣 阅读(137) | 评论 (0)编辑

    sourceforge被和谐了,下一个会是谁呢?
    sourceforge是什么?去sourceforge的人都是些什么人?那些傻逼和白痴们以为区区一道墙就能阻挡得了这些人了嘛?
    更早的一些时候,我们伟大的祖先建立了那道伟大的墙,结果如何?伟大的汉族文明却被墙外的铁骑一而再再而三地翻墙而过继而狠狠地踏在脚底!
    我们热爱民族,我们热爱祖国,我们是成年人,我们接受过足以明辨是非的教育,我们对自己的行为负责。可是,我们不需要如此暴力而傻逼的对待!
 
   Tor,就像是雨衣,穿着洗澡真他妈不是滋味。但是,澡还是要洗的,对吧?

   

posted @ 2008-07-11 20:58 江南白衣 阅读(147) | 评论 (2)编辑