hi all,
i'm writing a routine that gathers data from autocad entities and displays them in a datagridview, after the user selects the entities, the idea is to have the user select the properties that they want to be display (eg. layer name, length, radius)... similiar to quick select in autocad.
Sounds like AutoCAD Data Extraction. (?)
Have you used it?
Is there a way of populating, say a list, with the common properties from 2 different classes. My current thoughts are either use reflection to find common properties between the two or step my way up the class tree to find a base class that each object inherits from. Currently i'm leaning more towards using reflection, but just wanted to see if there was another or easier way to do this?
Not exactly sure what you mean, but my interpretation of 'the common
properties from 2 different classes' are the properties of their common
base classes.
So for example, given a Line and an Arc, the 'common properties' are
the properties exposed by their common base classes (Curve, Entity,
and DBObject).
There's also the matter of custom properties that are added to objects
(which are properties that do not actually exist as 'declared' properties),
which are only accessable via the System.ComponentModel namespace
classes, namely TypeDescriptor.
For example, TypeDescriptor.GetProperties( object ) returns all of the
static and dynamic properties for the given object. The result is a
collection of PropertyDescriptors. You can look at the 'PropertyType'
property of each PropertyDescriptor to determine which base class
exposes each property. You can use the PropertyDescriptor's GetValue()
method to get the value of the property for a given instance that you
pass as the argument.
The only question I would have is, that Data Extraction pretty much
does what you describe, and unless you have special requirements you
didn't touch on, it may be worth a look.
There's also a post on ThroughTheInterface that shows how to control
Data Extraction via code, that may also be worth pursing.