/// <summary> /// Adds an OData annotation to a property. /// </summary> /// <param name="propertyName">The name of the property to add annotation to. string.empty means the annotation is for the current scope.</param> /// <param name="annotationName">The name of the annotation to add.</param> /// <param name="annotationValue">The valud of the annotation to add.</param> internal void AddODataPropertyAnnotation(string propertyName, string annotationName, object annotationValue) { DebugUtils.CheckNoExternalCallers(); Debug.Assert(!string.IsNullOrEmpty(propertyName), "!string.IsNullOrEmpty(propertyName)"); Debug.Assert(!string.IsNullOrEmpty(annotationName), "!string.IsNullOrEmpty(annotationName)"); Debug.Assert(JsonLight.ODataJsonLightReaderUtils.IsODataAnnotationName(annotationName), "annotationName must be an OData annotation."); DuplicationRecord duplicationRecord = this.GetDuplicationRecordToAddPropertyAnnotation(propertyName, annotationName); Dictionary <string, object> odataAnnotations = duplicationRecord.PropertyODataAnnotations; if (odataAnnotations == null) { odataAnnotations = new Dictionary <string, object>(StringComparer.Ordinal); duplicationRecord.PropertyODataAnnotations = odataAnnotations; } else if (odataAnnotations.ContainsKey(annotationName)) { if (ODataJsonLightReaderUtils.IsAnnotationProperty(propertyName)) { throw new ODataException(Strings.DuplicatePropertyNamesChecker_DuplicateAnnotationForInstanceAnnotationNotAllowed(annotationName, propertyName)); } throw new ODataException(Strings.DuplicatePropertyNamesChecker_DuplicateAnnotationForPropertyNotAllowed(annotationName, propertyName)); } odataAnnotations.Add(annotationName, annotationValue); }