Microsoft

Inheritance Hierarchies

Blaahhhhhhh.........

Here MS made this really nice system, with a pretty well thought out object hierarchy. But can they make everything that goes on a Form share a common ancestor? Can they?

No.

While all Controls have a Name property and all ToolStrip items have a Name property, is there some common ancestor that also provides the Name property?

No.

Of course not.

So if you want to treat all objects in a Form equally, you have to use reflection for certain properties which is just silly. They should have moved the common core properties to a common ancestor.

static public string GetNameProperty(Object o) 
{ 
    Type t = o.GetType(); 
    PropertyInfo propName = t.GetProperty("Name", typeof(string)); 
    if (propName != null) 
        return (string)propName.GetValue(o, null); return null;  
}
Syndicate content