public static TName GetName <TName>([NotNull] this IDeclaredElement element, [NotNull] ISubstitution substitution)
            where TName : class, IName
        {
            var seen      = new Dictionary <DeclaredElementInstance, IName>();
            var name      = element.GetName(substitution, seen);
            var typedName = name as TName;

            if (typedName != null)
            {
                return(typedName);
            }

            // TODO NameUpdate: should be removable now... is handled in TypeShapeAnalysis now.
            // in case of unresolved types in using directives...
            // maybe this will be replaced when I have a better understanding of how aliases are handled in the R# AST
            if (typeof(AliasName) == name.GetType() && typeof(TName) == typeof(ITypeName))
            {
                return((TName)Names.UnknownType);
            }

            throw new InvalidCastException(
                      "Cannot cast {0}({1}) to {2}.".FormatEx(name.GetType().Name, name.Identifier, typeof(TName).Name));
        }