Click here to Skip to main content
15,891,942 members
Home / Discussions / C#
   

C#

 
AnswerRe: virtual/abstract methods and properties Pin
Peace ON30-Jun-10 23:51
Peace ON30-Jun-10 23:51 
GeneralRe: virtual/abstract methods and properties Pin
Daley831-Jul-10 0:00
Daley831-Jul-10 0:00 
AnswerRe: virtual/abstract methods and properties Pin
Peace ON1-Jul-10 0:20
Peace ON1-Jul-10 0:20 
AnswerRe: virtual/abstract methods and properties Pin
Łukasz Nowakowski1-Jul-10 0:22
Łukasz Nowakowski1-Jul-10 0:22 
GeneralRe: virtual/abstract methods and properties Pin
Daley831-Jul-10 1:04
Daley831-Jul-10 1:04 
AnswerUPDATE: virtual/abstract methods and properties Pin
Daley831-Jul-10 1:02
Daley831-Jul-10 1:02 
GeneralRe: UPDATE: virtual/abstract methods and properties Pin
Łukasz Nowakowski1-Jul-10 1:29
Łukasz Nowakowski1-Jul-10 1:29 
GeneralRe: UPDATE: virtual/abstract methods and properties Pin
Daley831-Jul-10 1:45
Daley831-Jul-10 1:45 
Lukasz, my man! That works a treat, exactly what I was looking for! I can't thank you enough for that, I really appreciate you taking the time to help and now I will look more into Assembly and System.Reflection in more detail.

For anyone interested here is the final code that works.

Class file;
namespace FruitBase_EG
{
    public class FruitBase
    {
        //Private fields
        private string _name;
        private string _colour;

        //Constructor
        public FruitBase()
        {
        }
        
        //Properties
        public virtual string Name
        {
            get { return _name; }
            set { _name = value; }
        }
        public string Colour
        {
            get { return _colour; }
            set { _colour = value; }
        }

        //Methods
        public virtual void GetDefaults()
        {
            this.Name = "Fruit";
            this.Colour = "White";
        }
    }

    public class Apple: FruitBase
    {
        //Constructor
        public Apple()
        {
        }

        public override void GetDefaults()
        {
            this.Name = "Apple";
            this.Colour = "Red";
        } 
    }
    public class Banana : FruitBase
    {
        //Constructor
        public Banana()
        {
        }

        public override void GetDefaults()
        {
            this.Name = "Banana";
            this.Colour = "Yellow";
        }
    }
}


And my code behind looks like this;

namespace FruitBase_EG
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        public void GetValues(object sender, EventArgs e)
        {
            string name = radList.SelectedValue;  

            Assembly assembly = typeof(FruitBase).Assembly;
            Type type = assembly.GetType(string.Format("{0}.{1}","FruitBase_EG", name));
            object obj = Activator.CreateInstance(type);
            FruitBase fb = obj as FruitBase;

            fb.GetDefaults();

            txtOuput.Text = fb.Name + " - " + fb.Colour;        
        }
    }
}


Now when the user selects a fruit using the radio button, on the click event of the Get Details button we run through the code above and it picks up the users choice and then sets the FruitBase class to which ever individual fruit class we have chosen, eventually outputting the name and colour values to the textbox Smile | :)
GeneralRe: UPDATE: virtual/abstract methods and properties Pin
Łukasz Nowakowski1-Jul-10 1:54
Łukasz Nowakowski1-Jul-10 1:54 
GeneralRe: UPDATE: virtual/abstract methods and properties Pin
harold aptroot1-Jul-10 3:47
harold aptroot1-Jul-10 3:47 
AnswerRe: virtual/abstract methods and properties Pin
Ennis Ray Lynch, Jr.1-Jul-10 3:44
Ennis Ray Lynch, Jr.1-Jul-10 3:44 
QuestionHow to join 2 string[] objects Pin
Chesnokov Yuriy30-Jun-10 23:00
professionalChesnokov Yuriy30-Jun-10 23:00 
AnswerRe: How to join 2 string[] objects Pin
R. Giskard Reventlov30-Jun-10 23:03
R. Giskard Reventlov30-Jun-10 23:03 
AnswerRe: How to join 2 string[] objects Pin
freakyit30-Jun-10 23:19
freakyit30-Jun-10 23:19 
AnswerRe: How to join 2 string[] objects Pin
Ayman Kouzayha30-Jun-10 23:31
Ayman Kouzayha30-Jun-10 23:31 
AnswerRe: How to join 2 string[] objects Pin
Laxman Auti1-Jul-10 0:19
Laxman Auti1-Jul-10 0:19 
GeneralRe: How to join 2 string[] objects Pin
Chesnokov Yuriy1-Jul-10 0:41
professionalChesnokov Yuriy1-Jul-10 0:41 
AnswerRe: How to join 2 string[] objects Pin
Ravi Bhavnani2-Jul-10 4:58
professionalRavi Bhavnani2-Jul-10 4:58 
QuestionConvert 32-bit Bitmap file to 24-bit Pin
Ayman Kouzayha30-Jun-10 22:28
Ayman Kouzayha30-Jun-10 22:28 
QuestionRe: Convert 32-bit Bitmap file to 24-bit Pin
Ayman Kouzayha30-Jun-10 23:21
Ayman Kouzayha30-Jun-10 23:21 
QuestionOnShown event not always triggered Pin
Gonzalo Cao30-Jun-10 21:43
Gonzalo Cao30-Jun-10 21:43 
QuestionHow to Integrate Quick Book With VS08 Pin
kanchan112330-Jun-10 20:32
kanchan112330-Jun-10 20:32 
AnswerRe: How to Integrate Quick Book With VS08 Pin
Richard MacCutchan30-Jun-10 21:41
mveRichard MacCutchan30-Jun-10 21:41 
QuestionEWS attribute 'Value' missing.. ARGG Pin
Jacob Dixon30-Jun-10 9:47
Jacob Dixon30-Jun-10 9:47 
QuestionLABEL for X and Y Axis Pin
It_tech30-Jun-10 8:51
It_tech30-Jun-10 8:51 

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.