本文整理汇总了C#中DuplicatePropertyNamesChecker.CheckForDuplicatePropertyNames方法的典型用法代码示例。如果您正苦于以下问题:C# DuplicatePropertyNamesChecker.CheckForDuplicatePropertyNames方法的具体用法?C# DuplicatePropertyNamesChecker.CheckForDuplicatePropertyNames怎么用?C# DuplicatePropertyNamesChecker.CheckForDuplicatePropertyNames使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DuplicatePropertyNamesChecker
的用法示例。
在下文中一共展示了DuplicatePropertyNamesChecker.CheckForDuplicatePropertyNames方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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*/);
}
示例2: WriteStreamProperty
/// <summary>
/// Writes a stream property to the ATOM payload
/// </summary>
/// <param name="streamProperty">The stream property to create the payload for.</param>
/// <param name="owningType">The <see cref="IEdmEntityType"/> instance for which the stream property 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 WriteStreamProperty(
ODataProperty streamProperty,
IEdmEntityType owningType,
DuplicatePropertyNamesChecker duplicatePropertyNamesChecker,
ProjectedPropertiesAnnotation projectedProperties)
{
DebugUtils.CheckNoExternalCallers();
Debug.Assert(streamProperty != null, "Stream property must not be null.");
Debug.Assert(streamProperty.Value != null, "The media resource of the stream property must not be null.");
WriterValidationUtils.ValidatePropertyNotNull(streamProperty);
string propertyName = streamProperty.Name;
if (projectedProperties.ShouldSkipProperty(propertyName))
{
return;
}
WriterValidationUtils.ValidateProperty(streamProperty);
duplicatePropertyNamesChecker.CheckForDuplicatePropertyNames(streamProperty);
IEdmProperty edmProperty = WriterValidationUtils.ValidatePropertyDefined(streamProperty.Name, owningType);
WriterValidationUtils.ValidateStreamReferenceProperty(streamProperty, edmProperty, this.Version, this.WritingResponse);
ODataStreamReferenceValue streamReferenceValue = (ODataStreamReferenceValue)streamProperty.Value;
if (owningType != null && owningType.IsOpen && edmProperty == null)
{
ValidationUtils.ValidateOpenPropertyValue(streamProperty.Name, streamReferenceValue);
}
AtomStreamReferenceMetadata streamReferenceMetadata = streamReferenceValue.GetAnnotation<AtomStreamReferenceMetadata>();
string contentType = streamReferenceValue.ContentType;
string linkTitle = streamProperty.Name;
Uri readLink = streamReferenceValue.ReadLink;
if (readLink != null)
{
string readLinkRelation = AtomUtils.ComputeStreamPropertyRelation(streamProperty, false);
AtomLinkMetadata readLinkMetadata = streamReferenceMetadata == null ? null : streamReferenceMetadata.SelfLink;
AtomLinkMetadata mergedMetadata = ODataAtomWriterMetadataUtils.MergeLinkMetadata(readLinkMetadata, readLinkRelation, readLink, linkTitle, contentType);
this.atomEntryMetadataSerializer.WriteAtomLink(mergedMetadata, null /* etag */);
}
Uri editLink = streamReferenceValue.EditLink;
if (editLink != null)
{
string editLinkRelation = AtomUtils.ComputeStreamPropertyRelation(streamProperty, true);
AtomLinkMetadata editLinkMetadata = streamReferenceMetadata == null ? null : streamReferenceMetadata.EditLink;
AtomLinkMetadata mergedMetadata = ODataAtomWriterMetadataUtils.MergeLinkMetadata(editLinkMetadata, editLinkRelation, editLink, linkTitle, contentType);
this.atomEntryMetadataSerializer.WriteAtomLink(mergedMetadata, streamReferenceValue.ETag);
}
}
示例3: WriteProperty
/// <summary>
/// Writes a single property in ATOM format.
/// </summary>
/// <param name="property">The property to write out.</param>
/// <param name="owningType">The owning type for the <paramref name="property"/> or null if no metadata is available.</param>
/// <param name="isTopLevel">true if writing a top-level property payload; otherwise false.</param>
/// <param name="isWritingCollection">true if we are writing a top-level collection instead of an entry.</param>
/// <param name="beforePropertyAction">Action which is called before the property is written, if it's going to be written.</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>
/// <returns>true if the property was actually written, false otherwise.</returns>
private bool WriteProperty(
ODataProperty property,
IEdmStructuredType owningType,
bool isTopLevel,
bool isWritingCollection,
Action beforePropertyAction,
DuplicatePropertyNamesChecker duplicatePropertyNamesChecker,
ProjectedPropertiesAnnotation projectedProperties)
{
WriterValidationUtils.ValidatePropertyNotNull(property);
object value = property.Value;
string propertyName = property.Name;
//// TODO: If we implement type conversions the value needs to be converted here
//// since the next method call needs to know if the value is a string or not in some cases.
ODataComplexValue complexValue = value as ODataComplexValue;
ProjectedPropertiesAnnotation complexValueProjectedProperties = null;
if (!ShouldWritePropertyInContent(projectedProperties, propertyName))
{
return false;
}
WriterValidationUtils.ValidatePropertyName(propertyName);
duplicatePropertyNamesChecker.CheckForDuplicatePropertyNames(property);
IEdmProperty edmProperty = WriterValidationUtils.ValidatePropertyDefined(propertyName, owningType);
IEdmTypeReference propertyTypeReference = edmProperty == null ? null : edmProperty.Type;
if (value is ODataStreamReferenceValue)
{
throw new ODataException(ODataErrorStrings.ODataWriter_StreamPropertiesMustBePropertiesOfODataEntry(propertyName));
}
// Null property value.
if (value == null)
{
this.WriteNullPropertyValue(propertyTypeReference, propertyName, isTopLevel, isWritingCollection, beforePropertyAction);
return true;
}
bool isOpenPropertyType = owningType != null && owningType.IsOpen && propertyTypeReference == null;
if (isOpenPropertyType)
{
ValidationUtils.ValidateOpenPropertyValue(propertyName, value);
}
if (complexValue != null)
{
return this.WriteComplexValueProperty(
complexValue,
propertyName,
isTopLevel,
isWritingCollection,
beforePropertyAction,
propertyTypeReference,
isOpenPropertyType,
complexValueProjectedProperties);
}
ODataCollectionValue collectionValue = value as ODataCollectionValue;
if (collectionValue != null)
{
this.WriteCollectionValueProperty(
collectionValue,
propertyName,
isTopLevel,
isWritingCollection,
beforePropertyAction,
propertyTypeReference,
isOpenPropertyType);
return true;
}
// If the value isn't one of the value types tested for already, it must be a non-null primitive or enum type.
this.WritePropertyStart(beforePropertyAction, property, isWritingCollection, isTopLevel);
SerializationTypeNameAnnotation serializationTypeNameAnnotation = property.ODataValue.GetAnnotation<SerializationTypeNameAnnotation>();
ODataEnumValue enumValue = value as ODataEnumValue;
if (enumValue != null)
{
this.WriteEnumValue(enumValue, /*collectionValidator*/ null, propertyTypeReference, serializationTypeNameAnnotation);
}
else
{
this.WritePrimitiveValue(value, /*collectionValidator*/ null, propertyTypeReference, serializationTypeNameAnnotation);
}
this.WritePropertyEnd();
return true;
//.........这里部分代码省略.........
示例4: WriteProperty
private void WriteProperty(
ODataProperty property,
IEdmStructuredType owningType,
bool isTopLevel,
bool allowStreamProperty,
DuplicatePropertyNamesChecker duplicatePropertyNamesChecker,
ProjectedPropertiesAnnotation projectedProperties)
{
WriterValidationUtils.ValidatePropertyNotNull(property);
string propertyName = property.Name;
if (projectedProperties.ShouldSkipProperty(propertyName))
{
return;
}
WriterValidationUtils.ValidatePropertyName(propertyName, bypassValidation);
duplicatePropertyNamesChecker.CheckForDuplicatePropertyNames(property);
if (property.InstanceAnnotations.Any())
{
if (isTopLevel)
{
this.InstanceAnnotationWriter.WriteInstanceAnnotations(property.InstanceAnnotations);
}
else
{
this.InstanceAnnotationWriter.WriteInstanceAnnotations(property.InstanceAnnotations, propertyName);
}
}
IEdmProperty edmProperty = WriterValidationUtils.ValidatePropertyDefined(
propertyName,
owningType,
!this.bypassValidation);
IEdmTypeReference propertyTypeReference = edmProperty == null ? null : edmProperty.Type;
ODataValue value = property.ODataValue;
ODataStreamReferenceValue streamReferenceValue = value as ODataStreamReferenceValue;
if (streamReferenceValue != null)
{
if (!allowStreamProperty)
{
throw new ODataException(ODataErrorStrings.ODataWriter_StreamPropertiesMustBePropertiesOfODataEntry(propertyName));
}
Debug.Assert(owningType == null || owningType.IsODataEntityTypeKind(), "The metadata should not allow named stream properties to be defined on a non-entity type.");
Debug.Assert(!isTopLevel, "Stream properties are not allowed at the top level.");
WriterValidationUtils.ValidateStreamReferenceProperty(property, edmProperty, this.WritingResponse, this.bypassValidation);
this.WriteStreamReferenceProperty(propertyName, streamReferenceValue);
return;
}
string wirePropertyName = isTopLevel ? JsonLightConstants.ODataValuePropertyName : propertyName;
if (value is ODataNullValue || value == null)
{
WriterValidationUtils.ValidateNullPropertyValue(propertyTypeReference, propertyName, this.MessageWriterSettings.WriterBehavior, this.Model, this.bypassValidation);
if (isTopLevel)
{
// Write the special null marker for top-level null properties.
this.ODataAnnotationWriter.WriteInstanceAnnotationName(ODataAnnotationNames.ODataNull);
this.JsonWriter.WriteValue(true);
}
else
{
this.JsonWriter.WriteName(wirePropertyName);
this.JsonLightValueSerializer.WriteNullValue();
}
return;
}
bool isOpenPropertyType = this.IsOpenProperty(property, owningType, edmProperty);
if (isOpenPropertyType && this.JsonLightOutputContext.MessageWriterSettings.EnableFullValidation)
{
ValidationUtils.ValidateOpenPropertyValue(propertyName, value);
}
ODataComplexValue complexValue = value as ODataComplexValue;
if (complexValue != null)
{
if (!isTopLevel)
{
this.JsonWriter.WriteName(wirePropertyName);
}
this.JsonLightValueSerializer.WriteComplexValue(complexValue, propertyTypeReference, isTopLevel, isOpenPropertyType, this.CreateDuplicatePropertyNamesChecker());
return;
}
IEdmTypeReference typeFromValue = TypeNameOracle.ResolveAndValidateTypeNameForValue(this.Model, propertyTypeReference, value, isOpenPropertyType);
ODataEnumValue enumValue = value as ODataEnumValue;
if (enumValue != null)
{
// This is a work around, needTypeOnWire always = true for client side:
// ClientEdmModel's reflection can't know a property is open type even if it is, so here
// make client side always write 'odata.type' for enum.
//.........这里部分代码省略.........
示例5: ReadPropertiesImplementation
/// <summary>
/// Reads the content of a properties in an element (complex value, m:properties, ...)
/// </summary>
/// <param name="structuredType">The type which should declare the properties to be read. Optional.</param>
/// <param name="properties">The list of properties to add properties to.</param>
/// <param name="duplicatePropertyNamesChecker">The duplicate property names checker to use.</param>
/// <remarks>
/// Pre-Condition: XmlNodeType.Element - The element to read properties from.
/// Post-Condition: XmlNodeType.Element - The element to read properties from if it is an empty element.
/// XmlNodeType.EndElement - The end element of the element to read properties from.
/// </remarks>
private void ReadPropertiesImplementation(IEdmStructuredType structuredType, ReadOnlyEnumerable<ODataProperty> properties, DuplicatePropertyNamesChecker duplicatePropertyNamesChecker)
{
Debug.Assert(properties != null, "properties != null");
Debug.Assert(duplicatePropertyNamesChecker != null, "duplicatePropertyNamesChecker != null");
this.AssertXmlCondition(XmlNodeType.Element);
// Empty values are valid - they have no properties
if (!this.XmlReader.IsEmptyElement)
{
// Read over the complex value element to its first child node (or end-element)
this.XmlReader.ReadStartElement();
// WCF DS will skip over the rest of the complex value or entity properties if the first element in it is preceded with
// a text node. Once the first element is found (no matter its namespace) then the non-element nodes
// are ignored but skipped and the reading continues.
// For ODataLib we should not do this and probably just ignore the text node even at the beginning (to be consistent).
do
{
switch (this.XmlReader.NodeType)
{
case XmlNodeType.Element:
if (this.XmlReader.NamespaceEquals(this.XmlReader.ODataNamespace))
{
// Found a property
IEdmProperty edmProperty = null;
bool isOpen = false;
bool ignoreProperty = false;
if (structuredType != null)
{
// Lookup the property in metadata
edmProperty = ReaderValidationUtils.ValidateValuePropertyDefined(this.XmlReader.LocalName, structuredType, this.MessageReaderSettings, out ignoreProperty);
if (edmProperty != null && edmProperty.PropertyKind == EdmPropertyKind.Navigation)
{
throw new ODataException(ODataErrorStrings.ODataAtomPropertyAndValueDeserializer_NavigationPropertyInProperties(edmProperty.Name, structuredType));
}
// If the property was not declared, it must be open.
isOpen = edmProperty == null;
}
if (ignoreProperty)
{
this.XmlReader.Skip();
}
else
{
// EdmLib bridge marks all key properties as non-nullable, but Astoria allows them to be nullable.
// If the property has an annotation to ignore null values, we need to omit the property in requests.
ODataNullValueBehaviorKind nullValueReadBehaviorKind = this.ReadingResponse || edmProperty == null
? ODataNullValueBehaviorKind.Default
: this.Model.NullValueReadBehaviorKind(edmProperty);
ODataProperty property = this.ReadProperty(
false,
edmProperty == null ? null : edmProperty.Name,
edmProperty == null ? null : edmProperty.Type,
nullValueReadBehaviorKind);
Debug.Assert(
property != null || nullValueReadBehaviorKind == ODataNullValueBehaviorKind.IgnoreValue,
"If we don't ignore null values the property must not be null.");
if (property != null)
{
if (isOpen)
{
ValidationUtils.ValidateOpenPropertyValue(property.Name, property.Value);
}
duplicatePropertyNamesChecker.CheckForDuplicatePropertyNames(property);
properties.AddToSourceList(property);
}
}
}
else
{
this.XmlReader.Skip();
}
break;
case XmlNodeType.EndElement:
// End of the complex value.
break;
default:
// Non-element so for example a text node, just ignore
this.XmlReader.Skip();
break;
}
//.........这里部分代码省略.........
示例6: ReadComplexValue
//.........这里部分代码省略.........
if (string.CompareOrdinal(ODataAnnotationNames.ODataType, propertyName) == 0)
{
throw new ODataException(ODataErrorStrings.ODataJsonLightPropertyAndValueDeserializer_ComplexTypeAnnotationNotFirst);
}
else
{
throw new ODataException(ODataErrorStrings.ODataJsonLightPropertyAndValueDeserializer_UnexpectedAnnotationProperties(propertyName));
}
case PropertyParsingResult.CustomInstanceAnnotation:
ODataAnnotationNames.ValidateIsCustomAnnotationName(propertyName);
Debug.Assert(
!this.MessageReaderSettings.ShouldSkipAnnotation(propertyName),
"!this.MessageReaderSettings.ShouldReadAndValidateAnnotation(annotationName) -- otherwise we should have already skipped the custom annotation and won't see it here.");
var customInstanceAnnotationValue = this.ReadCustomInstanceAnnotationValue(duplicatePropertyNamesChecker, propertyName);
complexValue.InstanceAnnotations.Add(new ODataInstanceAnnotation(propertyName, customInstanceAnnotationValue.ToODataValue()));
break;
case PropertyParsingResult.PropertyWithoutValue:
throw new ODataException(ODataErrorStrings.ODataJsonLightPropertyAndValueDeserializer_ComplexValuePropertyAnnotationWithoutProperty(propertyName));
case PropertyParsingResult.PropertyWithValue:
// Any other property is data
ODataProperty property = new ODataProperty();
property.Name = propertyName;
// Lookup the property in metadata
IEdmProperty edmProperty = null;
bool ignoreProperty = false;
if (complexValueTypeReference != null)
{
edmProperty = ReaderValidationUtils.ValidateValuePropertyDefined(propertyName, complexValueTypeReference.ComplexDefinition(), this.MessageReaderSettings, out ignoreProperty);
}
if (ignoreProperty
&& (this.JsonReader.NodeType == JsonNodeType.StartObject || this.JsonReader.NodeType == JsonNodeType.StartArray))
{
this.JsonReader.SkipValue();
}
else
{
// EdmLib bridge marks all key properties as non-nullable, but Astoria allows them to be nullable.
// If the property has an annotation to ignore null values, we need to omit the property in requests.
ODataNullValueBehaviorKind nullValueReadBehaviorKind = this.ReadingResponse || edmProperty == null
? ODataNullValueBehaviorKind.Default
: this.Model.NullValueReadBehaviorKind(edmProperty);
// Read the property value
object propertyValue = this.ReadNonEntityValueImplementation(
ValidateDataPropertyTypeNameAnnotation(duplicatePropertyNamesChecker, propertyName),
edmProperty == null ? null : edmProperty.Type,
/*duplicatePropertyNamesChecker*/ null,
/*collectionValidator*/ null,
nullValueReadBehaviorKind == ODataNullValueBehaviorKind.Default,
/*isTopLevelPropertyValue*/ false,
/*insideComplexValue*/ false,
propertyName,
edmProperty == null);
if (nullValueReadBehaviorKind != ODataNullValueBehaviorKind.IgnoreValue || propertyValue != null)
{
duplicatePropertyNamesChecker.CheckForDuplicatePropertyNames(property);
property.Value = propertyValue;
var propertyAnnotations = duplicatePropertyNamesChecker.GetCustomPropertyAnnotations(propertyName);
if (propertyAnnotations != null)
{
foreach (var annotation in propertyAnnotations)
{
if (annotation.Value != null)
{
// annotation.Value == null indicates that this annotation should be skipped.
property.InstanceAnnotations.Add(new ODataInstanceAnnotation(annotation.Key, annotation.Value.ToODataValue()));
}
}
}
properties.Add(property);
}
}
break;
case PropertyParsingResult.EndOfObject:
break;
case PropertyParsingResult.MetadataReferenceProperty:
throw new ODataException(ODataErrorStrings.ODataJsonLightPropertyAndValueDeserializer_UnexpectedMetadataReferenceProperty(propertyName));
}
});
}
Debug.Assert(this.JsonReader.NodeType == JsonNodeType.EndObject, "After all the properties of a complex value are read the EndObject node is expected.");
this.JsonReader.ReadEndObject();
complexValue.Properties = new ReadOnlyEnumerable<ODataProperty>(properties);
this.DecreaseRecursionDepth();
return complexValue;
}
示例7: WriteProperty
private void WriteProperty(
ODataProperty property,
IEdmStructuredType owningType,
bool isTopLevel,
bool allowStreamProperty,
DuplicatePropertyNamesChecker duplicatePropertyNamesChecker,
ProjectedPropertiesAnnotation projectedProperties)
{
this.WriterValidator.ValidatePropertyNotNull(property);
string propertyName = property.Name;
if (projectedProperties.ShouldSkipProperty(propertyName))
{
return;
}
this.WriterValidator.ValidatePropertyName(propertyName);
duplicatePropertyNamesChecker.CheckForDuplicatePropertyNames(property);
WriteInstanceAnnotation(property, isTopLevel);
bool throwOnMissingProperty = this.JsonLightOutputContext.MessageWriterSettings.EnableFullValidation && !this.WritingResponse;
IEdmProperty edmProperty = this.WriterValidator.ValidatePropertyDefined(
propertyName,
owningType,
throwOnMissingProperty);
IEdmTypeReference propertyTypeReference = edmProperty == null ? null : edmProperty.Type;
ODataValue value = property.ODataValue;
ODataStreamReferenceValue streamReferenceValue = value as ODataStreamReferenceValue;
if (streamReferenceValue != null)
{
if (!allowStreamProperty)
{
throw new ODataException(ODataErrorStrings.ODataWriter_StreamPropertiesMustBePropertiesOfODataEntry(propertyName));
}
Debug.Assert(owningType == null || owningType.IsODataEntityTypeKind(), "The metadata should not allow named stream properties to be defined on a non-entity type.");
Debug.Assert(!isTopLevel, "Stream properties are not allowed at the top level.");
this.WriterValidator.ValidateStreamReferenceProperty(property, edmProperty, this.WritingResponse);
this.WriteStreamReferenceProperty(propertyName, streamReferenceValue);
return;
}
if (value is ODataNullValue || value == null)
{
this.WriteNullProperty(property, propertyTypeReference, isTopLevel);
return;
}
bool isOpenPropertyType = this.IsOpenProperty(property, owningType, edmProperty);
ODataPrimitiveValue primitiveValue = value as ODataPrimitiveValue;
if (primitiveValue != null)
{
this.WritePrimitiveProperty(property, primitiveValue, propertyTypeReference, isTopLevel, isOpenPropertyType);
return;
}
ODataComplexValue complexValue = value as ODataComplexValue;
if (complexValue != null)
{
this.WriteComplexProperty(property, complexValue, propertyTypeReference, isTopLevel, isOpenPropertyType);
return;
}
ODataEnumValue enumValue = value as ODataEnumValue;
if (enumValue != null)
{
this.WriteEnumProperty(property, enumValue, propertyTypeReference, isTopLevel, isOpenPropertyType);
return;
}
ODataCollectionValue collectionValue = value as ODataCollectionValue;
if (collectionValue != null)
{
this.WriteCollectionProperty(property, collectionValue, propertyTypeReference, isTopLevel, isOpenPropertyType);
return;
}
else
{
ODataUntypedValue untypedValue = value as ODataUntypedValue;
this.WriteUntypedProperty(property, untypedValue, isTopLevel);
return;
}
}