Click here to Skip to main content
15,914,447 members
Home / Discussions / C#
   

C#

 
AnswerRe: convert pointer and adress to C#? Pin
dec8211-Jan-09 17:51
dec8211-Jan-09 17:51 
AnswerRe: convert pointer and adress to C#? Pin
Guffa11-Jan-09 19:37
Guffa11-Jan-09 19:37 
QuestionNHibernate .NET 3.0 support? Pin
devvvy11-Jan-09 14:05
devvvy11-Jan-09 14:05 
AnswerRe: NHibernate .NET 3.0 support? Pin
Eddy Vluggen11-Jan-09 21:09
professionalEddy Vluggen11-Jan-09 21:09 
QuestionNetworkStream.Write Pin
Eli Nurman11-Jan-09 11:53
Eli Nurman11-Jan-09 11:53 
AnswerRe: NetworkStream.Write [modified] Pin
Luc Pattyn11-Jan-09 12:48
sitebuilderLuc Pattyn11-Jan-09 12:48 
GeneralRe: NetworkStream.Write Pin
Ben Fair12-Jan-09 7:43
Ben Fair12-Jan-09 7:43 
QuestionObject type not known at Design TIme Pin
CodingYoshi11-Jan-09 10:00
CodingYoshi11-Jan-09 10:00 
Lets say I have a database with one table, for the sake of this question, and the table structure is like below:

Customer
========
CustomerID
FirstName
LastName
DateOfBirth
Address
City
Province
Country
PostalCode

I have created a DAL which is a singleton class and has a method called Load() which loads all the customers from the database (Lets not worry about memory issues here). Now what I want to do is allow clients to pass in objects of type T and I will load that object for them. For example, client can pass object X and X only needs CutomerID, FirstName, and LastName and I will load object X with those fields.

The problem is at the design time of DAL I can not anticipate the type clients will pass in. I know I can create a method which takes a generic type and create a constraint on it that it must derive from some class or implement some interface but I can not foretell what interface they should implement or what class they should inherit. A client might pass an object which only requires the ID or 2 fields, or 5 fields and so on.

One solution is clients can pass names of fields in an array and I can return them values in an array but I do not like this option. I want to totally abstract the object loading from the client. Can this be done?
Here is the skeleton:

public class DAL
{
public void Load()
{
// Loads all customers from the database and keeps them in a DataTable
}

public CustomerCollection ToCustomerCollection()
{
// Creates type of Customer which has all fields for customers and adds them to a CustomerCollection
}

public void LoadMe(T unknownType)
{
if (T is SomeAbstractClass || T is SomeInterface) // Not an option
{}
// This method should somehow find the properties of T at runtime and load those properties.
}
}

Note: Both clients and DAL know the fields in the database.
AnswerRe: Object type not known at Design TIme Pin
User 665811-Jan-09 10:46
User 665811-Jan-09 10:46 
AnswerRe: Object type not known at Design TIme Pin
Not Active11-Jan-09 12:31
mentorNot Active11-Jan-09 12:31 
GeneralRe: Object type not known at Design TIme Pin
CodingYoshi11-Jan-09 12:38
CodingYoshi11-Jan-09 12:38 
GeneralRe: Object type not known at Design TIme Pin
Guffa11-Jan-09 20:05
Guffa11-Jan-09 20:05 
AnswerRe: Object type not known at Design TIme Pin
Guffa11-Jan-09 20:02
Guffa11-Jan-09 20:02 
QuestionHow do I write to this class? [modified] Pin
e40s11-Jan-09 8:17
e40s11-Jan-09 8:17 
AnswerRe: How do I write to this class? Pin
Not Active11-Jan-09 8:28
mentorNot Active11-Jan-09 8:28 
GeneralRe: How do I write to this class? [modified] Pin
e40s11-Jan-09 9:17
e40s11-Jan-09 9:17 
GeneralRe: How do I write to this class? Pin
Not Active11-Jan-09 9:32
mentorNot Active11-Jan-09 9:32 
GeneralRe: How do I write to this class? [modified] Pin
e40s11-Jan-09 10:02
e40s11-Jan-09 10:02 
GeneralRe: How do I write to this class? Pin
Not Active11-Jan-09 12:20
mentorNot Active11-Jan-09 12:20 
GeneralRe: How do I write to this class? [modified] Pin
e40s11-Jan-09 16:16
e40s11-Jan-09 16:16 
GeneralRe: How do I write to this class? Pin
Not Active11-Jan-09 16:29
mentorNot Active11-Jan-09 16:29 
AnswerRe: How do I write to this class? [modified] Pin
Luc Pattyn11-Jan-09 16:54
sitebuilderLuc Pattyn11-Jan-09 16:54 
AnswerRe: How do I write to this class? Pin
Pete O'Hanlon11-Jan-09 8:43
mvePete O'Hanlon11-Jan-09 8:43 
GeneralRe: How do I write to this class? Pin
e40s11-Jan-09 9:23
e40s11-Jan-09 9:23 
GeneralRe: How do I write to this class? Pin
Not Active11-Jan-09 9:29
mentorNot Active11-Jan-09 9:29 

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

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