private void Initialize() { isDynamicCodedValue = false; isCodedValue = false; isTypeIDField = false; dynamicCodedValueSource = null; codedValueSources = null; TypeIDField = string.Empty; if (string.IsNullOrEmpty(_field) || _layerInfo == null) { return; } TypeIDField = _layerInfo.TypeIdField; Field field = _layerInfo.Fields.FirstOrDefault(x => x.Name == _field); isDynamicCodedValue = FieldDomainUtils.IsDynamicDomain(field, LayerInfo); isCodedValue = (field.Domain is CodedValueDomain); isTypeIDField = (field.Name == TypeIDField); if (isDynamicCodedValue) { dynamicCodedValueSource = FieldDomainUtils.BuildDynamicCodedValueSource(field, _layerInfo); } else if (isTypeIDField) { codedValueSources = FieldDomainUtils.BuildTypeIDCodedValueSource(field, _layerInfo); } else if (isCodedValue) { codedValueSources = FieldDomainUtils.BuildCodedValueSource(field); } }
internal int Compare(Graphic x, Graphic y) { var o1 = x.Attributes[Field]; // get primitive value var o2 = y.Attributes[Field]; // get primitive value if (isDynamicCodedValue) { o1 = DynamicCodedValueSource.CodedValueNameLookup(TypeIDField, Field, x, dynamicCodedValueSource); o2 = DynamicCodedValueSource.CodedValueNameLookup(TypeIDField, Field, y, dynamicCodedValueSource); } if (isCodedValue || isTypeIDField) { o1 = CodedValueSources.CodedValueNameLookup(Field, x, codedValueSources); o2 = CodedValueSources.CodedValueNameLookup(Field, y, codedValueSources); } return(comparer.Compare(o1, o2)); // compare primitives }
/// <summary> /// Builds a DynamicCodedValueSource object used to lookup display value. /// </summary> /// <param name="field">The field to build DynamicCodedValueSource for</param> /// <param name="layerInfo">The FeatureLayerInfo used to lookup all the coded value domains </param> /// <returns>DynamicCodedValueSource which is a collection of coded value domain values for a field.</returns> internal static DynamicCodedValueSource BuildDynamicCodedValueSource(Field field, FeatureLayerInfo layerInfo) { DynamicCodedValueSource dynamicCodedValueSource = null; foreach (object key in layerInfo.FeatureTypes.Keys) { FeatureType featureType = layerInfo.FeatureTypes[key]; if (featureType.Domains.ContainsKey(field.Name)) { if (dynamicCodedValueSource == null) dynamicCodedValueSource = new DynamicCodedValueSource(); CodedValueDomain codedValueDomain = featureType.Domains[field.Name] as CodedValueDomain; if (codedValueDomain != null) { CodedValueSources codedValueSources = null; foreach (KeyValuePair<object, string> kvp in codedValueDomain.CodedValues) { if (codedValueSources == null) { codedValueSources = new CodedValueSources(); if (field.Nullable) { CodedValueSource nullableSource = new CodedValueSource() { Code = null, DisplayName = " " }; codedValueSources.Add(nullableSource); } } codedValueSources.Add(new CodedValueSource() { Code = kvp.Key, DisplayName = kvp.Value }); } if (codedValueSources != null) { if (dynamicCodedValueSource == null) dynamicCodedValueSource = new DynamicCodedValueSource(); dynamicCodedValueSource.Add(featureType.Id, codedValueSources); } } } } return dynamicCodedValueSource; }
internal int Compare(Graphic x, Graphic y) { var o1 = x.Attributes[Field]; // get primitive value var o2 = y.Attributes[Field]; // get primitive value if (o1 == null && o2 == null) { return(0); } else if (o1 != null && o2 == null) { return(1); } else if (o1 == null && o2 != null) { return(-1); } var type = NonNullableType(DataType); var t1 = o1.GetType(); var t2 = o2.GetType(); if (type == typeof(DateTime)) { if (t1 != type && t2 != type) { return(0); } if (t1 != type && t2 == type) { return(-1); } if (t1 == type && t2 != type) { return(1); } } else { if (t1 != type) { o1 = Convert.ChangeType(o1, type); } if (t2 != type) { o2 = Convert.ChangeType(o2, type); } } if (isDynamicCodedValue) { o1 = DynamicCodedValueSource.CodedValueNameLookup(TypeIDField, Field, x, dynamicCodedValueSource); o2 = DynamicCodedValueSource.CodedValueNameLookup(TypeIDField, Field, y, dynamicCodedValueSource); } else if (isCodedValue || isTypeIDField) { o1 = CodedValueSources.CodedValueNameLookup(Field, x, codedValueSources); o2 = CodedValueSources.CodedValueNameLookup(Field, y, codedValueSources); } return(comparer.Compare(o1, o2)); // compare primitives }