Esempio n. 1
0
        /// <summary>
        ///     XmlSerialize object without processing instructions, remove all tags & collapse any white-space to a single space,
        ///     convert all apply ToLocalTime to all DateTime properties
        /// </summary>
        /// <param name="baseDoc"></param>
        /// <returns></returns>
        public int CalcDocChecksum(BaseDoc baseDoc, bool?docStatus = null)
        {
            docStatus = docStatus ?? baseDoc.DocStatus;

            // absolutely necessary the object is not altered in any way shape of form
            //TODO:implement NormalizeDateTimePropertyValues recursively & properly
            baseDoc = baseDoc.Clone(); // NormalizeDateTimePropertyValues();

            // strip the processing instruction values so they don't yield a different rendering of the object
            foreach (PropertyInfo p in typeof(DocProcessingInstructions).GetProperties()
                     .Where(p => p.CanWrite && p.PropertyType.IsValueType))
            {
                p.SetValue(baseDoc, Activator.CreateInstance(p.PropertyType), null);
            }

            using (StringWriter _StringWriter = new StringWriter())
                using (XmlTextWriter _XmlTextWriter = new XmlTextWriter(_StringWriter)) {
                    new XmlSerializer(baseDoc.GetType()).Serialize(_XmlTextWriter, baseDoc);
                    return(_StringWriter.ToString()
                           .GetHashCode() ^ (docStatus ?? false).GetHashCode());
                }
        }