コード例 #1
0
        public void AnalyzeCombinedConstructor()
        {
            var injectTypeInfo = TypeAnalyzer.Analyze(typeof(HasInjectAndNoInjectConstructor));

            Assert.That(injectTypeInfo.InjectConstructor.ConstructorInfo.GetCustomAttribute <InjectAttribute>(), Is.Not.Null);
            Assert.That(injectTypeInfo.InjectConstructor.ConstructorInfo.GetParameters().Length, Is.EqualTo(1));
        }
コード例 #2
0
        bool TryGenerate(TypeDefinition typeDef, List <DiagnosticMessage> diagnosticMessages)
        {
            var type = Type.GetType($"{typeDef.FullName}, {module.Assembly.FullName}");

            if (type == null || !NeedsInjectType(type))
            {
                return(false);
            }

            InjectTypeInfo injectTypeInfo;

            try
            {
                injectTypeInfo = TypeAnalyzer.Analyze(type);
            }
            catch (Exception ex)
            {
                diagnosticMessages.Add(new DiagnosticMessage
                {
                    DiagnosticType = DiagnosticType.Warning,
                    MessageData    = $"Failed to analyze {type.FullName} : {ex.Message}"
                });
                return(false);
            }

            GenerateInnerInjectorType(typeDef, injectTypeInfo);
            return(true);
        }
コード例 #3
0
 public void AnalyzeDuplicateAttributeConstructor()
 {
     Assert.Throws <VContainerException>(() =>
     {
         TypeAnalyzer.Analyze(typeof(HasMultipleInjectConstructor));
     });
 }
コード例 #4
0
        bool TryGenerateType(TypeDefinition typeDef, List <DiagnosticMessage> diagnosticMessages)
        {
            Type type;

            try
            {
                type = GetTypeFromDef(typeDef);
            }
            catch (Exception ex)
            {
                diagnosticMessages.Add(new DiagnosticMessage
                {
                    DiagnosticType = DiagnosticType.Warning,
                    MessageData    = $"Skip IL waving because cannot detect type: {typeDef.FullName}. {ex} {ex.Message}"
                });
                return(false);
            }
            if (type == null)
            {
                diagnosticMessages.Add(new DiagnosticMessage
                {
                    DiagnosticType = DiagnosticType.Warning,
                    MessageData    = $"Skip IL waving because cannot detect type: {typeDef.FullName}"
                });
                return(false);
            }

            if (!NeedsInjectType(type))
            {
                return(false);
            }

            InjectTypeInfo injectTypeInfo;

            try
            {
                injectTypeInfo = TypeAnalyzer.Analyze(type);
            }
            catch (Exception ex)
            {
                diagnosticMessages.Add(new DiagnosticMessage
                {
                    DiagnosticType = DiagnosticType.Warning,
                    MessageData    = $"Failed to analyze {type.FullName} : {ex} {ex.Message}"
                });
                return(false);
            }

            GenerateInnerInjectorType(typeDef, injectTypeInfo);
            return(true);
        }
コード例 #5
0
        public void Analyze()
        {
            {
                var injectTypeInfo = TypeAnalyzer.Analyze(typeof(HasNoConstructor));
                Assert.That(injectTypeInfo.InjectConstructor.ParameterInfos.Length, Is.EqualTo(0));
            }

            {
                var injectTypeInfo = TypeAnalyzer.Analyze(typeof(HasNoAttributeConstructor));
                Assert.That(injectTypeInfo.InjectConstructor.ParameterInfos.Length, Is.EqualTo(2));
            }
            {
                var injectTypeInfo = TypeAnalyzer.Analyze(typeof(HasInjectConstructor));
                // Assert.That(injectTypeInfo.InjectConstructor.ConstructorInfo.GetCustomAttribute<InjectAttribute>(), Is.Not.Null);
            }
        }
コード例 #6
0
ファイル: TypeAnalyzerTests.cs プロジェクト: thanus/myriad-ql
        public void Analyze_ShouldDetectErrorIfInvalidValueTypeRuleIsGiven(
            Widget widget,
            IList <ValueType> invalidTypes)
        {
            const string sampleQuestionName = "SampleQuestion";

            foreach (var invalidType in invalidTypes)
            {
                var typeAnamyzer = new TypeAnalyzer();

                var sampleQuestionMapings = new Dictionary <string, ValueType>
                {
                    { sampleQuestionName, invalidType }
                };

                var valueTypeRule = new ValueTypeRule(invalidType, widget, null);

                typeAnamyzer.Analyze(this.GetStyleSheetWrapper(valueTypeRule), sampleQuestionMapings);

                Assert.NotEmpty(typeAnamyzer.Report.AllMessages);
                Assert.IsType <InvalidWidgetTypeMessage>(typeAnamyzer.Report.Errors.FirstOrDefault());
                Assert.Equal(1, typeAnamyzer.Report.AllMessages.Count());
            }
        }
コード例 #7
0
ファイル: TypeAnalyzerTests.cs プロジェクト: thanus/myriad-ql
        public void Analyze_ShouldThrowExceptionIfNullStyleRootNodeIsGiven()
        {
            var typeAnamyzer = new TypeAnalyzer();

            Assert.Throws <ArgumentNullException>(() => typeAnamyzer.Analyze(null, new Dictionary <string, ValueType>()));
        }
コード例 #8
0
ファイル: TypeAnalyzerTests.cs プロジェクト: thanus/myriad-ql
        public void Analyze_ShouldThrowExceptionIfNullQuestionMappingsAreGivenNodeIsGiven()
        {
            var typeAnamyzer = new TypeAnalyzer();

            Assert.Throws <ArgumentNullException>(() => typeAnamyzer.Analyze(new StyleSheet("SampleStyleSheet"), null));
        }
コード例 #9
0
        public void AnalyzeNoAttributeConstructor()
        {
            var injectTypeInfo = TypeAnalyzer.Analyze(typeof(HasMultipleConstructor));

            Assert.That(injectTypeInfo.InjectConstructor.ParameterInfos.Length, Is.EqualTo(2));
        }
コード例 #10
0
        public void AnalyzeStaticConstructor()
        {
            var injectTypeInfo = TypeAnalyzer.Analyze(typeof(HasStaticConstructor));

            Assert.That(injectTypeInfo.InjectConstructor.ConstructorInfo.IsStatic, Is.False);
        }