I have a class called ModelBase:
public abstract class ModelBase : ViewModelBase
{
public ModelBase
{
ProcessObjects.Instance.AddProcessObject(name, this);
}
public abstract void Dispose();
public String Name { get; set; }
....
....
}
public class SomeModel1: ModelBase
{
public String customprop1 { get; set; }
}
public class SomeModel2: ModelBase
{
public String customprop2 { get; set; }
}
I keep a list of all object instances in an application singleton. Now somewhere else in the application I want to retrieve customprop2 from SomeModel2 using this singleton list. I can retrieve the object as modelbase object and cast it:
SomeMethod()
{
if(_obj.Name == "SomeModel2"){
var _obj = obj as SomeModel2;
var _customProp2 = obj.customprop2 ;
}
}
But ideally i want to just try to retrieve the value straight from the object instance by knowing it is there in the parent of the basemodel.
try{
//Some code to automatically cast the object as parent.
var _customProp2 = _obj.customProp2;
}catch{
//Notify user that his request failed
}
The reason for this is that the user can write into a textbox and start a logging function for that particular property.