Exemplo n.º 1
0
        public static bool IsTypeNameIdentifier(string id)
        {
            if (TypeUtils.IsUnknownTypeIdentifier(id) ||
                PredefinedTypeName.IsPredefinedTypeNameIdentifier(id) ||
                TypeParameterName.IsTypeParameterNameIdentifier(id) ||
                ArrayTypeName.IsArrayTypeNameIdentifier(id) ||
                DelegateTypeName.IsDelegateTypeNameIdentifier(id))
            {
                return(false);
            }

            // unbalanced brackets
            foreach (var pair in new[] { "[]", "()" })
            {
                if (Count(id, pair[0]) != Count(id, pair[1]))
                {
                    return(false);
                }
            }

            if (MissingTickForGenericsMatcher.IsMatch(id))
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 2
0
        public static ITypeName CreateTypeName([NotNull] string identifier)
        {
            // checked first, because it's a special case
            if (IsUnknownTypeIdentifier(identifier))
            {
                return(UnknownTypeInstance);
            }
            if (PredefinedTypeName.IsPredefinedTypeNameIdentifier(identifier))
            {
                return(new PredefinedTypeName(identifier));
            }
            if (TypeParameterName.IsTypeParameterNameIdentifier(identifier))
            {
                return(new TypeParameterName(identifier));
            }
            if (ArrayTypeName.IsArrayTypeNameIdentifier(identifier))
            {
                return(new ArrayTypeName(identifier));
            }
            if (DelegateTypeName.IsDelegateTypeNameIdentifier(identifier))
            {
                return(new DelegateTypeName(identifier));
            }
            if (TypeName.IsTypeNameIdentifier(identifier))
            {
                return(new TypeName(identifier));
            }

            return(UnknownTypeInstance);
        }