ArcGIS Pro 3.4 API Reference Guide
ArcGIS.Core.Data Namespace / FeatureClass Class / GetDefinition Method
Example Version

GetDefinition Method (FeatureClass)
Gets the FeatureClassDefinition of this dataset.
Syntax
public new FeatureClassDefinition GetDefinition()

Return Value

The FeatureClassDefinition of this dataset.
Exceptions
ExceptionDescription
This dataset does not have a valid definition.
A geodatabase-related exception has occurred.
Remarks
This routine will throw an exception if called on a joined feature class, since there is no underlying datastore for these temporary datasets. Table.IsJoinedTable can be used to determine if this feature class represents a join.
Example
Getting a Table Definition from a Layer
// GetDefinitionFromLayer - This code works even if the layer has a join to another table
private TableDefinition GetDefinitionFromLayer(FeatureLayer featureLayer)
{
    // Get feature class from the layer
    FeatureClass featureClass = featureLayer.GetFeatureClass();

    // Determine if feature class is a join
    if (featureClass.IsJoinedTable())
    {
        // Get join from feature class
        Join join = featureClass.GetJoin();

        // Get origin table from join
        Table originTable = join.GetOriginTable();

        // Return feature class definition from the join's origin table
        return originTable.GetDefinition();
    }
    else
    {
        return featureClass.GetDefinition();
    }
}
Sorting a Table
public RowCursor SortWorldCities(FeatureClass worldCitiesTable)
{
    using (FeatureClassDefinition featureClassDefinition = worldCitiesTable.GetDefinition())
    {
        Field countryField = featureClassDefinition.GetFields()
          .First(x => x.Name.Equals("COUNTRY_NAME"));
        Field cityNameField = featureClassDefinition.GetFields()
          .First(x => x.Name.Equals("CITY_NAME"));

        // Create SortDescription for Country field
        SortDescription countrySortDescription = new SortDescription(countryField);
        countrySortDescription.CaseSensitivity = CaseSensitivity.Insensitive;
        countrySortDescription.SortOrder = SortOrder.Ascending;

        // Create SortDescription for City field
        SortDescription citySortDescription = new SortDescription(cityNameField);
        citySortDescription.CaseSensitivity = CaseSensitivity.Insensitive;
        citySortDescription.SortOrder = SortOrder.Ascending;

        // Create our TableSortDescription
        TableSortDescription tableSortDescription = new TableSortDescription(
          new List<SortDescription>() { countrySortDescription, citySortDescription });

        return worldCitiesTable.Sort(tableSortDescription);
    }
}
Use Select or Search with a Spatial Query
//var featSceneLayer = ...;
//var sname = featSceneLayer.Name;
await QueuedTask.Run(() =>
{
  if (!featSceneLayer.HasAssociatedFeatureService)
    return;//no search or select

  //Select all features within the current map view
  var sz = MapView.Active.GetViewSize();
  var map_pt1 = MapView.Active.ClientToMap(new System.Windows.Point(0, sz.Height));
  var map_pt2 = MapView.Active.ClientToMap(new System.Windows.Point(sz.Width, 0));

  //Convert to an envelope
  var temp_env = EnvelopeBuilderEx.CreateEnvelope(map_pt1, map_pt2, MapView.Active.Map.SpatialReference);

  //Project if needed to the layer spatial ref
  SpatialReference sr = null;
  using (var fc = featSceneLayer.GetFeatureClass())
  using (var fdef = fc.GetDefinition())
    sr = fdef.GetSpatialReference();

  var env = GeometryEngine.Instance.Project(temp_env, sr) as Envelope;

  //Set up a query filter
  var sf = new SpatialQueryFilter()
  {
    FilterGeometry = env,
    SpatialRelationship = SpatialRelationship.Intersects,
    SubFields = "*"
  };

  //Select against the feature service
  var select = featSceneLayer.Select(sf);
  if (select.GetCount() > 0)
  {
    //enumerate over the selected features
    using (var rc = select.Search())
    {
      while (rc.MoveNext())
      {
        using (var feature = rc.Current as Feature)
        {
          var oid = feature.GetObjectID();
          //etc.
        }
      }
    }
  }

  MapView.Active.Map.ClearSelection();

});
Requirements

Target Platforms: Windows 11, Windows 10

ArcGIS Pro version: 3 or higher.
See Also