Пример #1
0
        private void SetMimeTypeForProperties(IEdmStructuredType edmStructuredType)
        {
            Func <IEdmProperty, bool> predicate = null;
            Func <IEdmProperty, bool> func2     = null;
            MimeTypePropertyAttribute attribute = (MimeTypePropertyAttribute)this.GetClientTypeAnnotation(edmStructuredType).ElementType.GetCustomAttributes(typeof(MimeTypePropertyAttribute), true).SingleOrDefault <object>();

            if (attribute != null)
            {
                if (predicate == null)
                {
                    predicate = p => p.Name == attribute.DataPropertyName;
                }
                IEdmProperty edmProperty = edmStructuredType.Properties().SingleOrDefault <IEdmProperty>(predicate);
                if (edmProperty == null)
                {
                    throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.ClientType_MissingMimeTypeDataProperty(this.GetClientTypeAnnotation(edmStructuredType).ElementTypeName, attribute.DataPropertyName));
                }
                if (func2 == null)
                {
                    func2 = p => p.Name == attribute.MimeTypePropertyName;
                }
                IEdmProperty property2 = edmStructuredType.Properties().SingleOrDefault <IEdmProperty>(func2);
                if (property2 == null)
                {
                    throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.ClientType_MissingMimeTypeProperty(this.GetClientTypeAnnotation(edmStructuredType).ElementTypeName, attribute.MimeTypePropertyName));
                }
                this.GetClientPropertyAnnotation(edmProperty).MimeTypeProperty = this.GetClientPropertyAnnotation(property2);
            }
        }
Пример #2
0
        /// <summary>
        /// Find properties with dynamic MIME type related properties and
        /// set the references from each ClientProperty to its related MIME type property
        /// </summary>
        /// <param name="edmStructuredType">Client edm type instance to wire up the mime type properties.</param>
        private void SetMimeTypeForProperties(IEdmStructuredType edmStructuredType)
        {
            MimeTypePropertyAttribute attribute = (MimeTypePropertyAttribute)this.GetClientTypeAnnotation(edmStructuredType).ElementType.GetCustomAttributes(typeof(MimeTypePropertyAttribute), true).SingleOrDefault();

            if (null != attribute)
            {
                IEdmProperty dataProperty = edmStructuredType.Properties().SingleOrDefault(p => p.Name == attribute.DataPropertyName);
                if (dataProperty == null)
                {
                    throw c.Error.InvalidOperation(c.Strings.ClientType_MissingMimeTypeDataProperty(this.GetClientTypeAnnotation(edmStructuredType).ElementTypeName, attribute.DataPropertyName));
                }

                IEdmProperty mimeTypeProperty = edmStructuredType.Properties().SingleOrDefault(p => p.Name == attribute.MimeTypePropertyName);
                if (mimeTypeProperty == null)
                {
                    throw c.Error.InvalidOperation(c.Strings.ClientType_MissingMimeTypeProperty(this.GetClientTypeAnnotation(edmStructuredType).ElementTypeName, attribute.MimeTypePropertyName));
                }

                this.GetClientPropertyAnnotation(dataProperty).MimeTypeProperty = this.GetClientPropertyAnnotation(mimeTypeProperty);
            }
        }