<commit_before>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Microsoft.AspNet.SignalR;
using SignalrTypescriptGenerator.Models;

namespace SignalrTypescriptGenerator
{
	internal class TypeHelper
	{
		private readonly HashSet<Type> _doneTypes;
		public readonly Stack<Type> InterfaceTypes;
		public readonly Stack<Type> EnumTypes;

		public TypeHelper()
		{
			_doneTypes = new HashSet<Type>();
			InterfaceTypes = new Stack<Type>();
			EnumTypes = new Stack<Type>();
		}

		public List<FunctionDetails> GetClientFunctions(Type hubType)
		{
			var list = new List<FunctionDetails>();

			Type clientType = ClientType(hubType);
			if (clientType != null)
			{
				foreach (var method in clientType.GetMethods())
				{
					var functionDetails = new FunctionDetails();
					IEnumerable<string> ps = method.GetParameters().Select(x => x.Name + " : " + GetTypeContractName(x.ParameterType));
					string functionName = FirstCharLowered(method.Name);
					string functionArgs = "(" + string.Join(", ", ps) + ")";

					functionDetails.Name = functionName;
					functionDetails.Arguments = functionArgs;

					list.Add(functionDetails);
				}
			}

			return list;
		}

		public string FirstCharLowered(string s)
		{
			return Regex.Replace(s, "^.", x => x.Value.ToLowerInvariant());
		}

		public Type ClientType(Type hubType)
		{
			while (hubType != null && hubType != typeof(Hub))
			{
				if (hubType.IsGenericType && hubType.GetGenericTypeDefinition() == typeof(Hub<>))
				{
					return hubType.GetGenericArguments().Single();
				}
				hubType = hubType.BaseType;
			}
			return null;
		}

		public string GetTypeContractName(Type type)
		{
			if (type == typeof(Task))
			{
				return "void";
			}

			if (type.IsArray)
			{
				return GetTypeContractName(type.GetElementType()) + "[]";
			}

			if (type.IsGenericType)
			{
				if (typeof(Task<>).IsAssignableFrom(type.GetGenericTypeDefinition()))
				{
					return GetTypeContractName(type.GetGenericArguments()[0]);
				}

				if (typeof(Nullable<>).IsAssignableFrom(type.GetGenericTypeDefinition()))
				{
					return GetTypeContractName(type.GetGenericArguments()[0]);
				}

				if (typeof(List<>).IsAssignableFrom(type.GetGenericTypeDefinition()))
				{
					return GetTypeContractName(type.GetGenericArguments()[0]) + "[]";
				}
			}

			switch (type.Name.ToLowerInvariant())
			{

				case "datetime":
					return "Date";
				case "int16":
				case "int32":
				case "int64":
				case "single":
				case "double":
					return "number";
				case "boolean":
					return "boolean";
				case "void":
				case "string":
					return type.Name.ToLowerInvariant();
			}

			if (!_doneTypes.Contains(type))
			{
				_doneTypes.Add(type);
				if (type.IsEnum)
				{
					EnumTypes.Push(type);
				}
				else
				{
					InterfaceTypes.Push(type);
				}
			}
			return GenericSpecificName(type, true);
		}

		public string GenericSpecificName(Type type, bool referencing)
		{
			string name = (referencing ? type.FullName : type.Name).Split('`').First();
			if (type.IsGenericType)
			{
				name += "_" + string.Join("_", type.GenericTypeArguments.Select(a => GenericSpecificName(a, false))) + "_";
			}
			return name;
		}
	}
}<commit_msg>Improvement: Use IEnumerable<T> instead of List<T> when mapping to TypeScript arrays.<commit_after>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Microsoft.AspNet.SignalR;
using SignalrTypescriptGenerator.Models;

namespace SignalrTypescriptGenerator
{
	internal class TypeHelper
	{
		private readonly HashSet<Type> _doneTypes;
		public readonly Stack<Type> InterfaceTypes;
		public readonly Stack<Type> EnumTypes;

		public TypeHelper()
		{
			_doneTypes = new HashSet<Type>();
			InterfaceTypes = new Stack<Type>();
			EnumTypes = new Stack<Type>();
		}

		public List<FunctionDetails> GetClientFunctions(Type hubType)
		{
			var list = new List<FunctionDetails>();

			Type clientType = ClientType(hubType);
			if (clientType != null)
			{
				foreach (var method in clientType.GetMethods())
				{
					var functionDetails = new FunctionDetails();
					IEnumerable<string> ps = method.GetParameters().Select(x => x.Name + " : " + GetTypeContractName(x.ParameterType));
					string functionName = FirstCharLowered(method.Name);
					string functionArgs = "(" + string.Join(", ", ps) + ")";

					functionDetails.Name = functionName;
					functionDetails.Arguments = functionArgs;

					list.Add(functionDetails);
				}
			}

			return list;
		}

		public string FirstCharLowered(string s)
		{
			return Regex.Replace(s, "^.", x => x.Value.ToLowerInvariant());
		}

		public Type ClientType(Type hubType)
		{
			while (hubType != null && hubType != typeof(Hub))
			{
				if (hubType.IsGenericType && hubType.GetGenericTypeDefinition() == typeof(Hub<>))
				{
					return hubType.GetGenericArguments().Single();
				}
				hubType = hubType.BaseType;
			}
			return null;
		}

		public string GetTypeContractName(Type type)
		{
			if (type == typeof(Task))
			{
				return "void";
			}

			if (type.IsArray)
			{
				return GetTypeContractName(type.GetElementType()) + "[]";
			}

			if (type.IsGenericType)
			{
				if (typeof(Task<>).IsAssignableFrom(type.GetGenericTypeDefinition()))
				{
					return GetTypeContractName(type.GetGenericArguments()[0]);
				}

				if (typeof(Nullable<>).IsAssignableFrom(type.GetGenericTypeDefinition()))
				{
					return GetTypeContractName(type.GetGenericArguments()[0]);
				}

				if (typeof(IEnumerable<>).IsAssignableFrom(type.GetGenericTypeDefinition()))
				{
					return GetTypeContractName(type.GetGenericArguments()[0]) + "[]";
				}
			}

			switch (type.Name.ToLowerInvariant())
			{

				case "datetime":
					return "Date";
				case "int16":
				case "int32":
				case "int64":
				case "single":
				case "double":
					return "number";
				case "boolean":
					return "boolean";
				case "void":
				case "string":
					return type.Name.ToLowerInvariant();
			}

			if (!_doneTypes.Contains(type))
			{
				_doneTypes.Add(type);
				if (type.IsEnum)
				{
					EnumTypes.Push(type);
				}
				else
				{
					InterfaceTypes.Push(type);
				}
			}
			return GenericSpecificName(type, true);
		}

		public string GenericSpecificName(Type type, bool referencing)
		{
			string name = (referencing ? type.FullName : type.Name).Split('`').First();
			if (type.IsGenericType)
			{
				name += "_" + string.Join("_", type.GenericTypeArguments.Select(a => GenericSpecificName(a, false))) + "_";
			}
			return name;
		}
	}
}
{'fraction_non_alphanumeric': 0.12909747292418772, 'fraction_numerical': 0.00259927797833935, 'mean_word_length': 2.9263038548752833, 'pattern_counts': {'":': 18, '<': 31, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1551691', 'n_tokens_mistral': 2697, 'n_tokens_neox': 2077, 'n_words': 404}