Esempio n. 1
0
        /// <summary>
        /// get property wrapper for a property name, might be method around open types for otherwise unknown properties
        /// </summary>
        /// <param name="propertyName">property name</param>
        /// <param name="undeclaredPropertyBehavior">UndeclaredPropertyBehavior</param>
        /// <returns>property wrapper</returns>
        /// <exception cref="InvalidOperationException">for unknown properties on closed types</exception>
        internal ClientPropertyAnnotation GetProperty(string propertyName, UndeclaredPropertyBehavior undeclaredPropertyBehavior)
        {
            Debug.Assert(propertyName != null, "property name");
            if (this.clientPropertyCache == null)
            {
                this.BuildPropertyCache();
            }

            ClientPropertyAnnotation property;

            if (!this.clientPropertyCache.TryGetValue(propertyName, out property))
            {
                string propertyClientName = ClientTypeUtil.GetClientPropertyName(this.ElementType, propertyName, undeclaredPropertyBehavior);
                if ((string.IsNullOrEmpty(propertyClientName) || !this.clientPropertyCache.TryGetValue(propertyClientName, out property)) && (undeclaredPropertyBehavior == UndeclaredPropertyBehavior.ThrowException))
                {
                    throw Microsoft.OData.Client.Error.InvalidOperation(Microsoft.OData.Client.Strings.ClientType_MissingProperty(this.ElementTypeName, propertyName));
                }
            }

            return(property);
        }
Esempio n. 2
0
        /// <summary>
        /// get property wrapper for a property name, might be method around open types for otherwise unknown properties
        /// </summary>
        /// <param name="propertyName">property name</param>
        /// <param name="ignoreMissingProperties">are missing properties ignored</param>
        /// <returns>property wrapper</returns>
        /// <exception cref="InvalidOperationException">for unknown properties on closed types</exception>
        internal ClientPropertyAnnotation GetProperty(string propertyName, bool ignoreMissingProperties)
        {
            Debug.Assert(propertyName != null, "property name");
            if (this.clientPropertyCache == null)
            {
                this.BuildPropertyCache();
            }

            ClientPropertyAnnotation property;

            if (!this.clientPropertyCache.TryGetValue(propertyName, out property))
            {
                string propertyClientName = ClientTypeUtil.GetClientPropertyName(this.ElementType, propertyName, ignoreMissingProperties);
                if ((string.IsNullOrEmpty(propertyClientName) || !this.clientPropertyCache.TryGetValue(propertyClientName, out property)) && !ignoreMissingProperties)
                {
                    throw Microsoft.OData.Client.Error.InvalidOperation(Microsoft.OData.Client.Strings.ClientType_MissingProperty(this.ElementTypeName, propertyName));
                }
            }

            return(property);
        }