Skip to content

Instantly share code, notes, and snippets.

@ABaker86
Created February 12, 2020 16:33
Show Gist options
  • Save ABaker86/808924205c59d3b42db6766f2a8b5140 to your computer and use it in GitHub Desktop.
Save ABaker86/808924205c59d3b42db6766f2a8b5140 to your computer and use it in GitHub Desktop.
//using the following interfaces
public interface IUseInterface<T> where T : IAmAnInterface { T ViewModel { get; set; } }
private Type GetGenericType<TInterface>(TInterface someObjectInterface) where TInterface : IAmAnInterface =>
typeof(IUseInterface<>).MakeGenericType(someObjectInterface.GetType().GetInterfaces()
.Where(x => x.Name.Contains("Template")).ToArray());
//returns Type IUseInterface<T> where T : IAmAnInterface
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment