/// <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); }