Bug 5470 - Cairo.Context IDisposable casting
Summary: Cairo.Context IDisposable casting
Status: RESOLVED NOT_ON_ROADMAP
Alias: None
Product: Class Libraries
Classification: Mono
Component: Mono.Cairo ()
Version: unspecified
Hardware: PC Windows
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-06-02 13:14 UTC by pinggi
Modified: 2012-06-19 16:25 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED NOT_ON_ROADMAP

Description pinggi 2012-06-02 13:14:52 UTC
I have encountered one 'strangeness':

	Cairo.Context ctx = new Cairo.Context(cairoImageSurface);
	((IDisposable)ctx).Dispose();

Why do I need to cast cairo context to IDisposable to be able to call Dispose method?
What is the reason, because I would expect something like this:

	Cairo.Context ctx = new Cairo.Context(cairoImageSurface);
	ctx.Dispose();
Comment 1 Miguel de Icaza [MSFT] 2012-06-19 15:37:01 UTC
Good observation, I am not aware of the background for this, but I suspect whoever wrote it wanted to encourage this pattern:

using (var ctx = new Cairo.Context (surface)){
   [...]
}

Which does not require the manual call to Dispose.
Comment 2 pinggi 2012-06-19 16:25:08 UTC
Really interesting way of 'encouraging this pattern'. 

Well, it is obvious that the developers should use the 'using' construction if an object contains the 'Dispose' method. But it isn't if it doesn't contain.

Developers don't know when to use disposing pattern because they don't know that  the object is disposable :)

I personaly don't open 'Assembly browser' for every object to find out if it implements IDisposable. Therefore, I don't understand how it could be the right way.