Skip to content

Instantly share code, notes, and snippets.

@controlflow
Created February 14, 2019 21:32
Show Gist options
  • Select an option

  • Save controlflow/f01b163a67e092dc7daa2b65cc115d41 to your computer and use it in GitHub Desktop.

Select an option

Save controlflow/f01b163a67e092dc7daa2b65cc115d41 to your computer and use it in GitHub Desktop.
[Pure, ContractAnnotation("null => false")]
public static bool IsValueTuple([CanBeNull] this ITypeElement typeElement)
{
var structType = typeElement as IStruct;
if (structType == null) return false;
return typeElement.ShortName == "ValueTuple"
&& typeElement.GetContainingNamespace() is INamespace ns
&& ns.ShortName == "System"
&& ns.GetContainingNamespace() is INamespace root
&& root.IsRootNamespace;
}
[Pure, ContractAnnotation("null => false")]
public static bool IsValueTuple([CanBeNull] this ITypeElement typeElement)
{
return typeElement is IStruct { ShortName: "ValueTuple" }
&& typeElement.GetContainingNamespace() is { ShortName: "System" } ns
&& ns.GetContainingNamespace() is { IsRootNamespace: true };
}
[Pure, ContractAnnotation("null => false")]
public static bool IsValueTuple([CanBeNull] this ITypeElement typeElement)
{
return typeElement is IStruct {
ShortName: "ValueTuple",
ContainingNamespace: {
ShortName: "System",
ContainingNamespace: { IsRootNamespace: true }
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment