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

.NET (Core and Framework)

 
QuestionHow to build a IP LAN Scanner in .Net Pin
Carmine_XX25-Jun-07 4:49
Carmine_XX25-Jun-07 4:49 
AnswerRe: How to build a IP LAN Scanner in .Net Pin
Ilya Verbitskiy8-Jul-07 1:18
Ilya Verbitskiy8-Jul-07 1:18 
GeneralRe: How to build a IP LAN Scanner in .Net Pin
Carmine_XX8-Jul-07 4:41
Carmine_XX8-Jul-07 4:41 
GeneralRe: How to build a IP LAN Scanner in .Net Pin
Ilya Verbitskiy8-Jul-07 21:19
Ilya Verbitskiy8-Jul-07 21:19 
QuestionGenerics, Inheritance and frustration Pin
Santiago Perez25-Jun-07 2:38
Santiago Perez25-Jun-07 2:38 
AnswerRe: Generics, Inheritance and frustration Pin
Andy L 225-Jun-07 7:10
Andy L 225-Jun-07 7:10 
GeneralRe: Generics, Inheritance and frustration Pin
Santiago Perez25-Jun-07 8:32
Santiago Perez25-Jun-07 8:32 
GeneralRe: Generics, Inheritance and frustration Pin
Andy L 226-Jun-07 0:16
Andy L 226-Jun-07 0:16 
Maybe I am missing the point somewhere but I cannot see why you need to use generics to do this.

In my previous example by placing all the initialisation properties into iPerson for example would enable you to initialise all classes derived from iPerson i.e.

// Interface that defines properties and methods to be called during initilaisation
public interface I
{
string Prop1 { get; set; }
int Prop2 { get; set; }
void Initialise(params object[] arrParams);
}

// Classes to be initialised
class A: I
{
private string _prop1 = null;
private int _prop2;

// Interface implementations
string I.Prop1
{
get { return _prop1; }
set { _prop1 = value; }
}

int I.Prop2
{
get { return _prop2; }
set { _prop2 = value; }
}

void I.Initialise(params object[] arrParams)
{
// Do some initialisation on params
Initialise(arrParams);
}

// Option for in class initialisation - could use virtual.
protected abstract void Initialise(params object[] arrParams);
}

class B: A
{
protected override void Initialise(params object[] arrParams)
{
}
}

class C: B
{
private string Prop3 = null;

protected override void Initialise(params object[] arrParams)
{
}
}


Now using interface I to initialise instances of A, B or C as follows:
//Create list
List<I> items = new List<I>();

// This could equally be:
// ArrayList items = new ArrayList();
....
if (ClassType == eType.A)
{
items.Add(new A());
}
else if (ClassType == eType.B)
{
items.Add(new B());
}
else if (ClassType == eType.C)
{
items.Add(new C());
}

// Initialisation can be performed on object instances of type A, B and C this way using interface I no casting required.
foreach (I item in items)
{
// Initialise object properties
item.Prop1 = source.P1;
item.Prop2 = source.P2;

//Or even call an initialise method on the object itself.
item.Initialise(source.P1, source.P2, "P3");
}

This example relies on a single interface structure defined at compile time, this is also a requirement that applies to generics - if what you are looking for is to try and initialise objects by examining their structures at run-time then this falls into the realms of Reflection - and only do this if for some reason you really need to.

If you are requiring to initialise properties that apply to the derived classes (i.e class C)
you could used the Initialise() method shown but you would have to either apply strict parameter ordering or employ a mechanism for identifying which parameter goes to which property.
GeneralRe: Generics, Inheritance and frustration Pin
Santiago Perez26-Jun-07 16:41
Santiago Perez26-Jun-07 16:41 
GeneralRe: Generics, Inheritance and frustration Pin
Santiago Perez26-Jun-07 18:28
Santiago Perez26-Jun-07 18:28 
GeneralRe: Generics, Inheritance and frustration Pin
Santiago Perez26-Jun-07 20:19
Santiago Perez26-Jun-07 20:19 
GeneralRe: Generics, Inheritance and frustration Pin
Andy L 226-Jun-07 22:37
Andy L 226-Jun-07 22:37 
GeneralRe: Generics, Inheritance and frustration Pin
Santiago Perez27-Jun-07 5:05
Santiago Perez27-Jun-07 5:05 
GeneralRe: Generics, Inheritance and frustration Pin
Santiago Perez27-Jun-07 5:29
Santiago Perez27-Jun-07 5:29 
GeneralRe: Generics, Inheritance and frustration Pin
Santiago Perez27-Jun-07 5:45
Santiago Perez27-Jun-07 5:45 
GeneralRe: Generics, Inheritance and frustration Pin
Santiago Perez28-Jun-07 7:34
Santiago Perez28-Jun-07 7:34 
GeneralRe: Generics, Inheritance and frustration Pin
Andy L 229-Jun-07 5:33
Andy L 229-Jun-07 5:33 
QuestionXML 3 BulkLoad Error Pin
Panchal Hardik25-Jun-07 2:25
Panchal Hardik25-Jun-07 2:25 
AnswerRe: XML 3 BulkLoad Error Pin
Dave Kreskowiak25-Jun-07 4:04
mveDave Kreskowiak25-Jun-07 4:04 
Questioninstallation .net 2005 Pin
Sumanth Pereji25-Jun-07 2:19
Sumanth Pereji25-Jun-07 2:19 
AnswerRe: installation .net 2005 Pin
Dave Kreskowiak25-Jun-07 4:09
mveDave Kreskowiak25-Jun-07 4:09 
GeneralRe: installation .net 2005 Pin
Pete O'Hanlon25-Jun-07 5:13
mvePete O'Hanlon25-Jun-07 5:13 
GeneralRe: installation .net 2005 Pin
Dave Kreskowiak25-Jun-07 5:56
mveDave Kreskowiak25-Jun-07 5:56 
GeneralRe: installation .net 2005 Pin
Pete O'Hanlon25-Jun-07 8:32
mvePete O'Hanlon25-Jun-07 8:32 
GeneralRe: installation .net 2005 Pin
originSH25-Jun-07 23:03
originSH25-Jun-07 23:03 

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.