예제 #1
0
        public void NestedClassLevelNoTrace_Overrides_AssemblyLevel()
        {
            string code = @"
                using TracerAttributes;

                namespace First
                {
                    [NoTrace]
                    public class MyClass
                    {
                        public class InnerClass
                        {
                            public void PublicMethod()
                            {}

                            public void PublicMethod2()
                            {}
                        }
                    }
                }
            ";

            MethodDefinition    publicMethodDef  = GetMethodDefinition(code, "PublicMethod");
            MethodDefinition    publicMethodDef2 = GetMethodDefinition(code, "PublicMethod");
            ITraceLoggingFilter filter           = GetDefaultFilter(TraceTargetVisibility.Public, TraceTargetVisibility.All);

            filter.ShouldAddTrace(publicMethodDef).Should().BeFalse("public");
            filter.ShouldAddTrace(publicMethodDef2).Should().BeFalse("public");
        }
예제 #2
0
        public void AssemblyLevelSpecification_InternalClass_AllFilter()
        {
            string code = @"
                using TracerAttributes;

                namespace First
                {
                    internal class MyClass
                    {
                        public void PublicMethod()
                        {}

                        internal void InternalMethod()
                        {}

                        protected void ProtectedMethod()
                        {}

                        private void PrivateMethod()
                        {}
                    }
                }
            ";

            MethodDefinition    publicMethodDef    = GetMethodDefinition(code, "PublicMethod");
            MethodDefinition    internalMethodDef  = GetMethodDefinition(code, "InternalMethod");
            MethodDefinition    protectedMethodDef = GetMethodDefinition(code, "ProtectedMethod");
            MethodDefinition    privateMethodDef   = GetMethodDefinition(code, "PrivateMethod");
            ITraceLoggingFilter filter             = GetDefaultFilter(TraceTargetVisibility.All, TraceTargetVisibility.ProtectedOrMoreVisible);

            filter.ShouldAddTrace(publicMethodDef).Should().BeTrue("public");
            filter.ShouldAddTrace(internalMethodDef).Should().BeTrue("internal");
            filter.ShouldAddTrace(protectedMethodDef).Should().BeTrue("protected");
            filter.ShouldAddTrace(privateMethodDef).Should().BeFalse("private");
        }
예제 #3
0
        /// <summary>
        /// Runs the waving on the type linked to this instance (via <see cref="TypeDefinition"/>).
        /// </summary>
        public void Execute()
        {
            var methodsToVisit = _typeDefinition.GetMethods().Concat(_typeDefinition.GetConstructors())
                                 .Where(method => method.HasBody && !method.IsAbstract);

            foreach (var method in methodsToVisit.ToList())
            {
                if (AlreadyWeaved(method))
                {
                    continue;
                }

                bool shouldAddTrace = !TypeHasCompilerGeneratedAttribute && !MethodHasCompilerGeneratedAttribute(method) &&
                                      ((method.IsConstructor && _shouldTraceConstructors && !method.IsStatic) || !method.IsConstructor) &&
                                      ((method.IsPropertyAccessor() && _shouldTraceProperties) || !method.IsPropertyAccessor());

                FilterResult filterResult = new FilterResult(false);
                if (shouldAddTrace)
                {
                    filterResult = _filter.ShouldAddTrace(method);
                }

                _methodWeaverFactory.Create(method).Execute(filterResult.ShouldTrace, filterResult.Parameters);
            }
        }
예제 #4
0
        public void NestedClassLevelTraceOn_Overrides_AssemblyLevel()
        {
            string code = @"
                using TracerAttributes;

                namespace First
                {
                    [TraceOn(TraceTarget.Protected)]
                    public class MyClass
                    {
                        public class InnerClass
                        {
                            public void PublicMethod()
                            {}

                            internal void InternalMethod()
                            {}

                            protected void ProtectedMethod()
                            {}

                            private void PrivateMethod()
                            {}
                        }
                    }
                }
            ";

            MethodDefinition    publicMethodDef    = GetMethodDefinition(code, "PublicMethod");
            MethodDefinition    internalMethodDef  = GetMethodDefinition(code, "InternalMethod");
            MethodDefinition    protectedMethodDef = GetMethodDefinition(code, "ProtectedMethod");
            MethodDefinition    privateMethodDef   = GetMethodDefinition(code, "PrivateMethod");
            ITraceLoggingFilter filter             = GetDefaultFilter(TraceTargetVisibility.Public, TraceTargetVisibility.All);

            filter.ShouldAddTrace(publicMethodDef).Should().BeTrue("public");
            filter.ShouldAddTrace(internalMethodDef).Should().BeTrue("internal");
            filter.ShouldAddTrace(protectedMethodDef).Should().BeTrue("protected");
            filter.ShouldAddTrace(privateMethodDef).Should().BeFalse("private");
        }
예제 #5
0
        /// <summary>
        /// Runs the waving on the type linked to this instance (via <see cref="TypeDefinition"/>).
        /// </summary>
        public void Execute()
        {
            IEnumerable <MethodDefinition> methodsToVisit = _typeDefinition.GetMethods().Concat(_typeDefinition.GetConstructors())
                                                            .Where(method => method.HasBody && !method.IsAbstract);

            foreach (MethodDefinition method in methodsToVisit.ToList())
            {
                if (AlreadyWeaved(method))
                {
                    continue;
                }

                bool shouldAddTrace = !HasCompilerGeneratedAttribute &&
                                      ((method.IsConstructor && _shouldTraceConstructors && !method.IsStatic) || !method.IsConstructor) &&
                                      _filter.ShouldAddTrace(method) &&
                                      ((method.IsPropertyAccessor() && _shouldTraceProperties) || !method.IsPropertyAccessor());

                _methodWeaverFactory.Create(method).Execute(shouldAddTrace);
            }
        }
예제 #6
0
        public void MethodLevelNoTrace_Overrides_AssemblyLevel()
        {
            string code = @"
                using TracerAttributes;

                namespace First
                {
                    public class MyClass
                    {
                        [NoTrace]
                        public void MyMethod()
                        {}
                    }
                }
            ";

            MethodDefinition    methodDef = GetMethodDefinition(code, "MyMethod");
            ITraceLoggingFilter filter    = GetDefaultFilter(TraceTargetVisibility.Public, TraceTargetVisibility.Public);

            filter.ShouldAddTrace(methodDef).Should().BeFalse();
        }
예제 #7
0
        public void Execute()
        {
            var methodsToVisit = _typeDefinition.GetMethods().Concat(_typeDefinition.GetConstructors())
                                 .Where(method => method.HasBody && !method.IsAbstract);

            foreach (var method in methodsToVisit.ToList())
            {
                if (AlreadyWeaved(method))
                {
                    continue;
                }

                bool shouldAddTrace = !HasCompilerGeneratedAttribute && !method.IsConstructor && _filter.ShouldAddTrace(method);

                _methodWeaverFactory.Create(method).Execute(shouldAddTrace);
            }
        }