コード例 #1
0
        private static TypeDeclarationSyntax GetOrCreateTargetType(SyntaxNode sourceSymbol, SyntaxNode targetNamespace, IFrameworkSet frameworkSet, ClassModel classModel, out TypeDeclarationSyntax originalTargetType)
        {
            TypeDeclarationSyntax targetType = null;

            originalTargetType = null;

            if (targetNamespace != null && sourceSymbol != null)
            {
                var types = TestableItemExtractor.GetTypeDeclarations(targetNamespace);

                var targetClassName = frameworkSet.GetTargetTypeName(classModel, true);
                originalTargetType = targetType = types.FirstOrDefault(x => string.Equals(x.GetClassName(), targetClassName, StringComparison.OrdinalIgnoreCase));

                if (originalTargetType == null)
                {
                    targetClassName    = frameworkSet.GetTargetTypeName(classModel, false);
                    originalTargetType = targetType = types.FirstOrDefault(x => string.Equals(x.GetClassName(), targetClassName, StringComparison.OrdinalIgnoreCase));
                }
            }

            if (targetType == null)
            {
                targetType = new ClassGenerationStrategyFactory(frameworkSet).CreateFor(classModel);
            }
            else
            {
                targetType = EnsureAllConstructorParametersHaveFields(frameworkSet, classModel, targetType);
            }

            return(targetType);
        }
コード例 #2
0
        public void CanCallGetTypeDeclarations()
        {
            var root   = TestSemanticModelFactory.Tree.GetRoot();
            var result = TestableItemExtractor.GetTypeDeclarations(root);

            Assert.That(result.Count, Is.EqualTo(1));
            Assert.That(result[0].GetClassName(), Is.EqualTo("ModelSource"));
        }
コード例 #3
0
 public void CannotCallGetTypeDeclarationsWithNullRoot()
 {
     Assert.Throws <ArgumentNullException>(() => TestableItemExtractor.GetTypeDeclarations(default(SyntaxNode)));
 }