本文整理汇总了C#中DuplicatePropertyNamesChecker.MarkPropertyAsProcessed方法的典型用法代码示例。如果您正苦于以下问题:C# DuplicatePropertyNamesChecker.MarkPropertyAsProcessed方法的具体用法?C# DuplicatePropertyNamesChecker.MarkPropertyAsProcessed怎么用?C# DuplicatePropertyNamesChecker.MarkPropertyAsProcessed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DuplicatePropertyNamesChecker
的用法示例。
在下文中一共展示了DuplicatePropertyNamesChecker.MarkPropertyAsProcessed方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: ReadingComplexProperty
/// <summary>
/// Detects whether we are currently reading a complex property or not. This can be determined from metadata (if we have it)
/// or from the presence of the odata.type instance annotation in the payload.
/// </summary>
/// <param name="duplicatePropertyNamesChecker">The duplicate property names checker in use for the entry content.</param>
/// <param name="expectedPropertyTypeReference">The expected type reference of the property to read.</param>
/// <param name="payloadTypeName">The type name of the complex value if found in the payload; otherwise null.</param>
/// <returns>true if we are reading a complex property; otherwise false.</returns>
/// <remarks>
/// This method does not move the reader.
/// </remarks>
private bool ReadingComplexProperty(DuplicatePropertyNamesChecker duplicatePropertyNamesChecker, IEdmTypeReference expectedPropertyTypeReference, out string payloadTypeName)
{
payloadTypeName = null;
bool readingComplexProperty = false;
// First try to use the metadata if is available
if (expectedPropertyTypeReference != null)
{
readingComplexProperty = expectedPropertyTypeReference.IsComplex();
}
// Then check whether the first property in the JSON object is the 'odata.type'
// annotation; if we don't have an expected property type reference, the 'odata.type'
// annotation has to exist for complex properties. (This can happen for top-level open
// properties).
if (this.JsonReader.NodeType == JsonNodeType.Property && this.TryReadODataTypeAnnotation(out payloadTypeName))
{
// Register the odata.type annotation we just found with the duplicate property names checker.
duplicatePropertyNamesChecker.MarkPropertyAsProcessed(ODataAnnotationNames.ODataType);
IEdmType expectedPropertyType = null;
if (expectedPropertyTypeReference != null)
{
expectedPropertyType = expectedPropertyTypeReference.Definition;
}
EdmTypeKind typeKind = EdmTypeKind.None;
IEdmType actualWirePropertyTypeReference = MetadataUtils.ResolveTypeNameForRead(
this.Model,
expectedPropertyType,
payloadTypeName,
this.MessageReaderSettings.ReaderBehavior,
out typeKind);
if (actualWirePropertyTypeReference != null)
{
readingComplexProperty = actualWirePropertyTypeReference.IsODataComplexTypeKind();
}
}
return readingComplexProperty;
}
示例3: TryReadPayloadTypeFromObject
/// <summary>
/// Reads the payload type name from a JSON object (if it exists).
/// </summary>
/// <param name="duplicatePropertyNamesChecker">The duplicate property names checker to track the detected 'odata.type' annotation (if any).</param>
/// <param name="insideComplexValue">true if we are reading a complex value and the reader is already positioned inside the complex value; otherwise false.</param>
/// <param name="payloadTypeName">The value of the odata.type annotation or null if no such annotation exists.</param>
/// <returns>true if a type name was read from the payload; otherwise false.</returns>
/// <remarks>
/// Precondition: StartObject the start of a JSON object
/// Postcondition: Property the first property of the object if no 'odata.type' annotation exists as first property
/// or the first property after the 'odata.type' annotation.
/// EndObject for an empty JSON object or an object with only the 'odata.type' annotation
/// </remarks>
private bool TryReadPayloadTypeFromObject(DuplicatePropertyNamesChecker duplicatePropertyNamesChecker, bool insideComplexValue, out string payloadTypeName)
{
Debug.Assert(duplicatePropertyNamesChecker != null, "duplicatePropertyNamesChecker != null");
Debug.Assert(
(this.JsonReader.NodeType == JsonNodeType.StartObject && !insideComplexValue) ||
((this.JsonReader.NodeType == JsonNodeType.Property || this.JsonReader.NodeType == JsonNodeType.EndObject) && insideComplexValue),
"Pre-Condition: JsonNodeType.StartObject when not inside complex value; JsonNodeType.Property or JsonNodeType.EndObject otherwise.");
bool readTypeName = false;
payloadTypeName = null;
// If not already positioned inside the JSON object, read over the object start
if (!insideComplexValue)
{
this.JsonReader.ReadStartObject();
}
if (this.JsonReader.NodeType == JsonNodeType.Property)
{
readTypeName = this.TryReadODataTypeAnnotation(out payloadTypeName);
if (readTypeName)
{
// Register the odata.type annotation we just found with the duplicate property names checker.
duplicatePropertyNamesChecker.MarkPropertyAsProcessed(ODataAnnotationNames.ODataType);
}
}
this.AssertJsonCondition(JsonNodeType.Property, JsonNodeType.EndObject);
return readTypeName;
}
示例4: MarkPropertyAsProcessedWithNoPropertyShouldWork
public void MarkPropertyAsProcessedWithNoPropertyShouldWork()
{
DuplicatePropertyNamesChecker duplicateChecker = new DuplicatePropertyNamesChecker(false, true);
duplicateChecker.MarkPropertyAsProcessed("property");
Action odataAction = () => duplicateChecker.AddODataPropertyAnnotation("property", JsonLightConstants.ODataAnnotationNamespacePrefix + "name", null);
odataAction.ShouldThrow<ODataException>().WithMessage(ErrorStrings.DuplicatePropertyNamesChecker_PropertyAnnotationAfterTheProperty(JsonLightConstants.ODataAnnotationNamespacePrefix + "name", "property"));
Action customAction = () => duplicateChecker.AddCustomPropertyAnnotation("property", "custom.name");
customAction.ShouldThrow<ODataException>().WithMessage(ErrorStrings.DuplicatePropertyNamesChecker_PropertyAnnotationAfterTheProperty("custom.name", "property"));
}