Esempio n. 1
0
        public void IsAnonymousType_should_be_false_for_nullable_type()
        {
            Guid?obj = Guid.NewGuid();

            TypesHelper.IsAnonymousType(obj.GetType()).Should().BeFalse();
            TypesHelper.IsAnonymousType(typeof(Guid?)).Should().BeFalse();
        }
Esempio n. 2
0
        public void IsAnonymousType_should_be_false_for_non_anonymous_type()
        {
            var obj = new MyClass();

            TypesHelper.IsAnonymousType(obj.GetType()).Should().BeFalse();
            TypesHelper.IsAnonymousType(typeof(MyClass)).Should().BeFalse();
        }
Esempio n. 3
0
        public void IsAnonymousType_should_be_false_for_primitive_type()
        {
            var obj = "hello";

            TypesHelper.IsAnonymousType(obj.GetType()).Should().BeFalse();
            TypesHelper.IsAnonymousType(typeof(string)).Should().BeFalse();
            TypesHelper.IsAnonymousType(typeof(int)).Should().BeFalse();
        }
Esempio n. 4
0
        public void IsAnonymousType_should_be_true_for_anonymous_type()
        {
            var obj = new
            {
                A = 42
            };

            TypesHelper.IsAnonymousType(obj.GetType()).Should().BeTrue();
        }
        /// <summary>
        /// Logs the given <paramref name="messageTemplate"/> and <paramref name="exception"/> on the <see cref="LogLevel.Debug"/> level with given <paramref name="properties" />. The <paramref name="messageTemplate"/> can contain placeholders for <paramref name="properties"/>, see <see cref="LogEvent.MessageTemplate"/> for details.
        /// </summary>
        public static void Debug <T>(this ILog log, [CanBeNull] Exception exception, [CanBeNull] string messageTemplate, [CanBeNull] T properties)
        {
            if (!log.IsEnabledFor(LogLevel.Debug))
            {
                return;
            }

            if (!TypesHelper.IsAnonymousType(typeof(T)))
            {
                log.Debug(exception, messageTemplate, (object)properties);
                return;
            }

            log.Log(new LogEvent(LogLevel.Debug, PreciseDateTime.Now, messageTemplate, exception).WithObjectProperties(properties));
        }
        /// <summary>
        /// Logs the given <paramref name="messageTemplate"/> on the <see cref="LogLevel.Fatal"/> level with given <paramref name="properties" />. The <paramref name="messageTemplate"/> can contain placeholders for <paramref name="properties"/>, see <see cref="LogEvent.MessageTemplate"/> for details.
        /// </summary>
        public static void Fatal <T>(this ILog log, [CanBeNull] string messageTemplate, [CanBeNull] T properties)
        {
            if (!log.IsEnabledFor(LogLevel.Fatal))
            {
                return;
            }

            if (!TypesHelper.IsAnonymousType(typeof(T)))
            {
                log.Fatal(messageTemplate, (object)properties);
                return;
            }

            log.Log(new LogEvent(LogLevel.Fatal, PreciseDateTime.Now, messageTemplate).WithObjectProperties(properties));
        }
Esempio n. 7
0
 public void IsAnonymousType_should_be_false_for_generic_collections()
 {
     TypesHelper.IsAnonymousType(typeof(List <int>)).Should().BeFalse();
     TypesHelper.IsAnonymousType(typeof(Dictionary <int, string>)).Should().BeFalse();
 }