public void TestGetCodedValues() { IWorkspace workspace = WorkspaceUtils.OpenPgdbWorkspace(_simpleGdbPath); SortedDictionary <int, string> list = DomainUtils.GetCodedValueMap <int>( workspace, "TestCodedValueDomain"); Assert.AreEqual(5, list.Count); Assert.AreEqual("Value7", list[7]); }
protected virtual SortedDictionary <string, object> GetCodeValuesCore( [NotNull] IField field, [NotNull] IObjectClass table) { _msg.VerboseDebugFormat("Reading values for field {0}", field.Name); SortedDictionary <string, object> codeValues; var codedValueDomain = field.Domain as ICodedValueDomain; if (codedValueDomain == null) { int fieldIndex = table.FindField(field.Name); if (table is ISubtypes subtypesTbl && subtypesTbl.SubtypeFieldIndex == fieldIndex) { IList <Subtype> subtypes = DatasetUtils.GetSubtypes(table); codeValues = new SortedDictionary <string, object>(); foreach (Subtype subtype in subtypes) { codeValues.Add(subtype.Name, subtype.Code); } return(codeValues); } } Assert.True(codedValueDomain != null, "Field '{0}' not a coded value domain", field.Name); SortedDictionary <object, string> valueCodes = DomainUtils.GetCodedValueMap <object>(codedValueDomain); codeValues = new SortedDictionary <string, object>(); foreach (KeyValuePair <object, string> pair in valueCodes) { _msg.VerboseDebugFormat("Adding key / value pair {0} / {1} to result", pair.Value, pair.Key); codeValues.Add(pair.Value, pair.Key); } Assert.True(codeValues.ContainsKey(_nullValue) == false, _nullValue + " exists in domain of field " + field.Name); // add <Null> Value object nullObject = GetNullObject(field, valueCodes); codeValues.Add(_nullValue, nullObject); return(codeValues); }