ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Core.Data Namespace / Geodatabase Class / GetDefinition<T> Method
The type of dataset definition.
The name of the dataset.
Example

In This Topic
    GetDefinition<T> Method (Geodatabase)
    In This Topic
    Gets a specific Definition instance associated with name of type T in the geodatabase. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    Public Function GetDefinition(Of T As Definition)( _
       ByVal name As String _
    ) As T
    public T GetDefinition<T>( 
       string name
    )
    where T: Definition

    Parameters

    name
    The name of the dataset.

    Type Parameters

    T
    The type of dataset definition.

    Return Value

    A specific Definition instance corresponding to type T.
    Exceptions
    ExceptionDescription

    No valid geodatabase has been opened prior to calling this operation.

    -or-

    The DatasetType corresponding to type T is not supported.

    name is invalid (e.g., a null value or an empty string).
    name does not exist or cannot be opened in the geodatabase.
    A geodatabase-related exception has occurred.
    Example
    Obtaining Definition from Geodatabase
    {
      await QueuedTask.Run(() =>
      {
        using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(new Uri("path\\to\\sde\\file\\sdefile.sde"))))
        {
          // Remember that for Enterprise databases you have to qualify your dataset names with the DatabaseName and UserName.
          TableDefinition enterpriseTableDefinition = geodatabase.GetDefinition<TableDefinition>("LocalGovernment.GDB.CitizenContactInfo");
    
          // It does not matter if the dataset is within a FeatureDataset or not.
          FeatureClassDefinition featureClassDefinition = geodatabase.GetDefinition<FeatureClassDefinition>("LocalGovernment.GDB.FireStation");
    
          // GetDefinition For a RelationshipClass.
          RelationshipClassDefinition relationshipClassDefinition = geodatabase.GetDefinition<RelationshipClassDefinition>(
              "LocalGovernment.GDB.AddressPointHasSiteAddresses");
    
          // GetDefinition For a FeatureDataset.
          FeatureDatasetDefinition featureDatasetDefinition = geodatabase.GetDefinition<FeatureDatasetDefinition>("LocalGovernment.GDB.Address");
        }
      });
    }
    Obtaining Definitions from a Feature Service by Layer ID
    {
      //Url examples for (federated) feature services
      //(by "ref" online):
      var url =
          @"https://sampleserver6.arcgisonline.com/arcgis/rest/services/SF311/FeatureServer";
      //(federated by ref on portal)
      //https://portal.example.com/server/rest/services/FeatureServiceName/FeatureServer");
      //(federated by value - Hosted - on portal)
      //https://portal.example.com/server/rest/services/Hosted/FeatureServiceName/FeatureServer");
    
      await QueuedTask.Run(() =>
      {
        var uri = new Uri(url, UriKind.Absolute);
        using (var fs_db = new ArcGIS.Core.Data.Geodatabase(new ServiceConnectionProperties(uri)))
        {
          //Assuming that id 0 is a FeatureClass for the given service
          FeatureClassDefinition featureClassDefinition =
              fs_db.GetDefinition<FeatureClassDefinition>("0");
          string shapeField = featureClassDefinition.GetShapeField();
          IReadOnlyList<Field> fields = featureClassDefinition.GetFields();
    
          //Assuming that id 1 is a Table for the given service
          TableDefinition tableDefinition =
                fs_db.GetDefinition<TableDefinition>("1");
          string objectIDField = tableDefinition.GetObjectIDField();
        }
      });
    }
    Checking for the existence of a Table
    {
      //Must be called within QueuedTask.Run().
      bool TableExists(Geodatabase geodatabase, string tableName)
      {
        try
        {
          using TableDefinition tableDefinition =
            geodatabase.GetDefinition<TableDefinition>(tableName);
          return true;
        }
        catch
        {
          // GetDefinition throws an exception if the definition doesn't exist
          return false;
        }
      }
    }
    Checking for the existence of a Feature Class
    {
      //Must be called within QueuedTask.Run().
      bool FeatureClassExists(Geodatabase geodatabase, string featureClassName)
      {
        try
        {
          using FeatureClassDefinition featureClassDefinition =
            geodatabase.GetDefinition<FeatureClassDefinition>(featureClassName);
          return true;
        }
        catch
        {
          // GetDefinition throws an exception if the definition doesn't exist
          return false;
        }
      }
    }
    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.0 or higher.
    See Also