internal static string CodedValueNameLookup(string lookupField, string field, object generic, DynamicCodedValueSource dynamicCodedValueSource) { if (dynamicCodedValueSource != null && generic != null && !string.IsNullOrEmpty(field)) { #if SILVERLIGHT PropertyInfo lookupFieldProperty = generic.GetType().GetProperty(lookupField); if (lookupFieldProperty == null) { return(null); } var key = lookupFieldProperty.GetValue(generic, null); #else var key = generic is Graphic ? (generic as Graphic).Attributes[lookupField] : null; #endif if (key == null) { return(CodedValueSources.CodedValueNameLookup(field, generic, new CodedValueSources())); } if (dynamicCodedValueSource.ContainsKey(key)) { CodedValueSources codedValueSources = dynamicCodedValueSource[key]; if (codedValueSources != null) { string name = CodedValueSources.CodedValueNameLookup(field, generic, codedValueSources); if (!string.IsNullOrEmpty(name)) { return(name); } } } else if (dynamicCodedValueSource.ContainsKey(key.ToString())) { CodedValueSources codedValueSources = dynamicCodedValueSource[key.ToString()]; if (codedValueSources != null) { string name = CodedValueSources.CodedValueNameLookup(field, generic, codedValueSources); if (!string.IsNullOrEmpty(name)) { return(name); } } } else { PropertyInfo FieldProperty = generic.GetType().GetProperty(field); if (FieldProperty == null) { return(null); } var value = FieldProperty.GetValue(generic, null); return(value != null?value.ToString() : null); } } return(null); }
internal static CodedValueSources GetCodedValueSources(string lookupField, Field field, object generic, DynamicCodedValueSource dynamicCodedValueSource, CodedValueSources nullableSources) { if (dynamicCodedValueSource != null && generic != null && !string.IsNullOrEmpty(lookupField)) { #if SILVERLIGHT PropertyInfo lookupFieldProperty = generic.GetType().GetProperty(lookupField); if (lookupFieldProperty == null) { return(null); } var key = lookupFieldProperty.GetValue(generic, null); #else var key = (generic is Graphic) ? (generic as Graphic).Attributes[lookupField] : null; #endif if (key == null) { object code = CodedValueSources.CodedValueCodeLookup(field.Name, generic, new CodedValueSources()); nullableSources.Clear(); if (field.Nullable) { CodedValueSource nullableSource = new CodedValueSource() { Code = null, DisplayName = " " }; nullableSources.Add(nullableSource); } if (code != null) { CodedValueSource currentSource = new CodedValueSource() { Code = code, DisplayName = code.ToString() }; nullableSources.Add(currentSource); } return(nullableSources); } CodedValueSources codedValueSoruces = null; if (dynamicCodedValueSource.ContainsKey(key)) { codedValueSoruces = dynamicCodedValueSource[key]; } else if (dynamicCodedValueSource.ContainsKey(key.ToString())) { codedValueSoruces = dynamicCodedValueSource[key.ToString()]; } CodedValueSource tempSource = codedValueSoruces.FirstOrDefault(x => x.Temp == true); if (tempSource != null) { codedValueSoruces.Remove(tempSource); } #if SILVERLIGHT object value = CodedValueSources.CodedValueNameLookup(field.Name, generic, new CodedValueSources()); if (string.IsNullOrEmpty(value as string)) { value = null; } #else object value = (generic as Graphic).Attributes[field.Name]; #endif if (value != null) { CodedValueSource source = codedValueSoruces.FirstOrDefault(x => x.Code != null && x.Code.ToString() == value.ToString()); if (source == null) { CodedValueSource currentSource = new CodedValueSource() { Code = value, DisplayName = value.ToString(), Temp = true }; if (field.Nullable) { codedValueSoruces.Insert(1, currentSource); } else { codedValueSoruces.Insert(0, currentSource); } } } return(codedValueSoruces); } return(null); }