internal static void WriteFriendlyName( this TranslationBuffer buffer, Type type, TranslationSettings settings) { if (type.FullName == null) { // An open generic parameter Type: return; } if (type.IsArray) { buffer.WriteFriendlyName(type.GetElementType(), settings); buffer.WriteToTranslation("[]"); return; } if (!type.IsGenericType()) { var substitutedTypeName = type.GetSubstitutionOrNull(); if (type.IsNested) { buffer.WriteFriendlyName(type.DeclaringType, settings); buffer.WriteToTranslation('.'); buffer.WriteToTranslation(substitutedTypeName ?? type.Name); return; } if (substitutedTypeName != null) { buffer.WriteToTranslation(substitutedTypeName); return; } buffer.WriteTypeNamespaceIfRequired(type, settings); buffer.WriteToTranslation(type.Name); return; } Type underlyingNullableType; if ((underlyingNullableType = Nullable.GetUnderlyingType(type)) == null) { buffer.WriteGenericTypeName(type, settings); return; } buffer.WriteFriendlyName(underlyingNullableType, settings); buffer.WriteToTranslation('?'); }
private static void WriteGenericTypeName( this TranslationBuffer buffer, Type genericType, TranslationSettings settings) { var typeGenericTypeArguments = genericType.GetGenericTypeArguments(); if (!genericType.IsNested) { buffer.WriteTypeNamespaceIfRequired(genericType, settings); buffer.WriteClosedGenericTypeName(genericType, ref typeGenericTypeArguments, settings); return; } var types = new List <Type> { genericType }; // ReSharper disable once PossibleNullReferenceException while (genericType.IsNested) { genericType = genericType.DeclaringType; types.Add(genericType); } buffer.WriteTypeNamespaceIfRequired(genericType, settings); for (var i = types.Count; ;) { buffer.WriteClosedGenericTypeName(types[--i], ref typeGenericTypeArguments, settings); if (i == 0) { return; } buffer.WriteToTranslation('.'); } }