using System;
using System.ComponentModel;
namespace Netron.Diagramming.Core {
///
/// Type descriptor provider for all descendants of the classes.
///
class ShapeProvider : TypeDescriptionProvider {
#region Fields
///
/// simple shape descriptor
///
private static SimpleShapeBaseDescriptor simpleShapeBaseDescriptor;
///
/// complex shape descriptor
///
private static ComplexShapeBaseDescriptor complexShapeBaseDescriptor;
private static ClassShapeDescriptor classShapeDescriptor;
#endregion
#region Properties
#endregion
#region Constructor
public ShapeProvider() {
simpleShapeBaseDescriptor = new SimpleShapeBaseDescriptor(this, typeof(SimpleShapeBase));
complexShapeBaseDescriptor = new ComplexShapeBaseDescriptor(this, typeof(ComplexShapeBase));
classShapeDescriptor = new ClassShapeDescriptor(this, typeof(ClassShape));
}
#endregion
#region Methods
///
/// Gets a custom type descriptor for the given type and object.
///
/// The type of object for which to retrieve the type descriptor.
/// An instance of the type. Can be null if no instance was passed to the .
///
/// An that can provide metadata for the type.
///
public override ICustomTypeDescriptor GetTypeDescriptor(Type objectType, object instance) {
if (typeof(SimpleShapeBase).IsInstanceOfType(instance)) {
return simpleShapeBaseDescriptor;
} else if (typeof(ClassShape).IsInstanceOfType(instance)) {
return classShapeDescriptor;
} else if (typeof(ComplexShapeBase).IsInstanceOfType(instance)) {
return complexShapeBaseDescriptor;
} else //if nothing found use the base descriptor
return base.GetTypeDescriptor(objectType, instance);
}
#endregion
}
}