Esempio n. 1
0
        public static string ObjectToString(bool allowReflection, object obj, int?decimalPlaces, out bool isName)
        {
            var auditLogObj = AuditLogObject.GetAuditLogObject(obj, decimalPlaces, out var usesReflection);

            isName = auditLogObj.IsName;

            if (usesReflection)
            {
                return(!allowReflection ? null : auditLogObj.AuditLogText);
            }

            var text = auditLogObj.AuditLogText;

            return(isName && !(obj is DocNode) ? LogMessage.Quote(text) : text); // DocNodes shouldn't have quotes around them
        }
Esempio n. 2
0
        public List <DiffNodeNamePair> FindAllLeafNodes(DiffTree tree, PropertyName name, bool allowReflection, DiffNode parentNode = null)
        {
            var result = new List <DiffNodeNamePair>();

            var propertyNameString = Property.GetName(tree.Root, this, parentNode);

            var isName = false;
            // Collection elements should be referred to by their name or string representation
            var propName = IsCollectionElement
                ? new PropertyElementName(ObjectToString(allowReflection, Objects.FirstOrDefault(o => o != null), out isName))
                : (Property.IsTab ? new PropertyTabName(propertyNameString) : new PropertyName(propertyNameString));

            // The name can not be ignored if the node is a collection change (since then the child nodes of the collection change
            // have the same attribute as the collection change node)
            var canIgnoreName = (Property.IgnoreName && !IsCollectionElement);

            if (!canIgnoreName)
            {
                name = name != null?name.SubProperty(propName) : propName;
            }

            // We can't display sub changes of an element if it's unnamed, so we display its
            // string representation as a change
            if (IsCollectionElement && !isName && !canIgnoreName)
            {
                result.Add(new DiffNodeNamePair(this, name, allowReflection));
                return(result);
            }

            var obj           = Objects.FirstOrDefault();
            var isNamedChange = IsFirstExpansionNode || (obj != null && AuditLogObject.GetAuditLogObject(obj).IsName) &&
                                Expanded && !canIgnoreName;

            if (isNamedChange)
            {
                result.Add(new DiffNodeNamePair(this, name, allowReflection));
            }

            if (Nodes.Count == 0)
            {
                if (!isNamedChange)
                {
                    result.Add(new DiffNodeNamePair(this, name, allowReflection));
                }
            }
            else
            {
                var collectionPropDiffNode = this as CollectionPropertyDiffNode;
                if (collectionPropDiffNode != null && collectionPropDiffNode.RemovedAll)
                {
                    result.Add(new DiffNodeNamePair(this, name, allowReflection));
                }
                else
                {
                    foreach (var n in Nodes)
                    {
                        result.AddRange(n.FindAllLeafNodes(tree, name, allowReflection, this));
                    }
                }
            }

            return(result);
        }