/// <summary> /// Finds the display name for a given value in a coded value domain /// </summary> /// <param name="domain">CodedValueDomain to check</param> /// <param name="value">The value</param> /// <returns>The name, or string.Empty if not found</returns> public static string GetDomainNameForValue(ESRI.ArcGIS.Geodatabase.ICodedValueDomain domain, object value) { string result = string.Empty; if (null == domain) { throw new ArgumentNullException("domain"); } for (int i = 0; i < domain.CodeCount; i++) { object testValue = domain.get_Value(i); if (testValue.Equals(value)) { result = domain.get_Name(i); break; } } if (null == result) { throw new Exception(string.Format("value {0} not found in the domain {1}", value, ((ESRI.ArcGIS.Geodatabase.IDomain)domain).Name)); } return(result); }
/// <summary> /// Finds the actual value of a given name of a coded value domain /// </summary> /// <param name="domain">CodedValueDomain to check</param> /// <param name="name">Name of the desired value</param> /// <returns>The value</returns> public static object GetDomainValueForName(ESRI.ArcGIS.Geodatabase.ICodedValueDomain domain, string name) { object result = null; if (null == domain) { throw new ArgumentNullException("domain"); } for (int i = 0; i < domain.CodeCount; i++) { string testName = domain.get_Name(i); if (0 == string.Compare(name, testName)) { result = domain.get_Value(i); break; } } if (null == result) { throw new Exception(string.Format("name {0} not found in the domain {1}", name, ((ESRI.ArcGIS.Geodatabase.IDomain)domain).Name)); } return(result); }
/// <summary> /// Returns a display name as verified against a coded value domain. If there is not a coded value domain, just returns /// the value /// </summary> /// <param name="field">Field to check against</param> /// <param name="value">Value to check</param> /// <returns>Display name</returns> public static string CheckForCodedName(ESRI.ArcGIS.Geodatabase.IField field, object value) { // Assume no domain, in which case we will just return the input value string result = value.ToString(); if (null == field) { throw new ArgumentNullException("field"); } ESRI.ArcGIS.Geodatabase.ICodedValueDomain domain = field.Domain as ESRI.ArcGIS.Geodatabase.ICodedValueDomain; if (null != domain) { result = GetDomainNameForValue(domain, value); } return(result); }