private static bool ShouldSkipType(DistinctTypeList distinctTypeList, Type type) { return(!type.IsClass || type.IsValueType || type == typeof(string) || type == typeof(object) || distinctTypeList.ContainsType(type)); }
public DistinctTypeList AddRange(DistinctTypeList typeList) { foreach (var type in typeList.GetAllTypes()) { Add(type); } return(typeList); }
/// <summary> /// check all properties of types stored in distinctTypeList /// </summary> /// <param name="distinctTypeList"></param> /// <param name="attributesToCheck"></param> /// <returns></returns> public List <AttributeCheckResult> CheckPropertiesForAttributes(DistinctTypeList distinctTypeList, Type[] attributesToCheck) { var results = new List <AttributeCheckResult>(); foreach (var type in distinctTypeList.GetAllTypes()) { results.AddRange(CheckPropertiesOfTypeForAttributes(type, attributesToCheck)); } return(results); }
private bool SearchForTypesWhenItIsAClass(Type currentType, DistinctTypeList distinctTypeList) { if (!currentType.IsClass) { return(false); } distinctTypeList.Add(currentType); GetTypesRecursivlyFromPublicProperties(currentType, distinctTypeList); return(true); }
private void SearchPropertyForUsedTypes(DistinctTypeList distinctTypeList, PropertyInfo property) { var currentType = property.PropertyType; _ = ShouldSkipType(distinctTypeList, currentType) || SearchForTypesWhenItIsAnArray(currentType, distinctTypeList) || SearchForTypesWhenItIsAGenericType(currentType, distinctTypeList) || ShouldSkipFrameworkType(currentType) || SearchForTypesWhenItIsAClass(currentType, distinctTypeList); }
private bool SearchForTypesWhenItIsAnArray(Type currentType, DistinctTypeList distinctTypeList) { if (!currentType.IsArray) { return(false); } var typeOfArry = currentType.GetElementType() !; GetTypesRecursivlyFromPublicProperties(typeOfArry, distinctTypeList); return(true); }
/// <summary> /// get a IApiDescriptionGroupCollectionProvider from your dependency injection and use it to query all used types /// </summary> /// <param name="apiDescription"></param> /// <param name="mediaTypesToCheck"></param> /// <returns></returns> public DistinctTypeList GetUsedContractTypes(IApiDescriptionGroupCollectionProvider apiDescription, string?mediaTypesToCheck = null) { var apiDescriptions = apiDescription.ApiDescriptionGroups?.Items; var usedTypes = new DistinctTypeList(); foreach (var description in apiDescriptions !) { usedTypes.AddRange(GetUsedContractTypes(description, mediaTypesToCheck)); } return(usedTypes); }
private bool SearchForTypesWhenItIsAGenericType(Type currentType, DistinctTypeList distinctTypeList) { if (!currentType.IsGenericType) { return(false); } foreach (var typeArguments in SelectGenericTypeArguments(distinctTypeList, currentType)) { GetTypesRecursivlyFromPublicProperties(typeArguments, distinctTypeList); } return(true); }
/// <summary> /// get a ApiDescriptionGroup from your dependency injection and use it to query all used types /// </summary> /// <param name="apiDescription"></param> /// <param name="mediaTypesToCheck"></param> /// <returns></returns> public DistinctTypeList GetUsedContractTypes(ApiDescriptionGroup apiDescription, string?mediaTypesToCheck = null) { var apiDescriptions = apiDescription.Items .Where(w => w is not null) ; var usedTypes = new DistinctTypeList(); foreach (var description in apiDescriptions !) { var bodyParameter = description.ParameterDescriptions.Where(IsBodyParameter); usedTypes.AddRange(bodyParameter.Select(s => s.Type)); //TODO option to check for default Asp.net classes var responseParameter = description.SupportedResponseTypes.Where(w => w.Type != null && IsCorrectMediaType(mediaTypesToCheck, w)); usedTypes.AddRange(responseParameter.Select(s => s.Type)); } return(usedTypes); }
private static IEnumerable <Type> SelectGenericTypeArguments(DistinctTypeList distinctTypeList, Type currentType) { return(currentType.GetGenericArguments().Where(w => !ShouldSkipType(distinctTypeList, w))); }
private List <AttributeCheckResult> CheckTypeAttributes(DistinctTypeList typeList, Type[] attributesToCheck, IEnumerable <Type>?typesToIgnore = null) { var filteredTypeList = typeList.GetAllTypes().Where(w => typesToIgnore == null || !typesToIgnore.Contains(w)); return(_attributeChecker.CheckPropertiesForAttributes(filteredTypeList, attributesToCheck)); }