/// <summary> /// Check if this type represents an ATOM-style media link entry and /// if so mark the ClientType as such /// </summary> private void CheckMediaLinkEntry() { this.isMediaLinkEntry = false; // MediaEntryAttribute does not allow multiples, so there can be at most 1 instance on the type. MediaEntryAttribute mediaEntryAttribute = (MediaEntryAttribute)this.ElementType.GetCustomAttributes(typeof(MediaEntryAttribute), true).SingleOrDefault(); if (mediaEntryAttribute != null) { this.isMediaLinkEntry = true; ClientPropertyAnnotation mediaProperty = this.Properties().SingleOrDefault(p => p.PropertyName == mediaEntryAttribute.MediaMemberName); if (mediaProperty == null) { throw Microsoft.OData.Client.Error.InvalidOperation(Microsoft.OData.Client.Strings.ClientType_MissingMediaEntryProperty( this.ElementTypeName, mediaEntryAttribute.MediaMemberName)); } this.mediaDataMember = mediaProperty; } // HasStreamAttribute does not allow multiples, so there can be at most 1 instance on the type. bool hasStreamAttribute = this.ElementType.GetCustomAttributes(typeof(HasStreamAttribute), true).Any(); if (hasStreamAttribute) { this.isMediaLinkEntry = true; } }
private void CheckMediaLinkEntry() { Func <ClientPropertyAnnotation, bool> predicate = null; this.isMediaLinkEntry = false; MediaEntryAttribute mediaEntryAttribute = (MediaEntryAttribute)this.ElementType.GetCustomAttributes(typeof(MediaEntryAttribute), true).SingleOrDefault <object>(); if (mediaEntryAttribute != null) { this.isMediaLinkEntry = true; if (predicate == null) { predicate = p => p.PropertyName == mediaEntryAttribute.MediaMemberName; } ClientPropertyAnnotation annotation = this.Properties().SingleOrDefault <ClientPropertyAnnotation>(predicate); if (annotation == null) { throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.ClientType_MissingMediaEntryProperty(this.ElementTypeName, mediaEntryAttribute.MediaMemberName)); } this.mediaDataMember = annotation; } if (this.ElementType.GetCustomAttributes(typeof(HasStreamAttribute), true).Any <object>()) { this.isMediaLinkEntry = true; } if (this.isMediaLinkEntry.HasValue && this.isMediaLinkEntry.Value) { this.SetMediaLinkEntryAnnotation(); } }
/// <summary> /// Check based on edm base entity type and attribute on CLR type whether or not /// the to-be-created type is a media entity. /// </summary> /// <param name="edmBaseType">Base EDM Entity type</param> /// <param name="type">The CLR type to check on</param> /// <returns>HasStream value to set on the to-be-created EntityType</returns> private static bool GetHasStreamValue(IEdmEntityType edmBaseType, Type type) { // MediaEntryAttribute does not allow multiples, so there can be at most 1 instance on the type. MediaEntryAttribute mediaEntryAttribute = (MediaEntryAttribute)type.GetCustomAttributes(typeof(MediaEntryAttribute), true).SingleOrDefault(); if (mediaEntryAttribute != null) { return(true); } // HasStreamAttribute does not allow multiples, so there can be at most 1 instance on the type. bool hasStreamAttribute = type.GetCustomAttributes(typeof(HasStreamAttribute), true).Any(); return(hasStreamAttribute); }