Click here to Skip to main content
15,902,834 members
Home / Discussions / C#
   

C#

 
GeneralRe: GCHandle.Alloc and delegate Pin
Andy Brummer18-Jun-08 11:00
sitebuilderAndy Brummer18-Jun-08 11:00 
QuestionClickOnce Pin
Member 391904918-Jun-08 7:07
Member 391904918-Jun-08 7:07 
AnswerRe: ClickOnce Pin
Gareth H18-Jun-08 8:15
Gareth H18-Jun-08 8:15 
Question.NET Remotable Types Pin
conor2018-Jun-08 5:39
conor2018-Jun-08 5:39 
QuestionType casting Pin
indian14318-Jun-08 5:04
indian14318-Jun-08 5:04 
AnswerRe: Type casting Pin
DaveyM6918-Jun-08 5:08
professionalDaveyM6918-Jun-08 5:08 
AnswerRe: Type casting Pin
led mike18-Jun-08 5:21
led mike18-Jun-08 5:21 
AnswerRe: Type casting Pin
Pete O'Hanlon18-Jun-08 8:37
mvePete O'Hanlon18-Jun-08 8:37 
You can only really do this if one class inherits from the other. If there is no relation other than them sharing the same name, then you can't perform the cast. The only thing you could do is create an instance of the second class and copy the values from the first in. Here's an example where both objects have the same properties, but aren't the same class (and the same property names are present in both - it's an artificial example, but serves as an example):
private U Copy<T,U>(T original) where U : new()
{
  PropertyInfo[] props = original.GetType().GetProperties();
  U returnItem = new U();
  foreach (PropertyInfo p in props)
  {
    returnItem.SetValue(returnItem, p.GetValue(original, null) null);
  }
}
I've just typed this off the top of my head, so some of the details may need to be finetuned a bit.

Deja View - the feeling that you've seen this post before.

My blog | My articles



QuestionCustom Control implementation at Runtime via Code vs. Designtime via Toolbox Pin
rcaciopp18-Jun-08 5:01
rcaciopp18-Jun-08 5:01 
AnswerRe: Custom Control implementation at Runtime via Code vs. Designtime via Toolbox Pin
led mike18-Jun-08 5:26
led mike18-Jun-08 5:26 
GeneralRe: Custom Control implementation at Runtime via Code vs. Designtime via Toolbox Pin
rcaciopp18-Jun-08 6:24
rcaciopp18-Jun-08 6:24 
GeneralRe: Custom Control implementation at Runtime via Code vs. Designtime via Toolbox Pin
darkelv18-Jun-08 6:31
darkelv18-Jun-08 6:31 
GeneralRe: Custom Control implementation at Runtime via Code vs. Designtime via Toolbox Pin
rcaciopp18-Jun-08 6:48
rcaciopp18-Jun-08 6:48 
GeneralRe: Custom Control implementation at Runtime via Code vs. Designtime via Toolbox Pin
darkelv18-Jun-08 6:58
darkelv18-Jun-08 6:58 
AnswerRe: Custom Control implementation at Runtime via Code vs. Designtime via Toolbox Pin
rcaciopp18-Jun-08 7:26
rcaciopp18-Jun-08 7:26 
QuestionCulture independant Dates? Pin
Megidolaon18-Jun-08 3:59
Megidolaon18-Jun-08 3:59 
AnswerRe: Culture independant Dates? Pin
Luc Pattyn18-Jun-08 4:17
sitebuilderLuc Pattyn18-Jun-08 4:17 
AnswerRe: Culture independant Dates? Pin
PIEBALDconsult18-Jun-08 4:45
mvePIEBALDconsult18-Jun-08 4:45 
GeneralRe: Culture independant Dates? Pin
Megidolaon19-Jun-08 21:01
Megidolaon19-Jun-08 21:01 
Questionxcopy in post build event Pin
Russell Jones18-Jun-08 3:29
Russell Jones18-Jun-08 3:29 
QuestionListViewItem image overlay [modified] Pin
ajtunbridge18-Jun-08 2:59
ajtunbridge18-Jun-08 2:59 
AnswerRe: ListViewItem image overlay Pin
led mike18-Jun-08 5:24
led mike18-Jun-08 5:24 
GeneralRe: ListViewItem image overlay Pin
ajtunbridge18-Jun-08 5:48
ajtunbridge18-Jun-08 5:48 
Questionhow to check the database connected is readonly? Pin
nicolus18-Jun-08 2:46
nicolus18-Jun-08 2:46 
AnswerRe: how to check the database connected is readonly? Pin
Bert delaVega18-Jun-08 16:27
Bert delaVega18-Jun-08 16:27 

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.