Helper for accessing base type references in AST.
Inheritance: Helper
Esempio n. 1
0
        /// <summary>
        /// Guesses the base type kind basing on name.
        /// </summary>
        /// <param name="baseType"></param>
        /// <returns></returns>
        public static Roslyn.TypeKind GuessBaseTypeKindFromName(BaseTypeSyntax baseType)
        {
            var helper = new BaseTypeReference(baseType);
            var name = helper.Name;
            var firstLetter = name[0];

            if (firstLetter == 'I')
            {
                return Roslyn.TypeKind.Interface;
            }

            return Roslyn.TypeKind.Class;
        }
Esempio n. 2
0
        /// <summary>
        /// Used for assessing whether <see cref="SeparateClassAndInterfacesBasedOnNames"/> can be used for separating class and interfaces.
        /// </summary>
        /// <param name="baseTypes"></param>
        /// <returns></returns>
        public static bool CanSeparateClassAndInterfacesBasedOnNames(IEnumerable<BaseTypeSyntax> baseTypes)
        {
            int nameStartsWithIBaseTypes = 0;
            int nameDoesNotStartWithIBaseTypes = 0;

            foreach (var baseType in baseTypes)
            {
                var helper = new BaseTypeReference(baseType);
                var name = helper.Name;
                var firstLetter = name[0];

                if (firstLetter == 'I')
                {
                    nameStartsWithIBaseTypes++;
                }
                else
                {
                    nameDoesNotStartWithIBaseTypes++;
                }
            }

            return nameDoesNotStartWithIBaseTypes <= 1;
        }
Esempio n. 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ClassDeclaration"/> class.
 /// </summary>
 /// <param name="classDeclarationNode"></param>
 /// <param name="semanticModel"></param>
 public ClassDeclaration(ClassDeclarationSyntax classDeclarationNode, SemanticModel semanticModel)
     : base(classDeclarationNode, semanticModel)
 {
     this.interfaces = null;
     this.baseClass  = null;
 }
Esempio n. 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ClassDeclaration"/> class.
 /// </summary>
 /// <param name="classDeclarationNode"></param>
 /// <param name="semanticModel"></param>
 public ClassDeclaration(ClassDeclarationSyntax classDeclarationNode, SemanticModel semanticModel)
     : base(classDeclarationNode, semanticModel)
 {
     this.interfaces = null;
     this.baseClass = null;
 }
Esempio n. 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ClassDeclaration"/> class.
 /// </summary>
 /// <param name="classDeclarationNode"></param>
 public ClassDeclaration(ClassDeclarationSyntax classDeclarationNode)
     : base(classDeclarationNode)
 {
     this.interfaces = null;
     this.baseClass = null;
 }
Esempio n. 6
0
        /// <summary>
        /// Guesses the base type kind basing on the name of the base type.
        /// </summary>
        /// <param name="baseTypes"></param>
        /// <returns></returns>
        /// <remarks>
        /// 
        /// </remarks>
        public static IEnumerable<BaseTypeInfo> SeparateClassAndInterfacesBasedOnNames(IEnumerable<BaseTypeSyntax> baseTypes)
        {
            if (!CanSeparateClassAndInterfacesBasedOnNames(baseTypes))
            {
                throw new ArgumentException(nameof(baseTypes), "The provided collection of base types cannot be evaluated via this approach");
            }

            var infos = new List<BaseTypeInfo>();

            foreach (var baseType in baseTypes)
            {
                var helper = new BaseTypeReference(baseType);
                var name = helper.Name;
                var firstLetter = name[0];

                if (firstLetter == 'I')
                {
                    infos.Add(new BaseTypeInfo() { Node = baseType, Kind = Roslyn.TypeKind.Interface });
                }
                else
                {
                    infos.Add(new BaseTypeInfo() { Node = baseType, Kind = Roslyn.TypeKind.Class });
                }
            }

            return infos;
        }
Esempio n. 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ClassDeclaration"/> class.
 /// </summary>
 /// <param name="classDeclarationNode"></param>
 public ClassDeclaration(ClassDeclarationSyntax classDeclarationNode)
     : base(classDeclarationNode)
 {
     this.interfaces = null;
     this.baseClass  = null;
 }
Esempio n. 8
0
        private static void TestRetrieveTypeName(BaseTypeSyntax baseTypeNode, string expected)
        {
            Assert.IsNotNull(baseTypeNode, "Found node should be of type `{0}`!",
                typeof(BaseTypeSyntax).Name);

            BaseTypeReference baseTypeReference = new BaseTypeReference(baseTypeNode);
            string name = baseTypeReference.Name;

            Assert.IsNotNull(name, "Type name should not be null!");
            Assert.AreNotEqual(string.Empty, name, "Type name should not be empty!");
            Assert.AreEqual(expected, name, "Type name is not the one in source!");
        }