public TryGetApiScalarTypeWithApiTypeUnitTest(string name, IApiSchema apiSchema, string apiType, IApiScalarType expectedApiScalarType) : base(name) { this.ApiSchema = apiSchema; this.ApiType = apiType; this.ExpectedApiScalarType = expectedApiScalarType; }
/// <summary>Try and get the API named type by CLR type.</summary> /// <typeparam name="TEnumeration">CLR type to lookup the API named type by.</typeparam> /// <param name="apiNamedType">The API named type if it exists in the API schema, null otherwise.</param> /// <returns>True if API named type exists in the API schema, false otherwise.</returns> public static bool TryGetApiNamedType <TEnumeration>(this IApiSchema apiSchema, out IApiNamedType apiNamedType) { Contract.Requires(apiSchema != null); var clrType = typeof(TEnumeration); return(apiSchema.TryGetApiNamedType(clrType, out apiNamedType)); }
/// <summary>Get the API named type by CLR type object.</summary> /// <typeparam name="T">CLR type to lookup the API named type by.</typeparam> /// <returns>The API named type in the API schema, otherwise an exception is thrown.</returns> /// <exception cref="ApiSchemaException"></exception> public static IApiNamedType GetApiNamedType <T>(this IApiSchema apiSchema) { Contract.Requires(apiSchema != null); var clrType = typeof(T); return(apiSchema.GetApiNamedType(clrType)); }
/// <summary>Try and get the API scalar type by CLR type.</summary> /// <typeparam name="TScalar">CLR type to lookup the API scalar type by.</typeparam> /// <param name="apiScalarType">The API scalar type if it exists in the API schema, null otherwise.</param> /// <returns>True if API scalar type exists in the API schema, false otherwise.</returns> public static bool TryGetApiScalarType <TScalar>(this IApiSchema apiSchema, out IApiScalarType apiScalarType) { Contract.Requires(apiSchema != null); var clrType = typeof(TScalar); return(apiSchema.TryGetApiScalarType(clrType, out apiScalarType)); }
/// <summary>Try and get the API resource type by CLR type object.</summary> /// <typeparam name="TResource">CLR resource type object to lookup the API resource type by.</typeparam> /// <param name="apiResourceType">The API resource type if it exists in the API schema, null otherwise.</param> /// <returns>True if API resource type exists in the API schema, false otherwise.</returns> /// <remarks>If the CLR type exists but is an API complex object, then this method returns false.</remarks> public static bool TryGetApiResourceType <TResource>(this IApiSchema apiSchema, out IApiObjectType apiResourceType) { Contract.Requires(apiSchema != null); var clrResourceType = typeof(TResource); return(apiSchema.TryGetApiResourceType(clrResourceType, out apiResourceType)); }
/// <summary>Get the API resource type by CLR resource type object.</summary> /// <typeparam name="TResource">CLR resource type object to lookup the API resource type by.</typeparam> /// <returns>The API resource type in the API schema, otherwise an exception is thrown.</returns> /// <exception cref="ApiSchemaException"></exception> public static IApiObjectType GetApiResourceType <TResource>(this IApiSchema apiSchema) { Contract.Requires(apiSchema != null); var clrResourceType = typeof(TResource); return(apiSchema.GetApiResourceType(clrResourceType)); }
/// <summary>Get the API object type by CLR type object.</summary> /// <typeparam name="TObject">CLR type to lookup the API object type by.</typeparam> /// <returns>The API object type in the API schema, otherwise an exception is thrown.</returns> /// <exception cref="ApiSchemaException"></exception> public static IApiObjectType GetApiObjectType <TObject>(this IApiSchema apiSchema) { Contract.Requires(apiSchema != null); var clrType = typeof(TObject); return(apiSchema.GetApiObjectType(clrType)); }
/// <summary>Get the API enumeration type by CLR type object.</summary> /// <typeparam name="TEnumeration">CLR type to lookup the API enumeration type by.</typeparam> /// <returns>The API enumeration type in the API schema, otherwise an exception is thrown.</returns> /// <exception cref="ApiSchemaException"></exception> public static IApiEnumerationType GetApiEnumerationType <TEnumeration>(this IApiSchema apiSchema) { Contract.Requires(apiSchema != null); var clrType = typeof(TEnumeration); return(apiSchema.GetApiEnumerationType(clrType)); }
/// <summary>Get the API enumeration type by API type name.</summary> /// <param name="apiName">API type name to lookup the API enumeration type by.</param> /// <returns>The API enumeration type in the API schema, otherwise an exception is thrown.</returns> /// <exception cref="ApiSchemaException"></exception> public static IApiEnumerationType GetApiEnumerationType(this IApiSchema apiSchema, string apiName) { Contract.Requires(apiSchema != null); Contract.Requires(apiName.SafeHasContent()); if (apiSchema.TryGetApiEnumerationType(apiName, out var apiEnumerationType)) { return(apiEnumerationType); } // Unable to get API enumeration type by the given API name. var message = $"Unable to get API enumeration type [apiName={apiName}] in the API schema, API enumeration type was not configured."; throw new ApiSchemaException(message); }
/// <summary>Get the API named type by CLR type object.</summary> /// <param name="clrType">CLR type object to lookup the API named type by.</param> /// <returns>The API named type in the API schema, otherwise an exception is thrown.</returns> /// <exception cref="ApiSchemaException"></exception> public static IApiNamedType GetApiNamedType(this IApiSchema apiSchema, Type clrType) { Contract.Requires(apiSchema != null); Contract.Requires(clrType != null); if (apiSchema.TryGetApiNamedType(clrType, out var apiNamedType)) { return(apiNamedType); } // Unable to get API named type by the given CLR type. var message = $"Unable to get API named type [clrType={clrType.Name}] in the API schema, API named type was not configured."; throw new ApiSchemaException(message); }
/// <summary>Try and get the API resource type by CLR type object.</summary> /// <param name="clrResourceType">CLR resource type object to lookup the API resource type by.</param> /// <param name="apiResourceType">The API resource type if it exists in the API schema, null otherwise.</param> /// <returns>True if API resource type exists in the API schema, false otherwise.</returns> /// <remarks>If the CLR type exists but is an API complex object, then this method returns false.</remarks> public static bool TryGetApiResourceType(this IApiSchema apiSchema, Type clrResourceType, out IApiObjectType apiResourceType) { Contract.Requires(apiSchema != null); Contract.Requires(clrResourceType != null); apiResourceType = null; if (!apiSchema.TryGetApiObjectType(clrResourceType, out var apiObjectType)) { return(false); } var apiObjectTypeKind = apiObjectType.GetApiObjectTypeKind(); if (apiObjectTypeKind != ApiObjectTypeKind.ResourceType) { return(false); } apiResourceType = apiObjectType; return(true); }
/// <summary>Try and get the API resource type by API type name.</summary> /// <param name="apiName">API type name to lookup the API resource type by.</param> /// <param name="apiResourceType">The API resource type if it exists in the API schema, null otherwise.</param> /// <returns>True if API resource type exists in the API schema, false otherwise.</returns> public static bool TryGetApiResourceType(this IApiSchema apiSchema, string apiName, out IApiObjectType apiResourceType) { Contract.Requires(apiSchema != null); Contract.Requires(apiName.SafeHasContent()); apiResourceType = null; if (!apiSchema.TryGetApiObjectType(apiName, out var apiObjectType)) { return(false); } var apiObjectTypeKind = apiObjectType.GetApiObjectTypeKind(); if (apiObjectTypeKind != ApiObjectTypeKind.ResourceType) { return(false); } apiResourceType = apiObjectType; return(true); }
public void VisitApiSchema(IApiSchema apiSchema) { var description = apiSchema.ToString(); this.AddDescriptionToString(description); // ApiEnumerationTypes foreach (var apiEnumerationType in apiSchema.ApiEnumerationTypes.Cast <ApiEnumerationType>()) { apiEnumerationType.Accept(this, 1); } // ApiObjectTypes foreach (var apiObjectType in apiSchema.ApiObjectTypes.Cast <ApiObjectType>()) { apiObjectType.Accept(this, 1); } // ApiScalarTypes foreach (var apiScalarType in apiSchema.ApiScalarTypes.Cast <ApiScalarType>()) { apiScalarType.Accept(this, 1); } }
public TryGetApiObjectTypeWithClrTypeUnitTest(string name, IApiSchema apiSchema, IApiObjectType expectedApiObjectType) : base(name) { this.ApiSchema = apiSchema; this.ExpectedApiObjectType = expectedApiObjectType; }
// INTERNAL METHODS ///////////////////////////////////////////////// #region Methods internal void Initialize(IApiSchema subject) { Contract.Requires(subject != null); this.Subject = subject; }