Skip to content

Commit

Permalink
Make Create Slider<x> call generic method Create
Browse files Browse the repository at this point in the history
  • Loading branch information
tznind committed Jan 1, 2024
1 parent 74bf7ec commit cf17192
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/ViewFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,14 @@ static void SetDefaultDimensions( T v, int width = 5, int height = 1 )
[Obsolete( "Migrate to using generic Create<T> method" )]
public static View Create( Type requestedType )
{
if (requestedType.IsGenericType)
{
var method = typeof(ViewFactory).GetMethods().Single(m=>m.Name=="Create" && m.IsGenericMethodDefinition);
method = method.MakeGenericMethod(requestedType) ?? throw new Exception("Could not find Create<T> method on ViewFactory");

return (View)(method.Invoke(null, new object?[] { null, null, null }) ?? throw new Exception("ViewFactory.Create resulted in null"));
}

return requestedType switch
{
null => throw new ArgumentNullException( nameof( requestedType ) ),
Expand Down

0 comments on commit cf17192

Please sign in to comment.