/// <summary> /// This method attaches or detaches the "TabbedInspector" class extension to/from the specified /// feature class. If the featureclass already has an extension class, and it isn't the 'TabbedInspector' extension, /// the method does not modify the class extension. /// </summary> /// <param name="fc">The feature class to be altered.</param> /// <returns>Whether the operation succeeded (successful detach or attach).</returns> bool AlterClassExtension(IFeatureClass fc) { // Attempt to get access to schema-editing functionality on the feature class IClassSchemaEdit classSchemaEdit = fc as IClassSchemaEdit; if (classSchemaEdit == null) { m_appServices.SetStatusMessage("The selected feature class doesn't support attaching an extension class.", true); return(false); } // Create a UID object holding the TabbedInspector's CLSID UID classUID = new UIDClass(); classUID.Value = "{" + TabbedInspector.TabbedInspectorCLSID + "}"; // Do the schema update within a schema lock. bool succeeded = false; DoInSchemaLock(fc, delegate { // Does the feature class already have an extension class associated with it? if (fc.EXTCLSID != null) { // The featureclass already has an extension attached. if (fc.EXTCLSID.Value.Equals(classUID.Value)) { // The extension is the TabbedInspector extension. Detach it. classSchemaEdit.AlterClassExtensionCLSID(null, null); m_appServices.SetStatusMessage( string.Format("The 'custom inspector' extension class was detached from {0}.", fc.AliasName), false); succeeded = true; } else { //Don't mess with featureclasses that have some other existing extension class associated with them. m_appServices.SetStatusMessage( string.Format("{0} already has another extension class attached to it. No change was made.", fc.AliasName), true); succeeded = false; } } else { // There is no extension attached to the featureclass. Attach the TabbedInspector extension. classSchemaEdit.AlterClassExtensionCLSID(classUID, null); m_appServices.SetStatusMessage( string.Format("The 'custom inspector' extension class was attached to {0}.", fc.AliasName), false); succeeded = true; } }); return(succeeded); }
public void IClassSchemaEdit_Example(IObjectClass objectClass) { //This function shows how you can use the IClassSchemaEdit //interface to alter the COM class extension for an object class. //cast for the IClassSchemaEdit IClassSchemaEdit classSchemaEdit = (IClassSchemaEdit)objectClass; //set and exclusive lock on the class ISchemaLock schemaLock = (ISchemaLock)objectClass; schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock); ESRI.ArcGIS.esriSystem.UID classUID = new ESRI.ArcGIS.esriSystem.UIDClass(); //GUID for the C# project. classUID.Value = "{65a43962-8cc0-49c0-bfa3-015d0ff8350e}"; classSchemaEdit.AlterClassExtensionCLSID(classUID, null); //release the exclusive lock schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock); }