/// <summary> /// Attempts multiple casts on Data.Edm.IEdmType to reach derived classes and extract full name. /// Implementation taken (copy-pasted and primitiveType case commented) from OData V4 ExtensionMethods. /// </summary> /// <param name="type">OData V3 type to extract name of</param> /// <returns>Full name of V3 type</returns> public static string GetFullTypeName(this Data.Edm.IEdmType type) { // Taken from OData v4 EdmConstants (internal) const string CollectionTypeFormat = "Collection({0})"; var namedDefinition = type as Data.Edm.IEdmSchemaElement; var collectionType = type as Data.Edm.IEdmCollectionType; if (collectionType == null) { return(namedDefinition?.GetFullName()); } // Handle collection case. namedDefinition = collectionType.ElementType.Definition as Data.Edm.IEdmSchemaElement; return(namedDefinition != null?string.Format(CultureInfo.InvariantCulture, CollectionTypeFormat, GetFullName(namedDefinition)) : null); }
/// <summary> /// Finds a V4 type definition by the name of a V3 type definition /// </summary> /// <param name="model">V4 model to search</param> /// <param name="t">V3 type</param> /// <returns>Equivalent V4 Type or null if not found</returns> public static IEdmType GetV4Definition(this IEdmModel model, Data.Edm.IEdmType t) { return(t == null ? null : model.FindType(t.GetFullTypeName())); }