Click here to Skip to main content
       

C#

 
GeneralRe: GridView FindControl LINQ Update PinmemberRickSharp14-Feb-13 6:43 
GeneralRe: GridView FindControl LINQ Update PinmvpRichard MacCutchan14-Feb-13 6:58 
GeneralRe: GridView FindControl LINQ Update PinmemberRickSharp14-Feb-13 10:31 
GeneralRe: GridView FindControl LINQ Update PinmemberRickSharp14-Feb-13 13:28 
QuestionC# Cannot access a disposed object Pinmemberclassy_dog13-Feb-13 8:06 
AnswerRe: C# Cannot access a disposed object PinprotectorPete O'Hanlon13-Feb-13 8:13 
AnswerRe: C# Cannot access a disposed object Pinmemberjschell13-Feb-13 10:15 
QuestionIDisposable spread PinmemberOrjan Westin13-Feb-13 2:45 
When reading about IDisposable, I get the impression that the consensus is that once you introduce it, everything that's even heard about it need to be made IDisposable too. Can this really be correct?
 
I have a class DriverWrapper that holds an IntPtr to a DLL with a C interface. This class is IDisposable, and implements the standard Dispose pattern, with a finaliser. It also has a number of abstract functions, some delegate definitions, and a helper function to get a delegate from the loaded DLL.
 
From this class, I derive some other classes, which implements the abstract functions by creating delegates to DLL functions. (The reason for this is that I have three related DLLs, all doing effectively the same thing to different bits of hardware, so to a user in the application it makes sense that they all have the same, shared interface. Unfortunately, the DLLs have different names, and in some cases different signatures, for their functions.)
 
Now, the derived classes are already IDisposable from DriverWrapper, but if they only hold delegates, which aren't IDisposable themselves, is there any need to override Dispose(bool) in these? I think not, but I'm no expert on C#.
 
(Oh, and I'm not concerned with the using idiom, as these will be alive throughout the lifetime of their owner. Neither am I interested in whether I should implement it in case I will at some future point have a managed and disposable member, or hypotheticals like that.)
 
Next question:
There is an abstract base class Model which takes a DriverWrapper as a constructor parameter, and takes ownership of it. The classes derived from this only override one function, and are just meant to provide different types of DriverWrapper-derived classes. I'll need to have access to the DriverWrapper for the whole lifetime of the Model.
 
abstract class Model
{
  DriverWrapper theDriver;
 
  Model(DriverWrapper driver)
  {
    theDriver = driver;
  }
  ...
}
 
class DriverWrapper : IDisposable
{ 
  ~DriverWrapper()
  
  void Dispose()
  
  void Dispose(bool)
}
 
class DriverA : DriverWrapper
{ ... }
 
class DriverB : DriverWrapper
{ ... }
 
class DriverC : DriverWrapper
{ ... }
 
class ModelA : Model
{
  public ModelA()
  : base (new DriverA())
  {}
}
 
Would Model have to be IDisposable? Surely the DriverWrapper is now managed, and will be tidied away when the Model is? If not, would ModelA-C need to override Dispose even if they have no further data?
 
(Honestly, at times like this I really miss RAII and typedefs from C++)
AnswerRe: IDisposable spread PinmentorDaveyM6913-Feb-13 4:52 
AnswerRe: IDisposable spread PinmentorKeith Barrow13-Feb-13 5:13 
GeneralRe: IDisposable spread PinmemberPIEBALDconsult13-Feb-13 17:46 
GeneralRe: IDisposable spread PinmemberN a v a n e e t h13-Feb-13 18:59 
GeneralRe: IDisposable spread PinmemberOrjan Westin13-Feb-13 22:33 
AnswerRe: IDisposable spread PinmemberN a v a n e e t h13-Feb-13 18:56 
AnswerRe: IDisposable spread PinmemberBobJanova13-Feb-13 23:54 
Questionpropertygrid double click events Pinmemberjone.cunha13-Feb-13 0:56 
AnswerRe: propertygrid double click events PinmvpRichard MacCutchan13-Feb-13 1:14 
GeneralRe: propertygrid double click events Pinmemberjone.cunha13-Feb-13 1:24 
GeneralRe: propertygrid double click events PinmvpRichard MacCutchan13-Feb-13 1:44 
GeneralRe: propertygrid double click events Pinmemberjone.cunha13-Feb-13 1:53 
GeneralRe: propertygrid double click events PinmvpRichard MacCutchan13-Feb-13 3:16 
GeneralRe: propertygrid double click events Pinmemberjone.cunha13-Feb-13 4:45 
GeneralRe: propertygrid double click events PinmvpRichard MacCutchan13-Feb-13 5:38 
GeneralRe: propertygrid double click events Pinmemberjone.cunha13-Feb-13 7:32 
QuestionEnevts in MVC application. Need some Help. Pinmemberplywoods12-Feb-13 21:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 25 Jul 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid