Skip to content

Add GetFriendlyName and GetFullFriendlyName extension methods on Type - #171

Merged
dennisdoomen merged 3 commits into
mainfrom
dennisdoomen-add-get-friendly-name
Aug 10, 2026
Merged

Add GetFriendlyName and GetFullFriendlyName extension methods on Type#171
dennisdoomen merged 3 commits into
mainfrom
dennisdoomen-add-get-friendly-name

Conversation

@dennisdoomen

Copy link
Copy Markdown
Owner

Closes #161

Summary

Implements the approved API proposal from #161: GetFriendlyName() and GetFullFriendlyName() extension methods on Type, rendering a type the way a C# developer would write it instead of the raw CLR name.

Behavior

  • Dictionary<string, List<int>>Dictionary<string, List<int>>
  • int?int? (nullable value types use ?)
  • int[] / int[,] for arrays, respecting rank
  • Outer.Inner for nested types (+ replaced with .)
  • List<> (open generic type definition) → List<T>, using the generic parameter's own name
  • Common CLR primitives map to their C# keyword alias: int, string, bool, double, float, decimal, long, short, byte, sbyte, uint, ulong, ushort, char, object, void
  • GetFullFriendlyName() behaves the same but uses the namespace-qualified name for the outer type and recursively for all generic type arguments, e.g. System.Collections.Generic.Dictionary<string, System.Collections.Generic.List<int>> (primitives are still rendered as C# keywords, since those have no namespace-qualified form)
  • Types where HasFriendlyName() returns false get a structural fallback:
    • Tuples (ValueTuple/Tuple, per IsTuple()) render as (int, string), using the friendly names of their element types recursively
    • Anonymous types render as { Name, Age }, using the property names in declaration order

Tests

Added GetFriendlyName and GetFullFriendlyName nested test classes to TypeMetaDataExtensionsSpecs.cs covering simple types, primitive keyword aliases, nullable value types, single/multi-dimensional arrays, nested types, generics (single/multiple/nested type arguments), open generic type definitions, tuples, anonymous types, and the full-name variants.

Validation

  • dotnet build src\Reflectify\Reflectify.csproj — succeeds for all four target frameworks (net47, net6.0, netstandard2.0, netstandard2.1)
  • dotnet test tests\Reflectify.Specs\Reflectify.Specs.csproj --framework net8.0 — 223/223 tests pass (net472 and net6.0 also pass; netcoreapp3.0 can't run locally due to a missing runtime, unrelated to this change)

Docs

Updated the "How do I use it?" section of README.md to mention the new methods.


Co-authored-by: Copilot App 223556219+Copilot@users.noreply.github.com

Renders a type the way a C# developer would write it, instead of the
raw CLR name:
- Common CLR primitives map to their C# keyword alias (int, string, etc.)
- Nullable value types render with a trailing '?'
- Arrays respect their rank (int[], int[,])
- Nested types use '.' instead of the CLR '+'
- Open generic type definitions use the generic parameter's own name
  (List<T> instead of List<>)
- GetFullFriendlyName includes the namespace-qualified name, recursively
  applied to generic type arguments
- Types without a friendly name (tuples, anonymous types) fall back to
  a structural rendering, e.g. (int, string) and { Name, Age }

Closes #161

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions

github-actions Bot commented Aug 10, 2026

Copy link
Copy Markdown

Test Results

    4 files  ±  0      4 suites  ±0   3m 52s ⏱️ +10s
  307 tests + 36    307 ✅ + 36  0 💤 ±0  0 ❌ ±0 
1 223 runs  +144  1 223 ✅ +144  0 💤 ±0  0 ❌ ±0 

Results for commit 5ff8372. ± Comparison against base commit 5bf3449.

♻️ This comment has been updated with latest results.

Dennis Doomen and others added 2 commits August 10, 2026 17:44
Resolves conflicts with #159's type classifier extension methods
(IsNullable, IsEnumerable, GetElementTypeOfEnumerable, IsDictionary,
TryGetDictionaryTypes, IsAwaitable, IsTaskLike, IsNumeric,
IsPrimitiveOrString) which landed alongside GetFriendlyName/
GetFullFriendlyName.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@dennisdoomen
dennisdoomen merged commit 479309e into main Aug 10, 2026
4 checks passed
@dennisdoomen
dennisdoomen deleted the dennisdoomen-add-get-friendly-name branch August 10, 2026 15:59
dennisdoomen pushed a commit that referenced this pull request Aug 10, 2026
@dennisdoomen dennisdoomen added the enhancement New feature or request label Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[API Proposal]: Add GetFriendlyName to render types the way C# developers write them

1 participant