本文整理汇总了C#中DuplicatePropertyNamesChecker类的典型用法代码示例。如果您正苦于以下问题:C# DuplicatePropertyNamesChecker类的具体用法?C# DuplicatePropertyNamesChecker怎么用?C# DuplicatePropertyNamesChecker使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DuplicatePropertyNamesChecker类属于命名空间,在下文中一共展示了DuplicatePropertyNamesChecker类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DuplicateInstanceCustomAnnotationShouldFail
public void DuplicateInstanceCustomAnnotationShouldFail()
{
DuplicatePropertyNamesChecker duplicateChecker = new DuplicatePropertyNamesChecker(false, true);
Action action = () => duplicateChecker.MarkPropertyAsProcessed("custom.name");
action.ShouldNotThrow();
action.ShouldThrow<ODataException>().WithMessage(ErrorStrings.DuplicatePropertyNamesChecker_DuplicateAnnotationNotAllowed("custom.name"));
}
示例2: OnlyCustomAnnotationsForPropertyAddedShouldReturnNull
public void OnlyCustomAnnotationsForPropertyAddedShouldReturnNull()
{
DuplicatePropertyNamesChecker duplicateChecker = new DuplicatePropertyNamesChecker(false, true);
duplicateChecker.AddCustomPropertyAnnotation("property", "custom.annotation");
duplicateChecker.AddCustomPropertyAnnotation("property", "custom.annotation2");
duplicateChecker.GetODataPropertyAnnotations("property").Should().BeNull();
}
示例3: DuplicatePropertyCustomAnnotationShouldFail
public void DuplicatePropertyCustomAnnotationShouldFail()
{
DuplicatePropertyNamesChecker duplicateChecker = new DuplicatePropertyNamesChecker(false, true);
Action action = () => duplicateChecker.AddCustomPropertyAnnotation("property", "custom.name");
action.ShouldNotThrow();
action.ShouldThrow<ODataException>().WithMessage(ErrorStrings.DuplicatePropertyNamesChecker_DuplicateAnnotationForPropertyNotAllowed("custom.name", "property"));
}
示例4: DuplicatePropertyODataAnnotationShouldFail
public void DuplicatePropertyODataAnnotationShouldFail()
{
DuplicatePropertyNamesChecker duplicateChecker = new DuplicatePropertyNamesChecker(false, true);
Action action = () => duplicateChecker.AddODataPropertyAnnotation("property", JsonLightConstants.ODataAnnotationNamespacePrefix + "name", null);
action.ShouldNotThrow();
action.ShouldThrow<ODataException>().WithMessage(ErrorStrings.DuplicatePropertyNamesChecker_DuplicateAnnotationForPropertyNotAllowed(JsonLightConstants.ODataAnnotationNamespacePrefix + "name", "property"));
}
示例5: ReadInstanceAnnotationValueWillReadNullValueWithoutODataType
public void ReadInstanceAnnotationValueWillReadNullValueWithoutODataType()
{
var deserializer = this.CreateJsonLightEntryAndFeedDeserializer("{\"@odata.NullAnnotation\":null}");
AdvanceReaderToFirstPropertyValue(deserializer.JsonReader);
var duplicatePropertyNamesChecker = new DuplicatePropertyNamesChecker(false /*allowDuplicateProperties*/, true /*isResponse*/);
deserializer.ReadCustomInstanceAnnotationValue(duplicatePropertyNamesChecker, "odata.NullAnnotation").Should().BeNull();
}
示例6: AnnotationsForPropertyShouldBeStored
public void AnnotationsForPropertyShouldBeStored()
{
DuplicatePropertyNamesChecker duplicateChecker = new DuplicatePropertyNamesChecker(false, true);
duplicateChecker.AddODataPropertyAnnotation("property", JsonLightConstants.ODataAnnotationNamespacePrefix + "one", 1);
duplicateChecker.AddODataPropertyAnnotation("property", JsonLightConstants.ODataAnnotationNamespacePrefix + "two", "Two");
duplicateChecker.GetODataPropertyAnnotations("property").Should().Equal(new Dictionary<string, object>()
{
{ JsonLightConstants.ODataAnnotationNamespacePrefix + "one", 1 },
{ JsonLightConstants.ODataAnnotationNamespacePrefix + "two", "Two" }
});
}
示例7: ReadAtStartImplementation
/// <summary>
/// Implementation of the reader logic when in state 'Start'.
/// </summary>
/// <returns>true if more items can be read from the reader; otherwise false.</returns>
/// <remarks>
/// Pre-Condition: JsonNodeType.None: assumes that the JSON reader has not been used yet.
/// Post-Condition: When the new state is Value, the reader is positioned at the closing '}' or at the name of the next parameter.
/// When the new state is Entry, the reader is positioned at the starting '{' of the entry payload.
/// When the new state is Feed or Collection, the reader is positioned at the starting '[' of the feed or collection payload.
/// </remarks>
protected override bool ReadAtStartImplementation()
{
Debug.Assert(this.State == ODataParameterReaderState.Start, "this.State == ODataParameterReaderState.Start");
Debug.Assert(this.jsonLightParameterDeserializer.JsonReader.NodeType == JsonNodeType.None, "Pre-Condition: expected JsonNodeType.None");
// We use this to store annotations and check for duplicate annotation names, but we don't really store properties in it.
this.duplicatePropertyNamesChecker = this.jsonLightInputContext.CreateDuplicatePropertyNamesChecker();
// The parameter payload looks like "{ param1 : value1, ..., paramN : valueN }", where each value can be primitive, complex, collection, entity, feed or collection.
// Position the reader on the first node
this.jsonLightParameterDeserializer.ReadPayloadStart(
ODataPayloadKind.Parameter,
this.duplicatePropertyNamesChecker,
/*isReadingNestedPayload*/false,
/*allowEmptyPayload*/true);
return this.ReadAtStartImplementationSynchronously();
}
示例8: WriteAssociationLink
/// <summary>
/// Write the metadata for an OData association link; makes sure any duplicate of the link's values duplicated in metadata are equal.
/// </summary>
/// <param name="associationLink">The association link for which to write the metadata.</param>
/// <param name="owningType">The <see cref="IEdmEntityType"/> instance the association link is defined on.</param>
/// <param name="duplicatePropertyNamesChecker">The checker instance for duplicate property names.</param>
/// <param name="projectedProperties">Set of projected properties, or null if all properties should be written.</param>
internal void WriteAssociationLink(
ODataAssociationLink associationLink,
IEdmEntityType owningType,
DuplicatePropertyNamesChecker duplicatePropertyNamesChecker,
ProjectedPropertiesAnnotation projectedProperties)
{
DebugUtils.CheckNoExternalCallers();
ValidationUtils.ValidateAssociationLinkNotNull(associationLink);
if (projectedProperties.ShouldSkipProperty(associationLink.Name))
{
return;
}
this.ValidateAssociationLink(associationLink, owningType);
duplicatePropertyNamesChecker.CheckForDuplicatePropertyNames(associationLink);
AtomLinkMetadata linkMetadata = associationLink.GetAnnotation<AtomLinkMetadata>();
string linkRelation = AtomUtils.ComputeODataAssociationLinkRelation(associationLink);
AtomLinkMetadata mergedLinkMetadata = ODataAtomWriterMetadataUtils.MergeLinkMetadata(linkMetadata, linkRelation, associationLink.Url, associationLink.Name, MimeConstants.MimeApplicationXml);
this.atomEntryMetadataSerializer.WriteAtomLink(mergedLinkMetadata, null /* etag*/);
}
示例9: WriteComplexValue
internal bool WriteComplexValue(
ODataComplexValue complexValue,
IEdmTypeReference metadataTypeReference,
bool isOpenPropertyType,
bool isWritingCollection,
Action beforeValueAction,
Action afterValueAction,
DuplicatePropertyNamesChecker duplicatePropertyNamesChecker,
CollectionWithoutExpectedTypeValidator collectionValidator,
ProjectedPropertiesAnnotation projectedProperties)
{
Debug.Assert(complexValue != null, "complexValue != null");
string typeName = complexValue.TypeName;
if (collectionValidator != null)
{
collectionValidator.ValidateCollectionItem(typeName, EdmTypeKind.Complex);
}
this.IncreaseRecursionDepth();
// resolve the type name to the type; if no type name is specified we will use the
// type inferred from metadata
IEdmComplexTypeReference complexTypeReference = TypeNameOracle.ResolveAndValidateTypeForComplexValue(this.Model, metadataTypeReference, complexValue, isOpenPropertyType, this.WriterValidator).AsComplexOrNull();
string collectionItemTypeName;
typeName = this.AtomOutputContext.TypeNameOracle.GetValueTypeNameForWriting(complexValue, complexTypeReference, complexValue.GetAnnotation<SerializationTypeNameAnnotation>(), collectionValidator, out collectionItemTypeName);
Debug.Assert(collectionItemTypeName == null, "collectionItemTypeName == null");
Action beforeValueCallbackWithTypeName = beforeValueAction;
if (typeName != null)
{
// The beforeValueAction (if specified) will write the actual property element start.
// So if we are to write the type attribute, we must postpone that after the start element was written.
// And so we chain the existing action with our type attribute writing and use that
// as the before action instead.
if (beforeValueAction != null)
{
beforeValueCallbackWithTypeName = () =>
{
beforeValueAction();
this.WritePropertyTypeAttribute(typeName);
};
}
else
{
this.WritePropertyTypeAttribute(typeName);
}
}
bool propertyWritten = this.WriteProperties(
complexTypeReference == null ? null : complexTypeReference.ComplexDefinition(),
complexValue.Properties,
isWritingCollection,
beforeValueCallbackWithTypeName,
afterValueAction,
duplicatePropertyNamesChecker,
projectedProperties);
this.DecreaseRecursionDepth();
return propertyWritten;
}
示例10: ReadNextLinkAnnotationAtFeedEnd
/// <summary>
/// Reads any next link annotation immediately after the end of a feed.
/// </summary>
/// <param name="feed">The feed being read.</param>
/// <param name="expandedNavigationLinkInfo">The information about the expanded link. This must be non-null if we're reading an expanded feed, and must be null if we're reading a top-level feed.</param>
/// <param name="duplicatePropertyNamesChecker">The top-level duplicate property names checker, if we're reading a top-level feed.</param>
internal void ReadNextLinkAnnotationAtFeedEnd(
ODataFeedBase feed,
ODataJsonLightReaderNavigationLinkInfo expandedNavigationLinkInfo,
DuplicatePropertyNamesChecker duplicatePropertyNamesChecker)
{
Debug.Assert(feed != null, "feed != null");
// Check for annotations on the feed that occur after the feed itself. (Note: the only allowed one is odata.nextLink, and we fail for anything else.)
// We do this slightly differently depending on whether the feed was an expanded navigation or a top-level feed.
if (expandedNavigationLinkInfo != null)
{
this.ReadExpandedFeedAnnotationsAtFeedEnd(feed, expandedNavigationLinkInfo);
}
else
{
Debug.Assert(duplicatePropertyNamesChecker != null, "duplicatePropertyNamesChecker != null");
// Check for feed instance annotations that appear after the feed.
bool isReordering = this.JsonReader is ReorderingJsonReader;
this.ReadTopLevelFeedAnnotations(feed, duplicatePropertyNamesChecker, /*forFeedStart*/false, /*readAllFeedProperties*/isReordering);
}
}
示例11: ReadEntryInstanceAnnotation
/// <summary>
/// Reads instance annotation in the entry object.
/// </summary>
/// <param name="annotationName">The name of the instance annotation found.</param>
/// <param name="anyPropertyFound">true if a non-annotation property has already been encountered.</param>
/// <param name="typeAnnotationFound">true if the 'odata.type' annotation has already been encountered, or should have been by now.</param>
/// <param name="duplicatePropertyNamesChecker">The duplicate property names checker for the entry being read.</param>
/// <returns>The value of the annotation.</returns>
/// <remarks>
/// Pre-Condition: JsonNodeType.PrimitiveValue The value of the instance annotation property
/// JsonNodeType.StartObject
/// JsonNodeType.StartArray
/// Post-Condition: JsonNodeType.EndObject The end of the entry object
/// JsonNodeType.Property The next property after the instance annotation
/// </remarks>
internal object ReadEntryInstanceAnnotation(string annotationName, bool anyPropertyFound, bool typeAnnotationFound, DuplicatePropertyNamesChecker duplicatePropertyNamesChecker)
{
Debug.Assert(!string.IsNullOrEmpty(annotationName), "!string.IsNullOrEmpty(annotationName)");
this.AssertJsonCondition(JsonNodeType.PrimitiveValue, JsonNodeType.StartObject, JsonNodeType.StartArray);
switch (annotationName)
{
case ODataAnnotationNames.ODataType: // 'odata.type'
if (!typeAnnotationFound)
{
return this.ReadODataTypeAnnotationValue();
}
// We already read the odata.type if it was the first property in ReadEntryStart, so any other occurrence means
// that it was not the first property.
throw new ODataException(ODataErrorStrings.ODataJsonLightEntryAndFeedDeserializer_EntryTypeAnnotationNotFirst);
case ODataAnnotationNames.ODataId: // 'odata.id'
if (anyPropertyFound)
{
throw new ODataException(ODataErrorStrings.ODataJsonLightEntryAndFeedDeserializer_EntryInstanceAnnotationPrecededByProperty(annotationName));
}
return this.ReadAnnotationStringValueAsUri(annotationName);
case ODataAnnotationNames.ODataETag: // 'odata.etag'
if (anyPropertyFound)
{
throw new ODataException(ODataErrorStrings.ODataJsonLightEntryAndFeedDeserializer_EntryInstanceAnnotationPrecededByProperty(annotationName));
}
return this.ReadAndValidateAnnotationStringValue(annotationName);
case ODataAnnotationNames.ODataEditLink: // 'odata.editLink'
case ODataAnnotationNames.ODataReadLink: // 'odata.readLink'
case ODataAnnotationNames.ODataMediaEditLink: // 'odata.mediaEditLink'
case ODataAnnotationNames.ODataMediaReadLink: // 'odata.mediaReadLink'
return this.ReadAndValidateAnnotationStringValueAsUri(annotationName);
case ODataAnnotationNames.ODataMediaContentType: // 'odata.mediaContentType'
case ODataAnnotationNames.ODataMediaETag: // 'odata.mediaEtag'
return this.ReadAndValidateAnnotationStringValue(annotationName);
default:
ODataAnnotationNames.ValidateIsCustomAnnotationName(annotationName);
Debug.Assert(
!this.MessageReaderSettings.ShouldSkipAnnotation(annotationName),
"!this.MessageReaderSettings.ShouldReadAndValidateAnnotation(annotationName) -- otherwise we should have already skipped the custom annotation and won't see it here.");
return this.ReadCustomInstanceAnnotationValue(duplicatePropertyNamesChecker, annotationName);
}
}
示例12: ODataAtomCollectionDeserializer
/// <summary>
/// Constructor.
/// </summary>
/// <param name="atomInputContext">The ATOM input context to read from.</param>
internal ODataAtomCollectionDeserializer(ODataAtomInputContext atomInputContext)
: base(atomInputContext)
{
this.duplicatePropertyNamesChecker = this.CreateDuplicatePropertyNamesChecker();
}
示例13: WriteComplexValue
public void WriteComplexValue(
ODataComplexValue complexValue,
IEdmTypeReference metadataTypeReference,
bool isTopLevel,
bool isOpenPropertyType,
DuplicatePropertyNamesChecker duplicatePropertyNamesChecker)
{
Debug.Assert(complexValue != null, "complexValue != null");
this.IncreaseRecursionDepth();
// Start the object scope which will represent the entire complex instance;
// for top-level complex properties we already wrote the object scope (and the context URI when needed).
if (!isTopLevel)
{
this.JsonWriter.StartObjectScope();
}
string typeName = complexValue.TypeName;
if (isTopLevel)
{
Debug.Assert(metadataTypeReference == null, "Never expect a metadata type for top-level properties.");
if (typeName == null)
{
throw new ODataException(ODataErrorStrings.ODataJsonLightValueSerializer_MissingTypeNameOnComplex);
}
}
else
{
// In requests, we allow the property type reference to be null if the type name is specified in the OM
if (metadataTypeReference == null && !this.WritingResponse && typeName == null && this.Model.IsUserModel())
{
throw new ODataException(ODataErrorStrings.ODataJsonLightPropertyAndValueSerializer_NoExpectedTypeOrTypeNameSpecifiedForComplexValueRequest);
}
}
// Resolve the type name to the type; if no type name is specified we will use the
// type inferred from metadata.
IEdmComplexTypeReference complexValueTypeReference = (IEdmComplexTypeReference)TypeNameOracle.ResolveAndValidateTypeNameForValue(this.Model, metadataTypeReference, complexValue, isOpenPropertyType);
Debug.Assert(
metadataTypeReference == null || complexValueTypeReference == null || EdmLibraryExtensions.IsAssignableFrom(metadataTypeReference, complexValueTypeReference),
"Complex property types must be the same as or inherit from the ones from metadata (unless open).");
typeName = this.JsonLightOutputContext.TypeNameOracle.GetValueTypeNameForWriting(complexValue, metadataTypeReference, complexValueTypeReference, isOpenPropertyType);
if (typeName != null)
{
this.ODataAnnotationWriter.WriteODataTypeInstanceAnnotation(typeName);
}
// Write custom instance annotations
this.InstanceAnnotationWriter.WriteInstanceAnnotations(complexValue.InstanceAnnotations);
// Write the properties of the complex value as usual. Note we do not allow complex types to contain named stream properties.
this.PropertySerializer.WriteProperties(
complexValueTypeReference == null ? null : complexValueTypeReference.ComplexDefinition(),
complexValue.Properties,
true /* isComplexValue */,
duplicatePropertyNamesChecker,
null /*projectedProperties */);
// End the object scope which represents the complex instance;
// for top-level complex properties we already wrote the end object scope.
if (!isTopLevel)
{
this.JsonWriter.EndObjectScope();
}
this.DecreaseRecursionDepth();
}
示例14: WriteProperties
/// <summary>
/// Writes property names and value pairs.
/// </summary>
/// <param name="owningType">The <see cref="IEdmStructuredType"/> of the entry (or null if not metadata is available).</param>
/// <param name="properties">The enumeration of properties to write out.</param>
/// <param name="isComplexValue">
/// Whether the properties are being written for complex value. Also used for detecting whether stream properties
/// are allowed as named stream properties should only be defined on ODataEntry instances
/// </param>
/// <param name="duplicatePropertyNamesChecker">The checker instance for duplicate property names.</param>
/// <param name="projectedProperties">Set of projected properties, or null if all properties should be written.</param>
internal void WriteProperties(
IEdmStructuredType owningType,
IEnumerable<ODataProperty> properties,
bool isComplexValue,
DuplicatePropertyNamesChecker duplicatePropertyNamesChecker,
ProjectedPropertiesAnnotation projectedProperties)
{
if (properties == null)
{
return;
}
foreach (ODataProperty property in properties)
{
this.WriteProperty(
property,
owningType,
false /* isTopLevel */,
!isComplexValue,
duplicatePropertyNamesChecker,
projectedProperties);
}
}
示例15: ReadComplexValue
/// <summary>
/// Read a complex value from the reader.
/// </summary>
/// <param name="complexTypeReference">The type reference of the value to read (or null if no type is available).</param>
/// <param name="payloadTypeName">The name of the type specified in the payload.</param>
/// <param name="serializationTypeNameAnnotation">The serialization type name for the complex value (possibly null).</param>
/// <param name="duplicatePropertyNamesChecker">The duplicate property names checker to use (cached), or null if new one should be created.</param>
/// <returns>The value read from the payload.</returns>
/// <remarks>
/// Pre-Condition: XmlNodeType.Element - the element to read the value for.
/// XmlNodeType.Attribute - an attribute on the element to read the value for.
/// Post-Condition: XmlNodeType.EndElement - the element has been read.
///
/// Note that this method will not read null values, those should be handled by the caller already.
/// </remarks>
private ODataComplexValue ReadComplexValue(
IEdmComplexTypeReference complexTypeReference,
string payloadTypeName,
SerializationTypeNameAnnotation serializationTypeNameAnnotation,
DuplicatePropertyNamesChecker duplicatePropertyNamesChecker)
{
this.AssertXmlCondition(XmlNodeType.Element, XmlNodeType.Attribute);
this.IncreaseRecursionDepth();
ODataComplexValue complexValue = new ODataComplexValue();
IEdmComplexType complexType = complexTypeReference == null ? null : (IEdmComplexType)complexTypeReference.Definition;
// If we have a metadata type for the complex value, use that type name
// otherwise use the type name from the payload (if there was any).
complexValue.TypeName = complexType == null ? payloadTypeName : complexType.ODataFullName();
if (serializationTypeNameAnnotation != null)
{
complexValue.SetAnnotation(serializationTypeNameAnnotation);
}
// Move to the element (so that if we were on an attribute we can test the element for being empty)
this.XmlReader.MoveToElement();
if (duplicatePropertyNamesChecker == null)
{
duplicatePropertyNamesChecker = this.CreateDuplicatePropertyNamesChecker();
}
else
{
duplicatePropertyNamesChecker.Clear();
}
ReadOnlyEnumerable<ODataProperty> properties = new ReadOnlyEnumerable<ODataProperty>();
this.ReadPropertiesImplementation(complexType, properties, duplicatePropertyNamesChecker);
complexValue.Properties = properties;
this.AssertXmlCondition(true, XmlNodeType.EndElement);
Debug.Assert(complexValue != null, "The method should never return null since it doesn't handle null values.");
this.DecreaseRecursionDepth();
return complexValue;
}