Jump to content
Xtreme .Net Talk

Question about design issues (classes using dynamic class members)


Recommended Posts

Posted (edited)

Sort of hard for me to explain since I'm new to these concepts, but I'll try.

 

DataTable uses a DataView. However the DataTable only lets you get it's DefaultView (you cannot set it), and DataView lets you get or set the DataTable in which it belongs to.

 

I'm curious as to how the DataTable knows which DataView it belongs to. Is there an internal (for C#) reference for _dataView which DataView sets? Or is it handled differently?

 

ie;

 

// In DataView class.

public DataTable 
{
  get {
     return _table;
  }
  set {
     // The old Table is no longer using this DataView.
     _table.DataView = null;

     _table = value;
     _table.DataView = this;
     // Note: DataView is an internal property.
  }
}

// In DataTable class.

internal DataView 
{
  get {
     return _dataView;
  }
  set {
     _dataView = value;
  }
}

public DefaultView 
{
  get {
     return _dataView;
  }
}

 

I'm working on something similar. The ability to change dynamically how a class looks or is used based on a member class that it references. However I don't want the user to ruin the relationship by being able to set the Table's DefaultView to null or something else, which would leave the DataView.Table property pointing to a Table that doesn't use it. Or by setting the DataView.Table property to a Table, but not updating the Table.DefaultView, which would make the Table.DefaultView point to a DataView which it doesn't control.

 

What's the best way to handle this? How does the Table/DataView relationship work under the hood? The internal example I gave above still seems prone a little prone to error.

 

Thanks in advance.

Edited by wyrd
Gamer extraordinaire. Programmer wannabe.
  • *Experts*
Posted
Your way is probably the easiest. I don't think it's quite the method that the DataTable uses though (not exactly sure on that one).
Posted
Hmm.. regardless of being easy, hard or whatever, are there other ways? I'm more concerned with doing it correctly.
Gamer extraordinaire. Programmer wannabe.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...