本文整理汇总了C#中IEdmTypeReference.FullName方法的典型用法代码示例。如果您正苦于以下问题:C# IEdmTypeReference.FullName方法的具体用法?C# IEdmTypeReference.FullName怎么用?C# IEdmTypeReference.FullName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEdmTypeReference
的用法示例。
在下文中一共展示了IEdmTypeReference.FullName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetValueTypeNameForWriting
/// <summary>
/// Determines the type name to write to the payload. Json Light type names are only written into the payload for open properties
/// or if the payload type name is more derived than the model type name.
/// </summary>
/// <param name="value">The ODataValue whose type name is to be written.</param>
/// <param name="typeReferenceFromMetadata">The type as expected by the model.</param>
/// <param name="typeReferenceFromValue">The type resolved from the value.</param>
/// <param name="isOpenProperty">true if the type name belongs to an open property, false otherwise.</param>
/// <returns>Type name to write to the payload, or null if no type should be written.</returns>
internal override string GetValueTypeNameForWriting(
ODataValue value,
IEdmTypeReference typeReferenceFromMetadata,
IEdmTypeReference typeReferenceFromValue,
bool isOpenProperty)
{
SerializationTypeNameAnnotation typeNameAnnotation = value.GetAnnotation<SerializationTypeNameAnnotation>();
if (typeNameAnnotation != null)
{
return typeNameAnnotation.TypeName;
}
if (typeReferenceFromValue != null)
{
// Write type name when the type in the payload is more derived than the type from metadata.
if (typeReferenceFromMetadata != null && typeReferenceFromMetadata.Definition.AsActualType().FullTypeName() != typeReferenceFromValue.FullName())
{
return typeReferenceFromValue.FullName();
}
// Note: When writing derived complexType value in a payload, we don't have the expected type.
// So always write @odata.type for top-level derived complex type.
if (typeReferenceFromMetadata == null && typeReferenceFromValue.IsComplex())
{
if ((typeReferenceFromValue as IEdmComplexTypeReference).ComplexDefinition().BaseType != null)
{
return typeReferenceFromValue.FullName();
}
}
// Do not write type name when the type is native json type.
if (typeReferenceFromValue.IsPrimitive() && JsonSharedUtils.ValueTypeMatchesJsonType((ODataPrimitiveValue)value, typeReferenceFromValue.AsPrimitive()))
{
return null;
}
}
if (!isOpenProperty)
{
// Do not write type name for non-open properties since we expect the reader to have an expected type (via API or context URI) and thus not need it.
return null;
}
return GetTypeNameFromValue(value);
}
示例2: CreateODataValueAsync
/// <inheritdoc/>
public sealed override async Task<ODataValue> CreateODataValueAsync(object graph, IEdmTypeReference expectedType, ODataSerializerContext writeContext)
{
if (!expectedType.IsEnum())
{
throw Error.InvalidOperation(SRResources.CannotWriteType, typeof(ODataEnumSerializer).Name, expectedType.FullName());
}
ODataEnumValue value = await CreateODataEnumValueAsync(graph, expectedType.AsEnum(), writeContext);
if (value == null)
{
return new ODataNullValue();
}
return value;
}
示例3: CreateODataValue
/// <inheritdoc/>
public sealed override ODataValue CreateODataValue(object graph, IEdmTypeReference expectedType, ODataSerializerContext writeContext)
{
if (!expectedType.IsPrimitive())
{
throw Error.InvalidOperation(SRResources.CannotWriteType, typeof(ODataPrimitiveSerializer), expectedType.FullName());
}
ODataPrimitiveValue value = CreateODataPrimitiveValue(graph, expectedType.AsPrimitive(), writeContext);
if (value == null)
{
return new ODataNullValue();
}
return value;
}
示例4: NonentityRangeVariable
/// <summary>
/// Creates a <see cref="NonentityRangeVariable"/>.
/// </summary>
/// <param name="name"> The name of the associated range variable.</param>
/// <param name="typeReference">The type of the value the range variable represents.</param>
/// <param name="collectionNode">The collection that this rangeVariable node iterates over, can be null in the case of single value nodes.</param>
/// <exception cref="System.ArgumentNullException">Throws if the input name is null.</exception>
/// <exception cref="ArgumentException">Throws if the input type reference is an entity type.</exception>
public NonentityRangeVariable(string name, IEdmTypeReference typeReference, CollectionNode collectionNode)
{
ExceptionUtils.CheckArgumentNotNull(name, "name");
this.name = name;
if (typeReference != null)
{
if (typeReference.Definition.TypeKind == EdmTypeKind.Entity)
{
throw new ArgumentException(
ODataErrorStrings.Nodes_NonentityParameterQueryNodeWithEntityType(typeReference.FullName()));
}
}
this.typeReference = typeReference;
this.collectionNode = collectionNode;
}
示例5: CreateODataValue
/// <inheitdoc />
public sealed override ODataValue CreateODataValue(object graph, IEdmTypeReference expectedType,
ODataSerializerContext writeContext)
{
if (expectedType == null)
{
throw Error.ArgumentNull("expectedType");
}
if (!expectedType.IsComplex())
{
throw new SerializationException(
Error.Format(SRResources.CannotWriteType, GetType().Name, expectedType.FullName()));
}
return CreateODataComplexValue(graph, expectedType.AsComplex(), writeContext);
}
示例6: ReadWithExpectedType
/// <summary>
/// Reads a value from the message reader.
/// </summary>
/// <param name="expectedClientType">The expected client type being materialized into.</param>
/// <param name="expectedReaderType">The expected type for the underlying reader.</param>
protected override void ReadWithExpectedType(IEdmTypeReference expectedClientType, IEdmTypeReference expectedReaderType)
{
if (!expectedClientType.IsCollection())
{
throw new DataServiceClientException(DSClient.Strings.AtomMaterializer_TypeShouldBeCollectionError(expectedClientType.FullName()));
}
Type underlyingExpectedType = Nullable.GetUnderlyingType(this.ExpectedType) ?? this.ExpectedType;
bool isClrCollection = WebUtil.IsCLRTypeCollection(underlyingExpectedType, this.MaterializerContext.Model);
Debug.Assert(isClrCollection || (SingleResult.HasValue && !SingleResult.Value), "expected type must be collection or single result must be false");
// We are here for two cases:
// (1) Something like Execute<ICollection<T>>, in which case the underlyingExpectedType is ICollection<T>
// (2) Execute<T> with the bool singleValue = false, in which case underlyingExpectedType is T
Type collectionItemType = underlyingExpectedType;
Type collectionICollectionType = ClientTypeUtil.GetImplementationType(underlyingExpectedType, typeof(ICollection<>));
if (collectionICollectionType != null)
{
// Case 1 : Something like Execute<ICollection<T>>, in which case the underlyingExpectedType is ICollection<T>
collectionItemType = collectionICollectionType.GetGenericArguments()[0];
}
else
{
// Case 2 : Execute<T> with the bool singleValue = false, in which case underlyingExpectedType is T
collectionICollectionType = typeof(ICollection<>).MakeGenericType(new Type[] { collectionItemType });
}
Type clrCollectionType = WebUtil.GetBackingTypeForCollectionProperty(collectionICollectionType, collectionItemType);
object collectionInstance = this.CollectionValueMaterializationPolicy.CreateCollectionInstance((IEdmCollectionTypeReference)expectedClientType, clrCollectionType);
// Enumerator over our collection reader was created, then ApplyDataCollections was refactored to
// take an enumerable instead of a ODataCollectionValue. Enumerator is being used as a bridge
ODataCollectionReader collectionReader = messageReader.CreateODataCollectionReader();
NonEntityItemsEnumerable collectionEnumerable = new NonEntityItemsEnumerable(collectionReader);
bool isElementNullable = expectedClientType.AsCollection().ElementType().IsNullable;
this.CollectionValueMaterializationPolicy.ApplyCollectionDataValues(
collectionEnumerable,
null /*wireTypeName*/,
collectionInstance,
collectionItemType,
ClientTypeUtil.GetAddToCollectionDelegate(collectionICollectionType),
isElementNullable);
this.currentValue = collectionInstance;
}
示例7: GetEntityType
private static IEdmEntityTypeReference GetEntityType(IEdmTypeReference feedType)
{
if (feedType.IsCollection())
{
IEdmTypeReference elementType = feedType.AsCollection().ElementType();
if (elementType.IsEntity())
{
return elementType.AsEntity();
}
}
string message = string.Format(
CultureInfo.InvariantCulture,
"{0} cannot write an object of type '{1}'.",
typeof(ODataDomainFeedSerializer).Name,
feedType.FullName());
throw new SerializationException(message);
}
示例8: GetValueTypeNameForWriting
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.FullName();
}
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;
}
示例9: ConvertToStockTypeReference
private IEdmTypeReference ConvertToStockTypeReference(IEdmTypeReference edmTypeReference, EdmModel stockModel)
{
IEdmTypeReference stockTypeReference = null;
switch (edmTypeReference.Definition.TypeKind)
{
case EdmTypeKind.Entity:
var stockEntity = (IEdmEntityType)stockModel.FindType(edmTypeReference.FullName());
stockTypeReference = new EdmEntityTypeReference(stockEntity, edmTypeReference.IsNullable);
break;
case EdmTypeKind.Complex:
var stockComplex = (IEdmComplexType)stockModel.FindType(edmTypeReference.FullName());
stockTypeReference = new EdmComplexTypeReference(stockComplex, edmTypeReference.IsNullable);
break;
case EdmTypeKind.Primitive:
stockTypeReference = CreatePrimitveStockTypeReference(edmTypeReference, stockModel);
break;
case EdmTypeKind.Collection:
stockTypeReference = CreateCollectionStockTypeReference(edmTypeReference, stockModel);
break;
case EdmTypeKind.EntityReference:
stockTypeReference = CreateEntityReference(edmTypeReference, stockModel);
break;
case EdmTypeKind.Enum:
var stockEnum = (IEdmEnumType)stockModel.FindType(edmTypeReference.FullName());
stockTypeReference = new EdmEnumTypeReference(stockEnum, edmTypeReference.IsNullable);
break;
default:
throw new NotImplementedException("EdmTypeKind.None are not implemented.");
}
return stockTypeReference;
}
示例10: UpdateExpectedTypeBasedOnContextUri
/// <summary>
/// Updates the expected type based on the context URI if there is one.
/// </summary>
/// <param name="expectedPropertyTypeReference">The expected property type reference provided by the user through public APIs, or null if one was not provided.</param>
/// <returns>The expected type reference updated based on the context uri, if there is one.</returns>
private IEdmTypeReference UpdateExpectedTypeBasedOnContextUri(IEdmTypeReference expectedPropertyTypeReference)
{
Debug.Assert(!this.JsonLightInputContext.ReadingResponse || this.ContextUriParseResult != null, "Responses should always have a context uri, and that should already have been validated.");
if (this.ContextUriParseResult == null || this.ContextUriParseResult.EdmType == null)
{
return expectedPropertyTypeReference;
}
IEdmType typeFromContextUri = this.ContextUriParseResult.EdmType;
if (expectedPropertyTypeReference != null && !expectedPropertyTypeReference.Definition.IsAssignableFrom(typeFromContextUri))
{
throw new ODataException(ODataErrorStrings.ReaderValidationUtils_TypeInContextUriDoesNotMatchExpectedType(
UriUtils.UriToString(this.ContextUriParseResult.ContextUri),
typeFromContextUri.FullTypeName(),
expectedPropertyTypeReference.FullName()));
}
// Assume the value is nullable as its the looser option and the value may come from an open property.
bool isNullable = true;
if (expectedPropertyTypeReference != null)
{
// if there is a user-provided expected type, then flow nullability information from it.
isNullable = expectedPropertyTypeReference.IsNullable;
}
return typeFromContextUri.ToTypeReference(isNullable);
}
示例11: CreateODataCollectionValue
/// <summary>
/// Creates an <see cref="ODataCollectionValue"/> for the enumerable represented by <paramref name="enumerable"/>.
/// </summary>
/// <param name="enumerable">The value of the collection to be created.</param>
/// <param name="elementType">The element EDM type of the collection.</param>
/// <param name="writeContext">The serializer context to be used while creating the collection.</param>
/// <returns>The created <see cref="ODataCollectionValue"/>.</returns>
public virtual ODataCollectionValue CreateODataCollectionValue(IEnumerable enumerable, IEdmTypeReference elementType,
ODataSerializerContext writeContext)
{
if (writeContext == null)
{
throw Error.ArgumentNull("writeContext");
}
if (elementType == null)
{
throw Error.ArgumentNull("elementType");
}
ArrayList valueCollection = new ArrayList();
if (enumerable != null)
{
ODataEdmTypeSerializer itemSerializer = null;
foreach (object item in enumerable)
{
itemSerializer = itemSerializer ?? SerializerProvider.GetEdmTypeSerializer(elementType);
if (itemSerializer == null)
{
throw new SerializationException(
Error.Format(SRResources.TypeCannotBeSerialized, elementType.FullName(), typeof(ODataMediaTypeFormatter).Name));
}
// ODataCollectionWriter expects the individual elements in the collection to be the underlying values and not ODataValues.
valueCollection.Add(itemSerializer.CreateODataValue(item, elementType, writeContext).GetInnerValue());
}
}
// Ideally, we'd like to do this:
// string typeName = _edmCollectionType.FullName();
// But ODataLib currently doesn't support .FullName() for collections. As a workaround, we construct the
// collection type name the hard way.
string typeName = "Collection(" + elementType.FullName() + ")";
// ODataCollectionValue is only a V3 property, arrays inside Complex Types or Entity types are only supported in V3
// if a V1 or V2 Client requests a type that has a collection within it ODataLib will throw.
ODataCollectionValue value = new ODataCollectionValue
{
Items = valueCollection,
TypeName = typeName
};
AddTypeNameAnnotationAsNeeded(value, writeContext.MetadataLevel);
return value;
}
示例12: ReadCollectionValue
/// <summary>
/// Deserializes the given <paramref name="collectionValue"/> under the given <paramref name="readContext"/>.
/// </summary>
/// <param name="collectionValue">The <see cref="ODataCollectionValue"/> to deserialize.</param>
/// <param name="elementType">The element type of the collection to read.</param>
/// <param name="readContext">The deserializer context.</param>
/// <returns>The deserialized collection.</returns>
public virtual IEnumerable ReadCollectionValue(ODataCollectionValue collectionValue, IEdmTypeReference elementType,
ODataDeserializerContext readContext)
{
if (collectionValue == null)
{
throw Error.ArgumentNull("collectionValue");
}
if (elementType == null)
{
throw Error.ArgumentNull("elementType");
}
ODataEdmTypeDeserializer deserializer = DeserializerProvider.GetEdmTypeDeserializer(elementType);
if (deserializer == null)
{
throw new SerializationException(
Error.Format(SRResources.TypeCannotBeDeserialized, elementType.FullName(), typeof(ODataMediaTypeFormatter).Name));
}
foreach (object entry in collectionValue.Items)
{
if (elementType.IsPrimitive())
{
yield return entry;
}
else
{
yield return deserializer.ReadInline(entry, elementType, readContext);
}
}
}
示例13: ValidateNullPropertyValue
/// <summary>
/// Validates that the expected property allows null value.
/// </summary>
/// <param name="expectedPropertyTypeReference">The expected property type or null if we don't have any.</param>
/// <param name="propertyName">The name of the property.</param>
/// <param name="writerBehavior">The <see cref="ODataWriterBehavior"/> instance controlling the behavior of the writer.</param>
/// <param name="model">The model to use to get the OData version.</param>
/// <param name="bypassValidation">Bypass the validation if it is true.</param>
internal static void ValidateNullPropertyValue(IEdmTypeReference expectedPropertyTypeReference, string propertyName, ODataWriterBehavior writerBehavior, IEdmModel model, bool bypassValidation = false)
{
Debug.Assert(writerBehavior != null, "writerBehavior != null");
Debug.Assert(model != null, "For null validation, model is required.");
if (bypassValidation)
{
return;
}
if (expectedPropertyTypeReference != null)
{
if (expectedPropertyTypeReference.IsNonEntityCollectionType())
{
throw new ODataException(Strings.WriterValidationUtils_CollectionPropertiesMustNotHaveNullValue(propertyName));
}
if (expectedPropertyTypeReference.IsODataPrimitiveTypeKind())
{
// WCF DS allows null values for non-nullable primitive types, so we need to check for a knob which enables this behavior.
// See the description of ODataWriterBehavior.AllowNullValuesForNonNullablePrimitiveTypes for more details.
if (!expectedPropertyTypeReference.IsNullable && !writerBehavior.AllowNullValuesForNonNullablePrimitiveTypes)
{
throw new ODataException(Strings.WriterValidationUtils_NonNullablePropertiesMustNotHaveNullValue(propertyName, expectedPropertyTypeReference.FullName()));
}
}
else if (expectedPropertyTypeReference.IsODataEnumTypeKind() && !expectedPropertyTypeReference.IsNullable)
{
throw new ODataException(Strings.WriterValidationUtils_NonNullablePropertiesMustNotHaveNullValue(propertyName, expectedPropertyTypeReference.FullName()));
}
else if (expectedPropertyTypeReference.IsStream())
{
throw new ODataException(Strings.WriterValidationUtils_StreamPropertiesMustNotHaveNullValue(propertyName));
}
else if (expectedPropertyTypeReference.IsODataComplexTypeKind())
{
if (ValidationUtils.ShouldValidateComplexPropertyNullValue(model))
{
IEdmComplexTypeReference complexTypeReference = expectedPropertyTypeReference.AsComplex();
if (!complexTypeReference.IsNullable)
{
throw new ODataException(Strings.WriterValidationUtils_NonNullablePropertiesMustNotHaveNullValue(propertyName, expectedPropertyTypeReference.FullName()));
}
}
}
}
}
示例14: ThrowNullValueForNonNullableTypeException
/// <summary>
/// Create and throw exception that a null value was found when the expected type is non-nullable.
/// </summary>
/// <param name="expectedValueTypeReference">The expected type for this value.</param>
/// <param name="propertyName">The name of the property whose value is being read, if applicable.</param>
private static void ThrowNullValueForNonNullableTypeException(IEdmTypeReference expectedValueTypeReference, string propertyName)
{
if (string.IsNullOrEmpty(propertyName))
{
throw new ODataException(Strings.ReaderValidationUtils_NullValueForNonNullableType(expectedValueTypeReference.FullName()));
}
throw new ODataException(Strings.ReaderValidationUtils_NullNamedValueForNonNullableType(propertyName, expectedValueTypeReference.FullName()));
}
示例15: WriteDynamicTypeEntry
private void WriteDynamicTypeEntry(object graph, ODataWriter writer, IEdmTypeReference expectedType,
ODataSerializerContext writeContext)
{
var navigationProperties = new Dictionary<IEdmTypeReference, object>();
var entityType = expectedType.Definition as EdmEntityType;
var entry = new ODataEntry()
{
TypeName = expectedType.FullName(),
Properties = CreateODataPropertiesFromDynamicType(entityType, graph, navigationProperties)
};
entry.IsTransient = true;
writer.WriteStart(entry);
foreach (IEdmTypeReference type in navigationProperties.Keys)
{
var entityContext = new EntityInstanceContext(writeContext, expectedType.AsEntity(), graph);
var navigationProperty = entityType.NavigationProperties().FirstOrDefault(p => p.Type.Equals(type));
var navigationLink = CreateNavigationLink(navigationProperty, entityContext);
if (navigationLink != null)
{
writer.WriteStart(navigationLink);
WriteDynamicTypeEntry(navigationProperties[type], writer, type, writeContext);
writer.WriteEnd();
}
}
writer.WriteEnd();
}