public static string ObjectToXml(T data, SimpleFileLogger logger = null)
        {
            var result = string.Empty;

            try
            {
                using (var stringWriter = new System.IO.StringWriter())
                {
                    var serializer = new XmlSerializer(data.GetType());
                    serializer.Serialize(stringWriter, data);
                    result = stringWriter.ToString();
                }
            }
            catch (System.InvalidOperationException)
            {
                result = string.Empty;
            }
            logger?.Log(result);
            return(result);
        }
Beispiel #2
0
        public static string DumpInterface <T>(this T obj, SimpleFileLogger logger = null)
        {
            var sb    = new StringBuilder();
            var t     = obj.GetType();
            var props = t.GetProperties();

            foreach (var prop in props)
            {
                try
                {
                    sb.AppendLine(prop.GetIndexParameters().Length == 0
                        ? $"{prop.Name}={prop.GetValue(obj)}"
                        : $" {prop.Name}, {prop.PropertyType.Name} <Indexed>");
                }
                catch (Exception /*dont care*/)
                {
                    // ignored
                }
            }
            logger?.Log(sb.ToString());
            return(sb.ToString());
        }