Click here to Skip to main content
15,902,189 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
QuestionWhy .net code is in .h File not in .cpp file Pin
Abhijit D. Babar1-May-08 20:06
Abhijit D. Babar1-May-08 20:06 
AnswerRe: Why .net code is in .h File not in .cpp file Pin
Urs Enzler2-May-08 4:31
Urs Enzler2-May-08 4:31 
QuestionNeed for a rich Text Editor .... Pin
devboycpp1-May-08 19:12
devboycpp1-May-08 19:12 
AnswerRe: Need for a rich Text Editor .... Pin
Christian Graus1-May-08 19:32
protectorChristian Graus1-May-08 19:32 
AnswerRe: Need for a rich Text Editor .... Pin
Vasudevan Deepak Kumar2-May-08 0:44
Vasudevan Deepak Kumar2-May-08 0:44 
AnswerRe: Need for a rich Text Editor .... Pin
Reelix6-May-08 22:53
Reelix6-May-08 22:53 
QuestionChange Directory type info Pin
coleydog1-May-08 13:12
coleydog1-May-08 13:12 
QuestionStrange Behavior with Generics Pin
girijaa30-Apr-08 6:09
professionalgirijaa30-Apr-08 6:09 
Strange Behavior with Generics:

When I define a Generic at class level with a constraint, I get a compile exception , however , when I implement Generic at method level with the same constraint , all goes well ...
Wondering , wether its a bug in generics or the bug lies in my way of interpretation Frown | :-(

Have Tried to explain the problem below :

Case 1:
I have defined a abstract generic class and defined the generic type at class level , with a constraint . Below is the class definition.

public abstract class BaseVOMapper<T> where T:BaseVO
{
public abstract void Insert(BaseVO child , BaseVO parent );

public abstract void SaveChildrens(List<T> childListToPersist, BaseVO parentVO);
}

Below is the implementation o f the derived class , where FlightList is a List<FlightVO> & FlightVO: BaseVO & as per polymorphism ,I assume , I can pass List<FlightVO> where List<BaseVO> is expected.However , I endup getting the below error.
Argument '1': cannot convert from 'System.Collections.Generic.List<ValueObjects.FlightVO>' to 'System.Collections.Generic.List<ValueObjects.BaseVO>'

i.e
public class FlightVO : BaseVO
{
public int FlightId;
public string FlightName;
}


public class ScheduleVOMapper: BaseVOMapper<BaseVO>
{
public override void Insert(ValueObjects.BaseVO child, ValueObjects.BaseVO parent)
{
//((ScheduleVO)child).FlightList
this.SaveChildrens(((ScheduleVO)child).FlightList, parent);
}



public override void SaveChildrens(List<BaseVO> childListToPersist, BaseVO parentVO)
{
foreach (BaseVO child in childListToPersist)
{
ORlayerEngine.Persist(child, parentVO);
}
}
}

------------------------------------------------------------------Code using Generic at Method Level ------------------------------------------------------------------------------------------

Case 2
// generic type specified at method level , with the same constraint
public abstract class BaseVOMapper
{
public abstract void Insert(BaseVO child , BaseVO parent );

public abstract void SaveChildrens<T>(List<T> childListToPersist, BaseVO parentVO) where T:BaseVO ;
}

Below is the implementation of the derived class :

public class ScheduleVOMapper: BaseVOMapper
{
public override void Insert(ValueObjects.BaseVO child, ValueObjects.BaseVO parent)
{
//((ScheduleVO)child).FlightList
this.SaveChildrens(((ScheduleVO)child).FlightList, parent);
}

public override void SaveChildrens<T>(List<T> childListToPersist, BaseVO parentVO)
{
foreach (BaseVO child in childListToPersist)
{
ORlayerEngine.Persist(child, parentVO);
}
}
}

Comparing Case 1 & Case 2 , in case 1 , in the derived class ScheduleVOMapper , the SaveChildrens method has the generic type explicity specified as BaseVO ,
whereas in Case 2 , the method gets the Generic Type at runtime , which anyways as per the constraint has to be of Type BaseVO.

Though , I have my solution implemneted using Case 2 , would really like to get my doubt's cleared

Many Thanks
Girija
AnswerRe: Strange Behavior with Generics Pin
Urs Enzler1-May-08 10:12
Urs Enzler1-May-08 10:12 
QuestionUnsafe Assembly Permissions Pin
Brady Kelly30-Apr-08 5:15
Brady Kelly30-Apr-08 5:15 
QuestionDataTable.Select() Pin
alex.almeida30-Apr-08 3:24
alex.almeida30-Apr-08 3:24 
QuestionTableDataAdapter.Update to two mirror databases... [modified] Pin
sabr4930-Apr-08 2:07
sabr4930-Apr-08 2:07 
QuestionForce TextBox to show cursor Pin
Christian Wikander29-Apr-08 23:00
Christian Wikander29-Apr-08 23:00 
AnswerRe: Force TextBox to show cursor Pin
Arjun Marwaha30-Apr-08 7:44
Arjun Marwaha30-Apr-08 7:44 
QuestionSelect Statement Pin
Learning29-Apr-08 5:18
Learning29-Apr-08 5:18 
GeneralRe: Select Statement Pin
Mark J. Miller29-Apr-08 7:49
Mark J. Miller29-Apr-08 7:49 
GeneralRe: Select Statement Pin
Learning30-Apr-08 4:42
Learning30-Apr-08 4:42 
Questionunable to find a version of the runtime to run this application Pin
Muhammad Gouda28-Apr-08 22:28
Muhammad Gouda28-Apr-08 22:28 
AnswerRe: unable to find a version of the runtime to run this application Pin
Zoltan Balazs29-Apr-08 6:54
Zoltan Balazs29-Apr-08 6:54 
AnswerRe: unable to find a version of the runtime to run this application Pin
Muhammad Gouda30-Apr-08 1:41
Muhammad Gouda30-Apr-08 1:41 
GeneralDatagrid Pin
sabr4928-Apr-08 15:02
sabr4928-Apr-08 15:02 
GeneralApplication running slow Pin
Bad Programmer28-Apr-08 11:12
Bad Programmer28-Apr-08 11:12 
GeneralCross Post. Please ignore. Pin
Pete O'Hanlon29-Apr-08 1:29
mvePete O'Hanlon29-Apr-08 1:29 
QuestionStymied by interop Pin
Mark Schumann28-Apr-08 9:27
Mark Schumann28-Apr-08 9:27 
AnswerRe: Stymied by interop Pin
led mike28-Apr-08 9:30
led mike28-Apr-08 9:30 

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.