/// <summary> /// Start writing a collection - implementation of the actual functionality. /// </summary> /// <param name="collectionStart">The <see cref="ODataCollectionStart"/> representing the collection.</param> private void WriteStartImplementation(ODataCollectionStart collectionStart) { this.StartPayloadInStartState(); this.EnterScope(CollectionWriterState.Collection, collectionStart); this.InterceptException(() => { if (this.expectedItemType == null) { this.collectionValidator = new CollectionWithoutExpectedTypeValidator(/*expectedItemTypeName*/ null); } this.StartCollection(collectionStart); }); }
/// <summary> /// Constructor. /// </summary> /// <param name="inputContext">The input to read from.</param> /// <param name="expectedItemTypeReference">The expected type reference for the items in the collection.</param> /// <param name="listener">If not null, the reader will notify the implementer of the interface of relevant state changes in the reader.</param> protected ODataCollectionReaderCore( ODataInputContext inputContext, IEdmTypeReference expectedItemTypeReference, IODataReaderWriterListener listener) { this.inputContext = inputContext; this.expectedItemTypeReference = expectedItemTypeReference; if (this.expectedItemTypeReference == null) { // NOTE: collections cannot specify a type name for the collection itself, so always passing null. this.collectionValidator = new CollectionWithoutExpectedTypeValidator(/*expectedItemTypeName*/ null); } this.listener = listener; this.EnterScope(ODataCollectionReaderState.Start, null); }
internal string GetValueTypeNameForWriting( object value, IEdmTypeReference typeReferenceFromValue, SerializationTypeNameAnnotation typeNameAnnotation, CollectionWithoutExpectedTypeValidator collectionValidator, out string collectionItemTypeName) { Debug.Assert(value != null, "value != null"); collectionItemTypeName = null; // if no type name is specified we will use the type name inferred from metadata string typeName = GetTypeNameFromValue(value); if (typeName == null && typeReferenceFromValue != null) { typeName = typeReferenceFromValue.ODataFullName(); } if (typeName != null) { // If the type is the same as the one specified by the parent collection, omit the type name, since it's not needed. if (collectionValidator != null && string.CompareOrdinal(collectionValidator.ItemTypeNameFromCollection, typeName) == 0) { typeName = null; } // If value is a collection value, get the item type name. if (typeName != null && value is ODataCollectionValue) { collectionItemTypeName = ValidationUtils.ValidateCollectionTypeName(typeName); } } if (typeNameAnnotation != null) { // If the value of TypeName is null, we'll flow it through here, thereby instructing the caller to write no type name. typeName = typeNameAnnotation.TypeName; } return(typeName); }
internal string GetValueTypeNameForWriting( object value, IEdmTypeReference typeReferenceFromValue, SerializationTypeNameAnnotation typeNameAnnotation, CollectionWithoutExpectedTypeValidator collectionValidator, out string collectionItemTypeName) { Debug.Assert(value != null, "value != null"); collectionItemTypeName = null; // if no type name is specified we will use the type name inferred from metadata string typeName = GetTypeNameFromValue(value); if (typeName == null && typeReferenceFromValue != null) { typeName = typeReferenceFromValue.ODataFullName(); } if (typeName != null) { // If the type is the same as the one specified by the parent collection, omit the type name, since it's not needed. if (collectionValidator != null && string.CompareOrdinal(collectionValidator.ItemTypeNameFromCollection, typeName) == 0) { typeName = null; } // If value is a collection value, get the item type name. if (typeName != null && value is ODataCollectionValue) { collectionItemTypeName = ValidationUtils.ValidateCollectionTypeName(typeName); } } if (typeNameAnnotation != null) { // If the value of TypeName is null, we'll flow it through here, thereby instructing the caller to write no type name. typeName = typeNameAnnotation.TypeName; } return typeName; }