all groups > dotnet framework > november 2006 >
You're in the

dotnet framework

group:

Set Value for Property in base class.



Set Value for Property in base class. Ruben Gatt
11/30/2006 4:45:04 PM
dotnet framework: 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



Re: Set Value for Property in base class. Mattias Sjögren
11/30/2006 6:35:59 PM
[quoted text, click to view]

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


Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
AddThis Social Bookmark Button