Skip to content

Instantly share code, notes, and snippets.

@controlflow
Last active January 27, 2020 11:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save controlflow/b3d64eca9568b78574f3cf01cc53a8aa to your computer and use it in GitHub Desktop.
Save controlflow/b3d64eca9568b78574f3cf01cc53a8aa to your computer and use it in GitHub Desktop.
var argumentType = typeofExpression.ArgumentType;
if (!(argumentType is IDeclaredType declaredType)
|| declaredType.IsVoid()
|| declaredType is IDynamicType) return null;
var typeElement = declaredType.GetTypeElement();
if (typeElement is ITypeParameter) return null;
return typeElement?.TypeParameters.Count == 0 ? typeElement : null;
var argumentType = typeofExpression.ArgumentType as IDeclaredType;
if (argumentType == null
|| argumentType.IsVoid()
|| argumentType is IDynamicType) return null;
var typeElement = argumentType.GetTypeElement();
if (typeElement == null
|| typeElement is ITypeParameter
|| typeElement.TypeParameters.Count > 0) return null;
return typeElement; // bingo!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment