/// <summary> /// Gets code for imports that are specified in TsTypeAttribute.ImportPath property /// </summary> /// <param name="type"></param> /// <returns></returns> private string GetCustomImportsText(Type type) { var result = ""; IEnumerable <MemberInfo> members = _typeService.GetTsExportableMembers(type); IEnumerable <TsTypeAttribute> typeAttributes = members .Select(memberInfo => memberInfo.GetCustomAttribute <TsTypeAttribute>()) .Where(tsTypeAttribute => !string.IsNullOrEmpty(tsTypeAttribute?.ImportPath)) .Distinct(new TsTypeAttributeComparer()); foreach (TsTypeAttribute attribute in typeAttributes) { bool withOriginalTypeName = !string.IsNullOrEmpty(attribute.OriginalTypeName); string name = withOriginalTypeName ? attribute.OriginalTypeName : attribute.FlatTypeName; string asAlias = withOriginalTypeName ? $" as {attribute.FlatTypeName}" : ""; result += _templateService.FillImportTemplate(name, asAlias, attribute.ImportPath); } return(result); }
/// <summary> /// Gets type dependencies for the members inside a given type /// </summary> /// <param name="type"></param> /// <returns></returns> private IEnumerable <TypeDependencyInfo> GetMemberTypeDependencies(Type type) { IEnumerable <TypeDependencyInfo> result = Enumerable.Empty <TypeDependencyInfo>(); IEnumerable <MemberInfo> memberInfos = _typeService.GetTsExportableMembers(type); foreach (MemberInfo memberInfo in memberInfos) { if (memberInfo.GetCustomAttribute <TsTypeAttribute>() != null) { continue; } Type memberType = _typeService.GetMemberType(memberInfo); Type memberFlatType = _typeService.GetFlatType(memberType); if (memberFlatType == type || (memberFlatType.IsConstructedGenericType && memberFlatType.GetGenericTypeDefinition() == type)) { continue; // NOT a dependency if it's the type itself } if (_typeService.IsTsSimpleType(memberFlatType) || memberFlatType.IsGenericParameter) { continue; } var memberAttributes = memberInfo.GetCustomAttributes(typeof(Attribute), false) as Attribute[]; if (memberFlatType.GetTypeInfo().IsGenericType) { result = result.Concat(GetGenericTypeNonDefinitionDependencies(memberFlatType) .Select(t => new TypeDependencyInfo(t, memberAttributes))); } else { result = result.Concat(new[] { new TypeDependencyInfo(memberFlatType, memberAttributes) }); } } return(result); }