Click here to Skip to main content
15,559,121 members
Home / Discussions / C#
   

C#

 
GeneralRe: Generics Problems Pin
Kevin Marois7-Sep-12 11:44
professionalKevin Marois7-Sep-12 11:44 
GeneralRe: Generics Problems Pin
Eddy Vluggen7-Sep-12 11:54
professionalEddy Vluggen7-Sep-12 11:54 
GeneralRe: Generics Problems Pin
Kevin Marois7-Sep-12 11:56
professionalKevin Marois7-Sep-12 11:56 
GeneralRe: Generics Problems Pin
Eddy Vluggen7-Sep-12 12:09
professionalEddy Vluggen7-Sep-12 12:09 
AnswerRe: Generics Problems Pin
jschell7-Sep-12 11:39
jschell7-Sep-12 11:39 
GeneralRe: Generics Problems Pin
Kevin Marois7-Sep-12 11:41
professionalKevin Marois7-Sep-12 11:41 
GeneralRe: Generics Problems Pin
jschell8-Sep-12 8:23
jschell8-Sep-12 8:23 
AnswerRe: Generics Problems Pin
dbaseman7-Sep-12 22:20
dbaseman7-Sep-12 22: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 21:28
mveGerry Schmitz8-Sep-12 21:28 
Questionhow to change the parent of anUIElement Pin
benzarabel7-Sep-12 6:04
benzarabel7-Sep-12 6:04 
AnswerRe: how to change the parent of anUIElement Pin
Wes Aday7-Sep-12 6:55
professionalWes Aday7-Sep-12 6:55 
AnswerRe: how to change the parent of anUIElement Pin
Clifford Nelson7-Sep-12 8:25
Clifford Nelson7-Sep-12 8:25 
QuestionControl won't update Pin
MAW306-Sep-12 17:48
MAW306-Sep-12 17:48 
AnswerRe: Control won't update Pin
Dr.Walt Fair, PE6-Sep-12 18:13
professionalDr.Walt Fair, PE6-Sep-12 18:13 
GeneralRe: Control won't update Pin
MAW306-Sep-12 18:47
MAW306-Sep-12 18:47 
GeneralRe: Control won't update Pin
Dr.Walt Fair, PE6-Sep-12 18:57
professionalDr.Walt Fair, PE6-Sep-12 18:57 
GeneralRe: Control won't update Pin
MAW306-Sep-12 19:11
MAW306-Sep-12 19:11 
AnswerRe: Control won't update Pin
Eddy Vluggen6-Sep-12 19:24
professionalEddy Vluggen6-Sep-12 19:24 
GeneralRe: Control won't update Pin
MAW306-Sep-12 19:44
MAW306-Sep-12 19:44 
QuestionC# process code Pin
sc steinhayse6-Sep-12 11:19
sc steinhayse6-Sep-12 11:19 
AnswerRe: C# process code Pin
Dave Kreskowiak6-Sep-12 11:52
mveDave Kreskowiak6-Sep-12 11:52 
QuestionHow to open UNC path to C$ without credentials Pin
robwm16-Sep-12 10:15
robwm16-Sep-12 10:15 
AnswerRe: How to open UNC path to C$ without credentials Pin
Eddy Vluggen6-Sep-12 19:25
professionalEddy Vluggen6-Sep-12 19:25 
GeneralRe: How to open UNC path to C$ without credentials Pin
PIEBALDconsult7-Sep-12 5:51
professionalPIEBALDconsult7-Sep-12 5:51 
GeneralRe: How to open UNC path to C$ without credentials Pin
robwm17-Sep-12 9:26
robwm17-Sep-12 9: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.