Set Value for Property in base class.

R

Ruben Gatt

Hi,



I have a problem when im trying to set a value for a property in the base
class. the following example shows what i currently have...





Example:



Base Class



public class Person

{

public string Name

{

get {return m_Name;}

set {m_Name=value;}

}



}



Child Class



public class student: Person

{

public string Place

{

get {return m_Place;}

set {m_Place=value;}

}

}



--------------



Now i have a function where i pass the name of the property, the value and
an instance of the class...




example: LoopProperties(sStudent,"Place","test")



and the function loops in the properties of the class and set the value...



im using .GetProperties to get the list and im looping using foreach and
setting the value using property.SetValue()



However there is a chance that the function receive the property Name (which
is in the base class of student)



example: LoopProperties(sStudent,"Name","testname")





how can i set the property Name when i only have an instance of the class
student??





Thanks





Ruben
 
M

Mattias Sjögren

how can i set the property Name when i only have an instance of the class
student??

GetProperties returns inherited properties as well so I'd expect your
existing code to work in this case too.


Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top