/// <summary> /// If this reference is of a structured type, this will return a valid structured type reference to the type definition. Otherwise, it will return a bad structured type reference. /// </summary> /// <param name="type">Reference to the calling object.</param> /// <returns>A valid structured type reference if the definition of the reference is of a structured type. Otherwise a bad structured type reference.</returns> public static IEdmStructuredTypeReference AsStructured(this IEdmTypeReference type) { EdmUtil.CheckArgumentNull(type, "type"); IEdmStructuredTypeReference reference = type as IEdmStructuredTypeReference; if (reference != null) { return reference; } switch (type.TypeKind()) { case EdmTypeKind.Entity: return type.AsEntity(); case EdmTypeKind.Complex: return type.AsComplex(); case EdmTypeKind.Row: return type.AsRow(); } string typeFullName = type.FullName(); List<EdmError> errors = new List<EdmError>(type.TypeErrors()); if (errors.Count == 0) { errors.AddRange(ConversionError(type.Location(), typeFullName, EdmConstants.Type_Structured)); } return new BadEntityTypeReference(typeFullName, type.IsNullable, errors); }
public static IEdmStructuredTypeReference AsStructured(this IEdmTypeReference type) { string str; List<EdmError> edmErrors; EdmUtil.CheckArgumentNull<IEdmTypeReference>(type, "type"); IEdmStructuredTypeReference edmStructuredTypeReference = type as IEdmStructuredTypeReference; if (edmStructuredTypeReference == null) { EdmTypeKind edmTypeKind = type.TypeKind(); switch (edmTypeKind) { case EdmTypeKind.Entity: { return type.AsEntity(); } case EdmTypeKind.Complex: { return type.AsComplex(); } case EdmTypeKind.Row: { return type.AsRow(); } default: { str = type.FullName(); edmErrors = new List<EdmError>(type.TypeErrors()); if (edmErrors.Count != 0) { break; } edmErrors.AddRange(EdmTypeSemantics.ConversionError(type.Location(), str, "Structured")); break; } } return new BadEntityTypeReference(str, type.IsNullable, edmErrors); } else { return edmStructuredTypeReference; } }