FieldInformation類用于儲存字段資訊:
public class FieldInformation
{
public int Index { get; set; }
public bool Editable { get; set; }
public string Name { get; set; }
public esriFieldType FieldType { get; set; }
public int Precision { get; set; }
public int Scale { get; set; }
public int Length { get; set; }
public string Alias { get; set; }
public bool IsNullable { get; set; }
public bool IsRequired { get; set; }
}
擷取字段資訊的方法:
public static List<FieldInformation> GetFieldInformation(IFields pFields, string sTableName = "")
{
List<FieldInformation> lstFieldInformation = null;
try
{
var nFieldCount = pFields.FieldCount;
for (int i = 0; i < nFieldCount; i++)
{
var pField = pFields.Field[i];
if (null == pField) continue;
var sFieldName = pField.Name;
if (!string.IsNullOrEmpty(sTableName))
{
var nIndexOfDot = sFieldName.LastIndexOf(".");
if (nIndexOfDot > 0)
{
var sFieldTable = sFieldName.Substring(0, nIndexOfDot);
if (0 != string.Compare(sTableName, sFieldTable, StringComparison.OrdinalIgnoreCase))
{
continue;
}
sFieldName = sFieldName.Substring(nIndexOfDot + 1);
}
}
if (null == lstFieldInformation) lstFieldInformation = new List<FieldInformation>();
lstFieldInformation.Add(new FieldInformation()
{
Index = i,
Editable = pField.Editable,
Name = sFieldName,
FieldType = pField.Type,
Precision = pField.Precision,
Scale = pField.Scale,
Length = pField.Length,
Alias = pField.AliasName,
IsNullable = pField.IsNullable,
IsRequired = pField.Required
});
}
return lstFieldInformation;
}
catch
{
return null;
}
}