ArcGIS Pro 3.8 API Reference Guide
ArcGIS.Desktop.Editing.Attributes Namespace / Attribute Class / FieldName Property
Example

In This Topic
    FieldName Property (Attribute)
    In This Topic
    Gets the field name of this attribute.
    Syntax
    public string FieldName {get;}
    Public ReadOnly Property FieldName As String
    Example
    Create feature from a modified inspector
    // Creates a new feature by copying and optionally modifying the attributes of an existing feature using an inspector.
    await QueuedTask.Run(() =>
        {
          // Create an inspector and load a feature
          // The inspector is used to modify the attributes of the feature before creating it
          var insp = new Inspector();
          insp.Load(featureLayer, objectId);
          // modify attributes if necessary
          // insp["Field1"] = newValue;
    
          //Create new feature from an existing inspector (copying the feature)
          var createOp = new EditOperation() { Name = "Create from insp" };
          createOp.Create(insp.MapMember, insp.ToDictionary(a => a.FieldName, a => a.CurrentValue));
    
          if (!createOp.IsEmpty)
          {
            var result = createOp.Execute(); //Execute and ExecuteAsync will return true if the operation was successful and false if not
          }
        });
    Edit Operation Duplicate Features
    // Duplicates a feature in a feature layer and modifies its geometry.
    await QueuedTask.Run(() =>
      {
        var duplicateFeatures = new EditOperation() { Name = "Duplicate Features" };
    
        //Duplicate with an X and Y offset of 500 map units
    
        //Execute to execute the operation
        //Must be called within QueuedTask.Run
        var insp2 = new Inspector();
        insp2.Load(featureLayer, objectId);
        var geom = insp2["SHAPE"] as Geometry;
    
        var rtoken = duplicateFeatures.Create(insp2.MapMember, insp2.ToDictionary(a => a.FieldName, a => a.CurrentValue));
        if (!duplicateFeatures.IsEmpty)
        {
          if (duplicateFeatures.Execute())//Execute and ExecuteAsync will return true if the operation was successful and false if not
          {
            var modifyOp = duplicateFeatures.CreateChainedOperation();
            modifyOp.Modify(featureLayer, (long)rtoken.ObjectID, GeometryEngine.Instance.Move(geom, 500.0, 500.0));
            if (!modifyOp.IsEmpty)
            {
              var result = modifyOp.Execute();
            }
          }
        }
      });
    Get a layers schema using Inspector
    // Loads the schema of the specified feature layer and iterates through its attributes,  providing access to their properties such as field name, alias, type, and other metadata.
    await QueuedTask.Run(() =>
    {
      // create an instance of the inspector class
      var inspector = new Inspector();
      // load the layer
      inspector.LoadSchema(featureLayer);
      // iterate through the attributes, looking at properties
      foreach (var attribute in inspector)
      {
        var fldName = attribute.FieldName;
        var fldAlias = attribute.FieldAlias;
        var fldType = attribute.FieldType;
        int idxFld = attribute.FieldIndex;
        var fld = attribute.GetField();
        var isNullable = attribute.IsNullable;
        var isEditable = attribute.IsEditable;
        var isVisible = attribute.IsVisible;
        var isSystemField = attribute.IsSystemField;
        var isGeometryField = attribute.IsGeometryField;
      }
    });
    Adds a custom validation rule to the "Mineral" field of the specified feature layer.
    await QueuedTask.Run(() =>
    {
      var insp = new Inspector();
      insp.LoadSchema(featureLayer);
    
      bool success = insp.TrySetValue("mineral", "Salt");
      object result = null;
      success = insp.TryGetValue("mineral", out result);
      if (result != null && success)
      {
        MessageBox.Show($"Successfully stored and retrieved the value of field 'Mineral': {result.ToString()}");
      }
    
      var attrib = insp.Where(a => a.FieldName == "Mineral").First();
      attrib.AddValidate(() =>
      {
        if (attrib.CurrentValue.ToString() == "Salt")
        {
          return [];
        }
        else
        {
          return [ArcGIS.Desktop.Editing.Attributes.Attribute.ValidationError.Create("Error", Severity.Low)];
        }
      });
    });
    Using the custom inspector provider class
    /// <summary>
    /// Demonstrates the use of a custom InspectorProvider to create and load an inspector for a specific feature.
    /// </summary>
    public static async void InspectorProviderExample(FeatureLayer featureLayer, long objectId)
    {
      var provider = new MyProvider();
      Inspector _featureInspector = provider.Create();
      //Create an embed-able control from the inspector class to display on the pane
      var icontrol = _featureInspector.CreateEmbeddableControl();
    
      await _featureInspector.LoadAsync(featureLayer, objectId);
      var attribute = _featureInspector.Where(a => a.FieldName == "FontStyle").FirstOrDefault();
      var visibility = attribute.IsVisible; //Will return false
    
      attribute = _featureInspector.Where(a => a.FieldName == "ZOrder").FirstOrDefault();
      var highlighted = attribute.IsHighlighted; //Will return true
    }
    Requirements

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

    ArcGIS Pro version: 3.0 or higher.
    See Also