Click here to Skip to main content
15,886,137 members
Home / Discussions / C#
   

C#

 
GeneralRe: Generics Problems Pin
Kevin Marois7-Sep-12 10:44
professionalKevin Marois7-Sep-12 10:44 
GeneralRe: Generics Problems Pin
Eddy Vluggen7-Sep-12 10:54
professionalEddy Vluggen7-Sep-12 10:54 
GeneralRe: Generics Problems Pin
Kevin Marois7-Sep-12 10:56
professionalKevin Marois7-Sep-12 10:56 
GeneralRe: Generics Problems Pin
Eddy Vluggen7-Sep-12 11:09
professionalEddy Vluggen7-Sep-12 11:09 
AnswerRe: Generics Problems PinPopular
jschell7-Sep-12 10:39
jschell7-Sep-12 10:39 
GeneralRe: Generics Problems Pin
Kevin Marois7-Sep-12 10:41
professionalKevin Marois7-Sep-12 10:41 
GeneralRe: Generics Problems Pin
jschell8-Sep-12 7:23
jschell8-Sep-12 7:23 
AnswerRe: Generics Problems Pin
dbaseman7-Sep-12 21:20
dbaseman7-Sep-12 21:20 
The best way to do this is to create an interface that encapsulates the common properties of your entities:

C#
public interface IEntity
{
    string SomeProperty { get; set; }
}

public interface IAnotherInterface
{
    string Name { get; set; }
}


Each entity can inherit multiple interfaces, depending on how you want it set up:

C#
public class Entity1 : IEntity, IAnotherInterface
{
    public string SomeProperty { get; set; }
    public string Name { get; set; }
}


If every entity has a certain interface, then you can require it in the Form<t> definition:

C#
public partial class Form1<T> : Form
   where T : IEntity


Finally, cast to the interfaces to set properties. If only some entities implement a given interface, check first.

C#
void SetSomeProperties()
{
    (entity as IEntity).SomeProperty = "foo";
    if (entity is IAnotherInterface)
    {
        (entity as IAnotherInterface).Name = "bar";
    }
} 

AnswerRe: Generics Problems Pin
Gerry Schmitz8-Sep-12 20:28
mveGerry Schmitz8-Sep-12 20:28 
Questionhow to change the parent of anUIElement Pin
benzarabel7-Sep-12 5:04
benzarabel7-Sep-12 5:04 
AnswerRe: how to change the parent of anUIElement Pin
Wes Aday7-Sep-12 5:55
professionalWes Aday7-Sep-12 5:55 
AnswerRe: how to change the parent of anUIElement Pin
Clifford Nelson7-Sep-12 7:25
Clifford Nelson7-Sep-12 7:25 
QuestionControl won't update Pin
MAW306-Sep-12 16:48
MAW306-Sep-12 16:48 
AnswerRe: Control won't update Pin
Dr.Walt Fair, PE6-Sep-12 17:13
professionalDr.Walt Fair, PE6-Sep-12 17:13 
GeneralRe: Control won't update Pin
MAW306-Sep-12 17:47
MAW306-Sep-12 17:47 
GeneralRe: Control won't update Pin
Dr.Walt Fair, PE6-Sep-12 17:57
professionalDr.Walt Fair, PE6-Sep-12 17:57 
GeneralRe: Control won't update Pin
MAW306-Sep-12 18:11
MAW306-Sep-12 18:11 
AnswerRe: Control won't update Pin
Eddy Vluggen6-Sep-12 18:24
professionalEddy Vluggen6-Sep-12 18:24 
GeneralRe: Control won't update Pin
MAW306-Sep-12 18:44
MAW306-Sep-12 18:44 
QuestionC# process code Pin
sc steinhayse6-Sep-12 10:19
sc steinhayse6-Sep-12 10:19 
AnswerRe: C# process code Pin
Dave Kreskowiak6-Sep-12 10:52
mveDave Kreskowiak6-Sep-12 10:52 
QuestionHow to open UNC path to C$ without credentials Pin
robwm16-Sep-12 9:15
robwm16-Sep-12 9:15 
AnswerRe: How to open UNC path to C$ without credentials Pin
Eddy Vluggen6-Sep-12 18:25
professionalEddy Vluggen6-Sep-12 18:25 
GeneralRe: How to open UNC path to C$ without credentials Pin
PIEBALDconsult7-Sep-12 4:51
mvePIEBALDconsult7-Sep-12 4:51 
GeneralRe: How to open UNC path to C$ without credentials Pin
robwm17-Sep-12 8:26
robwm17-Sep-12 8:26 

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.