/// <summary> /// Gets vocabulary annotation that binds to a term and a qualifier from the metadata annotation dictionary in current data service context for a specified methodInfo. /// </summary> /// <param name="context">The data service context.</param> /// <param name="methodInfo">The specified annotated methodInfo.</param> /// <param name="term">The term name.</param> /// <param name="qualifier">The qualifier name.</param> /// <returns>The vocabulary annotation that binds to a term and a qualifier for the specified annotated methodInfo.</returns> private static IEdmVocabularyAnnotation GetOrInsertCachedMetadataAnnotationForMethodInfo(DataServiceContext context, MethodInfo methodInfo, string term, string qualifier) { IEdmModel serviceModel = context.Format.ServiceModel; if (serviceModel == null) { return(null); } IEdmVocabularyAnnotation edmValueAnnotation = GetCachedMetadataAnnotation(context, methodInfo, term, qualifier); if (edmValueAnnotation != null) { return(edmValueAnnotation); } IEdmVocabularyAnnotatable edmVocabularyAnnotatable = context.GetEdmOperationOrOperationImport(methodInfo); if (edmVocabularyAnnotatable == null) { return(null); } var edmOperationImport = edmVocabularyAnnotatable as IEdmOperationImport; IEnumerable <IEdmVocabularyAnnotation> edmValueAnnotations = null; if (edmOperationImport != null) { edmValueAnnotations = serviceModel.FindVocabularyAnnotations <IEdmVocabularyAnnotation>(edmOperationImport, term, qualifier) .Where(a => a.Qualifier == qualifier); if (!edmValueAnnotations.Any()) { edmVocabularyAnnotatable = edmOperationImport.Operation; } } if (edmValueAnnotations == null || !edmValueAnnotations.Any()) { edmValueAnnotations = serviceModel.FindVocabularyAnnotations <IEdmVocabularyAnnotation>(edmVocabularyAnnotatable, term, qualifier) .Where(a => a.Qualifier == qualifier); } if (edmValueAnnotations != null && edmValueAnnotations.Count() == 1) { edmValueAnnotation = edmValueAnnotations.Single(); InsertMetadataAnnotation(context, methodInfo, edmValueAnnotation); return(edmValueAnnotation); } return(null); }