From b3b357cd3c0c28a8a66fe0db5defd3ce9c848568 Mon Sep 17 00:00:00 2001 From: Christof Sprenger Date: Wed, 2 Dec 2020 14:20:18 -0800 Subject: [PATCH 1/3] add optional annotation location parameter to AddVocabularyAnnotation --- src/Microsoft.OData.Edm/Schema/EdmModel.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.OData.Edm/Schema/EdmModel.cs b/src/Microsoft.OData.Edm/Schema/EdmModel.cs index c0c97e5a89..c661f67130 100644 --- a/src/Microsoft.OData.Edm/Schema/EdmModel.cs +++ b/src/Microsoft.OData.Edm/Schema/EdmModel.cs @@ -119,7 +119,7 @@ public void AddElements(IEnumerable newElements) /// Adds a vocabulary annotation to this model. /// /// The annotation to be added. - public void AddVocabularyAnnotation(IEdmVocabularyAnnotation annotation) + public void AddVocabularyAnnotation(IEdmVocabularyAnnotation annotation, Csdl.EdmVocabularyAnnotationSerializationLocation location = Csdl.EdmVocabularyAnnotationSerializationLocation.OutOfLine) { EdmUtil.CheckArgumentNull(annotation, "annotation"); if (annotation.Target == null) @@ -135,6 +135,7 @@ public void AddVocabularyAnnotation(IEdmVocabularyAnnotation annotation) } elementAnnotations.Add(annotation); + Csdl.SerializationExtensionMethods.SetSerializationLocation(annotation, this, location); } /// From 6894e2abd1aaa1f075a2d70d98d61d83701d1d06 Mon Sep 17 00:00:00 2001 From: Christof Sprenger Date: Tue, 8 Dec 2020 16:39:51 -0800 Subject: [PATCH 2/3] moved code to extension method --- .../ExtensionMethods/ExtensionMethods.cs | 21 ++++++++++++------- src/Microsoft.OData.Edm/Schema/EdmModel.cs | 3 +-- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/Microsoft.OData.Edm/ExtensionMethods/ExtensionMethods.cs b/src/Microsoft.OData.Edm/ExtensionMethods/ExtensionMethods.cs index e2fde78b99..a806c57812 100644 --- a/src/Microsoft.OData.Edm/ExtensionMethods/ExtensionMethods.cs +++ b/src/Microsoft.OData.Edm/ExtensionMethods/ExtensionMethods.cs @@ -2027,13 +2027,20 @@ public static void AddAlternateKeyAnnotation(this EdmModel model, IEdmEntityType model.SetVocabularyAnnotation(annotation); } - /// - /// Checks whether the given entity type has the as one of the key properties. - /// - /// Given entity type. - /// Property to be searched for. - /// true if the type or base types has given property declared as key. false otherwise. - public static bool HasDeclaredKeyProperty(this IEdmEntityType entityType, IEdmProperty property) + public static void AddVocabularyAnnotation(this EdmModel model, IEdmVocabularyAnnotation annotation, Csdl.EdmVocabularyAnnotationSerializationLocation location) + { + model.AddVocabularyAnnotation(annotation); + annotation.SetSerializationLocation(model, location); + } + + + /// + /// Checks whether the given entity type has the as one of the key properties. + /// + /// Given entity type. + /// Property to be searched for. + /// true if the type or base types has given property declared as key. false otherwise. + public static bool HasDeclaredKeyProperty(this IEdmEntityType entityType, IEdmProperty property) { EdmUtil.CheckArgumentNull(entityType, "entityType"); EdmUtil.CheckArgumentNull(property, "property"); diff --git a/src/Microsoft.OData.Edm/Schema/EdmModel.cs b/src/Microsoft.OData.Edm/Schema/EdmModel.cs index c661f67130..c0c97e5a89 100644 --- a/src/Microsoft.OData.Edm/Schema/EdmModel.cs +++ b/src/Microsoft.OData.Edm/Schema/EdmModel.cs @@ -119,7 +119,7 @@ public void AddElements(IEnumerable newElements) /// Adds a vocabulary annotation to this model. /// /// The annotation to be added. - public void AddVocabularyAnnotation(IEdmVocabularyAnnotation annotation, Csdl.EdmVocabularyAnnotationSerializationLocation location = Csdl.EdmVocabularyAnnotationSerializationLocation.OutOfLine) + public void AddVocabularyAnnotation(IEdmVocabularyAnnotation annotation) { EdmUtil.CheckArgumentNull(annotation, "annotation"); if (annotation.Target == null) @@ -135,7 +135,6 @@ public void AddVocabularyAnnotation(IEdmVocabularyAnnotation annotation, Csdl.Ed } elementAnnotations.Add(annotation); - Csdl.SerializationExtensionMethods.SetSerializationLocation(annotation, this, location); } /// From 35f0cd7de9386b2c9813764b22dbc10dd56de62a Mon Sep 17 00:00:00 2001 From: Christof Sprenger Date: Tue, 8 Dec 2020 16:46:14 -0800 Subject: [PATCH 3/3] add code comment --- .../ExtensionMethods/ExtensionMethods.cs | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.OData.Edm/ExtensionMethods/ExtensionMethods.cs b/src/Microsoft.OData.Edm/ExtensionMethods/ExtensionMethods.cs index a806c57812..812b79ba7b 100644 --- a/src/Microsoft.OData.Edm/ExtensionMethods/ExtensionMethods.cs +++ b/src/Microsoft.OData.Edm/ExtensionMethods/ExtensionMethods.cs @@ -2027,20 +2027,25 @@ public static void AddAlternateKeyAnnotation(this EdmModel model, IEdmEntityType model.SetVocabularyAnnotation(annotation); } + /// + /// Adds a vocabulary annotation to this model. + /// + /// The model the annotation is added to. + /// The annotation to be added. + /// The location to add the allocation public static void AddVocabularyAnnotation(this EdmModel model, IEdmVocabularyAnnotation annotation, Csdl.EdmVocabularyAnnotationSerializationLocation location) { model.AddVocabularyAnnotation(annotation); annotation.SetSerializationLocation(model, location); } - - /// - /// Checks whether the given entity type has the as one of the key properties. - /// - /// Given entity type. - /// Property to be searched for. - /// true if the type or base types has given property declared as key. false otherwise. - public static bool HasDeclaredKeyProperty(this IEdmEntityType entityType, IEdmProperty property) + /// + /// Checks whether the given entity type has the as one of the key properties. + /// + /// Given entity type. + /// Property to be searched for. + /// true if the type or base types has given property declared as key. false otherwise. + public static bool HasDeclaredKeyProperty(this IEdmEntityType entityType, IEdmProperty property) { EdmUtil.CheckArgumentNull(entityType, "entityType"); EdmUtil.CheckArgumentNull(property, "property");