The default site created by the System.ComponentModel.Container class does not pass service requests (IServiceProvider.GetService()) to its container unless the requested service is of type ISite. That's just batty, because anyone trying to get the site this way won't get it, and anyone trying to get any other service from the container won't get it.

The offending code is in Container.cs:

105     if (typeof(ISite) != t) {
106         return null;
107     }

The fix is simple:

105     if (typeof(ISite) == t) {
106         return this;
107     }

I've also attached a test program so you can see the difference between the .NET implementation and the Mono implementation of this class.

--Brian
using System;
using System.ComponentModel;
using System.ComponentModel.Design;

namespace Test {
        class MainClass {
                public static void Main() {
                        TestContainer container = new TestContainer();
                        Console.WriteLine( "// Results should be not null" );
                        
                        container.Add( new TestComponent() );
                        
                        Console.ReadLine();
                }
        }
        
        class TestService {
        }
        
        class TestContainer : Container {
                ServiceContainer _services = new ServiceContainer();
                
                public TestContainer() {
                        _services.AddService( typeof(TestService), new 
TestService() );
                }
                
                protected override object GetService( Type serviceType ) {
                        return _services.GetService( serviceType );
                }
        }
        
        class TestComponent : Component {
                public override ISite Site {
                        get {
                                return base.Site;
                        }
                        set {
                                base.Site = value;
                                
                                if( value != null ) {
                                        Console.WriteLine( "ISite request 
result is {0}",
                                                (value.GetService( 
typeof(ISite) ) == null) ? "null" : "not null" );
                                        Console.WriteLine( "TestService request 
result is {0}",
                                                (value.GetService( 
typeof(TestService) ) == null) ? "null" : "not null" );
                                }
                        }
                }
        }
}

_______________________________________________
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list

Reply via email to