internal void CheckForDuplicatePropertyNames(ODataProperty property)
        {
            DuplicationRecord record;
            string            name            = property.Name;
            DuplicationKind   duplicationKind = GetDuplicationKind(property);

            if (!this.TryGetDuplicationRecord(name, out record))
            {
                this.propertyNameCache.Add(name, new DuplicationRecord(duplicationKind));
            }
            else if ((((record.DuplicationKind == DuplicationKind.Prohibited) || (duplicationKind == DuplicationKind.Prohibited)) || ((record.DuplicationKind == DuplicationKind.NavigationProperty) && record.AssociationLinkFound)) || !this.allowDuplicateProperties)
            {
                throw new ODataException(Strings.DuplicatePropertyNamesChecker_DuplicatePropertyNamesNotAllowed(name));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Check the <paramref name="property"/> for duplicate property names in an entry or complex value.
        /// If not explicitly allowed throw when duplicate properties are detected.
        /// If duplicate properties are allowed see the comment on ODataWriterBehavior.AllowDuplicatePropertyNames
        /// or ODataReaderBehavior.AllowDuplicatePropertyNames for further details.
        /// </summary>
        /// <param name="property">The property to be checked.</param>
        internal void CheckForDuplicatePropertyNames(ODataProperty property)
        {
            if (this.disabled)
            {
                return;
            }

            Debug.Assert(property != null, "property != null");
#if DEBUG
            Debug.Assert(this.startNavigationLinkName == null, "CheckForDuplicatePropertyNamesOnNavigationLinkStart was followed by a CheckForDuplicatePropertyNames(ODataProperty).");
#endif

            string            propertyName    = property.Name;
            DuplicationKind   duplicationKind = GetDuplicationKind(property);
            DuplicationRecord existingDuplicationRecord;
            if (!this.TryGetDuplicationRecord(propertyName, out existingDuplicationRecord))
            {
                this.propertyNameCache.Add(propertyName, new DuplicationRecord(duplicationKind));
            }
            else if (existingDuplicationRecord.DuplicationKind == DuplicationKind.PropertyAnnotationSeen)
            {
                existingDuplicationRecord.DuplicationKind = duplicationKind;
            }
            else
            {
                // If either of them prohibits duplication, fail
                // If the existing one is an association link, fail (association links don't allow duplicates with simple properties)
                // If we don't allow duplication in the first place, fail, since there is no valid case where a simple property coexists with anything else with the same name.
                if (existingDuplicationRecord.DuplicationKind == DuplicationKind.Prohibited ||
                    duplicationKind == DuplicationKind.Prohibited ||
                    (existingDuplicationRecord.DuplicationKind == DuplicationKind.NavigationProperty && existingDuplicationRecord.AssociationLinkName != null) ||
                    !this.allowDuplicateProperties)
                {
                    throw new ODataException(Strings.DuplicatePropertyNamesChecker_DuplicatePropertyNamesNotAllowed(propertyName));
                }
                else
                {
                    // Otherwise allow the duplicate.
                    // Note that we don't modify the existing duplication record in any way if the new property is a simple property.
                    // This is because if the existing one is a simple property which allows duplication as well, there's nothing to change.
                    // and if the existing one is a navigation property the navigation property information is more important than the simple property one.
                }
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="duplicationKind">The duplication kind of the record to create.</param>
 public DuplicationRecord(DuplicationKind duplicationKind)
 {
     this.DuplicationKind = duplicationKind;
 }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="duplicationKind">The duplication kind of the record to create.</param>
 public DuplicationRecord(DuplicationKind duplicationKind)
 {
     this.DuplicationKind = duplicationKind;
 }