Click here to Skip to main content
15,909,199 members
Home / Discussions / C#
   

C#

 
GeneralRe: Attach database file to SQL Server during Setup Pin
PIEBALDconsult31-Aug-10 3:21
mvePIEBALDconsult31-Aug-10 3:21 
GeneralRe: Attach database file to SQL Server during Setup Pin
firas_hamzeh31-Aug-10 4:10
firas_hamzeh31-Aug-10 4:10 
GeneralRe: Attach database file to SQL Server during Setup Pin
Not Active31-Aug-10 4:15
mentorNot Active31-Aug-10 4:15 
GeneralRe: Attach database file to SQL Server during Setup Pin
firas_hamzeh31-Aug-10 4:21
firas_hamzeh31-Aug-10 4:21 
GeneralRe: Attach database file to SQL Server during Setup Pin
PIEBALDconsult31-Aug-10 10:43
mvePIEBALDconsult31-Aug-10 10:43 
GeneralRe: Attach database file to SQL Server during Setup Pin
firas_hamzeh2-Sep-10 3:20
firas_hamzeh2-Sep-10 3:20 
GeneralRe: Attach database file to SQL Server during Setup Pin
PIEBALDconsult2-Sep-10 15:55
mvePIEBALDconsult2-Sep-10 15:55 
Question.dll file are not replacing when install new set up. Pin
jainiraj31-Aug-10 0:16
jainiraj31-Aug-10 0:16 
AnswerRe: .dll file are not replacing when install new set up. Pin
Not Active31-Aug-10 0:31
mentorNot Active31-Aug-10 0:31 
GeneralRe: .dll file are not replacing when install new set up. Pin
jainiraj31-Aug-10 0:48
jainiraj31-Aug-10 0:48 
GeneralRe: .dll file are not replacing when install new set up. Pin
patzerFish3-Sep-10 15:36
patzerFish3-Sep-10 15:36 
QuestionNaming Rules Pin
Adriaan Davel30-Aug-10 22:36
Adriaan Davel30-Aug-10 22:36 
AnswerMessage Removed Pin
30-Aug-10 22:55
Bigdeak30-Aug-10 22:55 
GeneralRe: Naming Rules Pin
Adriaan Davel30-Aug-10 23:00
Adriaan Davel30-Aug-10 23:00 
GeneralRe: Naming Rules Pin
Bigdeak31-Aug-10 0:31
Bigdeak31-Aug-10 0:31 
AnswerRe: Naming Rules Pin
Pete O'Hanlon30-Aug-10 23:30
mvePete O'Hanlon30-Aug-10 23:30 
AnswerRe: Naming Rules Pin
Eddy Vluggen31-Aug-10 0:08
professionalEddy Vluggen31-Aug-10 0:08 
AnswerRe: Naming Rules Pin
Kythen1-Sep-10 8:30
Kythen1-Sep-10 8:30 
Questioncan't get float value Pin
zhiyuan1630-Aug-10 22:22
zhiyuan1630-Aug-10 22:22 
AnswerRe: can't get float value Pin
Bigdeak30-Aug-10 23:00
Bigdeak30-Aug-10 23:00 
AnswerRe: can't get float value Pin
phil.o31-Aug-10 0:34
professionalphil.o31-Aug-10 0:34 
AnswerRe: can't get float value Pin
Luc Pattyn31-Aug-10 2:23
sitebuilderLuc Pattyn31-Aug-10 2:23 
QuestionAbstract Static and Inheritance Pin
Matthew Klein30-Aug-10 15:28
Matthew Klein30-Aug-10 15:28 
I’m apparently trying to do something stupid, because the C# help file says that I can’t, and that usually means my design is all jacked up.
Here’s a version of what I’m trying to do:
I have a base class, ItemBase, and I want to give it the method
public class ItemBase
{
    public abstract static List<string> GetAvaliableUpgrades();
}

Then, I have three classes
public class Car : ItemBase { }
public class Van : ItemBase { }
public class Truck : ItemBase { }

(they implement GetAvaliableUpgrades())

And finally, I have a control
public class MyItemDisplay<T> : UserControl where T : ItemBase
{
    public void SetUpgrades()
    {
        foreach (string s in T.GetAvaliableUpgrades())
            listBox1.Items.Add(s);
    }
}


Now I know that I can’t do that in C#, but I’m wondering if there is another way to implement this type of process. Since the Upgrades List is a property of the class itself and not unique to each instance, I want to make the GetAvaliableUpgrades() method static, and I don’t want to repeat myself, so I want the SetUpgrades() method in the Control to work on any ItemBase.

I know I can make something similar work by doing:
public class ItemBase
{
    protected abstract List<string> GetMyUpgrades();

    public static List<string> GetAvaliableUpgrades<T>() where T : ItemBase, new()
    {
        T item = new T();
        return item.GetMyUpgrades();
    }
}

public class MyItemDisplay<T> : UserControl where T : ItemBase
{
    public void SetUpgrades()
    {
        foreach (string s in ItemBase.GetAvaliableUpgrades<T>())
            listBox1.Items.Add(s);
    }
}

But that feels sloppy and incorrect, since I’ve got to make an instance of a class to get a property about that class. Is there some kind of design pattern I can research that will allow me to get the kind of functionality that I’m looking for in C#? Or is there another way to allow me to have one control that works on a family of classes, without having to copy-paste a bunch of code? Thank you all in advance for your time!

Matt
AnswerRe: Abstract Static and Inheritance Pin
PIEBALDconsult30-Aug-10 16:50
mvePIEBALDconsult30-Aug-10 16:50 
GeneralRe: Abstract Static and Inheritance Pin
Matthew Klein31-Aug-10 4:38
Matthew Klein31-Aug-10 4:38 

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.