Message Cleanup


The Message type implements IDisposable and defines a Close method. In a strange twist of architectural decision making, the Dispose member of the Message type is implemented explicity, thereby preventing its use directly from the Message type. Calling the Dispose method on a Message object requires first casting the Message object to an IDisposable object and then calling Dispose through that reference. Further complicating this twist is the fact that the Close method is implemented as a publicly visible instance method. In essence, you can call the Close method on a Message object, but you cannot call the Dispose method directly. Internally, the Dispose method calls the Close method, so it functionally works, and you can still wrap Message instantiation in the C# using statement.

Note 

In my view, IDisposable is not implemented properly in the Message type. All standards that I know of, including the ones stated in the Framework Design Guidelines, state that interface methods should seldom be implemented explicitly, and I know of no standard that accepts a Close method without a similarly visible Dispose method. Although this was done with the aim of reducing developer confusion about Close/Dispose, I think that the Message type makes an existing problem worse, not better. Developers have come to expect to see a Dispose method on types, and occasionally a Close method. I know of no other type in the Microsoft .NET Framework that hides Dispose and exposes Close.




Inside Windows Communication Foundation
Inside Windows Communication Foundation (Pro Developer)
ISBN: 0735623066
EAN: 2147483647
Year: 2007
Pages: 106
Authors: Justin Smith

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net