static string TextFunc(TypeNameValue tnv) { if (tnv.Type == null) { if (tnv.Value is null) { return(string.Format("<no properties>")); } string typeName = tnv.Value.GetType().Name; if (tnv.Value is FontFamily ff) { return(string.Format("{0} (Source={1})", typeName, ff.Source)); } else if (tnv.Value is DictionaryEntry de) { return(string.Format("{0} (Key={1})", typeName, de.Key)); } else if (tnv.Value is FamilyTypeface ft) { return(string.Format("{0} (Style={1},Weight={2},Stretch={3})", typeName, ft.Style, ft.Weight, ft.Stretch)); } else if (tnv.Value is FontFamilyMap ffm) { return(string.Format("{0} (Unicode={1})", typeName, ffm.Unicode)); } else if (tnv.Value is Typeface t) { return(string.Format("{0} (Style={1},Weight={2},Stretch={3})", typeName, t.Style, t.Weight, t.Stretch)); } else if (tnv.Value is KeyValuePair <XmlLanguage, string> kvp) { return(string.Format("{0} (Key={1})", "KeyValuePair<XmlLanguage, string>", kvp.Key)); } else if (tnv.Value is KeyValuePair <CultureInfo, String> kvp1) { return(string.Format("{0} (Key={1})", "KeyValuePair<CultureInfo, String>", kvp1.Key)); } else if (tnv.Value is KeyValuePair <UInt16, Double> kvp2) { return(string.Format("{0} (Key={1})", "KeyValuePair<UInt16, Double>", kvp2.Key)); } else if (tnv.Value is KeyValuePair <Int32, UInt16> kvp3) { return(string.Format("{0} (Key={1})", "KeyValuePair<Int32, UInt16>", kvp3.Key)); } else { return(string.Format("{0} {1}", typeName, tnv.Value)); } } else { string typeName = tnv.Type.Name; if (tnv.Value == null) { return(string.Format("{0} {1}=<null>", typeName, tnv.Name)); } else if (tnv.Value is IEnumerable && !(tnv.Value is string)) { PropertyInfo countProp = tnv.Value.GetType().GetProperty("Count"); if (countProp != null) { int count = (int)countProp.GetValue(tnv.Value, null); return(string.Format("{0} {1} (Count={2})", typeName, tnv.Name, count)); } else { return(string.Format("{0} {1}", typeName, tnv.Name)); } } else { if (tnv.Value.GetType() != tnv.Type) { string sourceTypeName = tnv.Value.GetType().Name; return(string.Format("{0} {1}=(Source Type={2}) {3}", typeName, tnv.Name, sourceTypeName, tnv.Value)); } else { return(string.Format("{0} {1}={2}", typeName, tnv.Name, tnv.Value)); } } } }
//static Func<TypeNameValue, bool> FalseFunc = (tnv) => { return false; }; static bool FalseFunc(TypeNameValue tnv) { return(false); }