Ejemplo n.º 1
0
        /// <summary>
        /// Registers the default rules.
        /// </summary>
        /// <param name="rules">The <see cref="IRulesConfiguration"/>.</param>
        public static void RegisterDefaultRules(IRulesConfiguration rules)
        {
            if (primitiveTypes == null)
            {
                primitiveTypes = AppDomain.CurrentDomain.GetAssemblies()
                                 .SelectMany(a => a.GetTypes())
                                 .Where(t => t.Namespace != null &&
                                        t.Namespace.StartsWith(nameof(System)) &&
                                        t.IsPrimitive &&
                                        t != typeof(IntPtr) &&
                                        t != typeof(UIntPtr))
                                 .ToArray();
            }

            if (collectionTypes == null)
            {
                var collectionNamespace = typeof(IEnumerable).Namespace;
                collectionTypes = AppDomain.CurrentDomain.GetAssemblies()
                                  .SelectMany(a => a.GetTypes())
                                  .Where(t => t.Namespace != null &&
                                         t.Namespace.StartsWith(collectionNamespace) &&
                                         t.IsPublic &&
                                         t.IsSerializable &&
                                         !t.IsEnum &&
                                         !typeof(Exception).IsAssignableFrom(t))
                                  .ToArray();
            }

            foreach (var primitive in primitiveTypes.Union(collectionTypes))
            {
                rules.RuleForType(primitive);
            }

            foreach (var common in new[]
            {
                typeof(Math),
                typeof(Enumerable),
                typeof(Queryable),
                typeof(string),
                typeof(DateTime),
                typeof(TimeSpan),
                typeof(Guid),
            })
            {
                rules.RuleForType(common);
            }

            rules.RuleForMethod(
                selector =>
                selector.ByNameForType <MethodInfo, object>(
                    nameof(object.ToString)));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Registers the default rules.
 /// </summary>
 /// <param name="rules">The <see cref="IRulesConfiguration"/>.</param>
 public static void RegisterDefaultRules(IRulesConfiguration rules)
 {
     rules.RuleForType(typeof(Math))
     .RuleForType(typeof(Enumerable))
     .RuleForType(typeof(Queryable))
     .RuleForType(typeof(AnonInitializer))
     .RuleForType(typeof(AnonType))
     .RuleForType(typeof(AnonValue))
     .RuleForType <string>()
     .RuleForType <DateTime>()
     .RuleForMethod(
         selector =>
         selector.ByNameForType <MethodInfo, object>(
             nameof(object.ToString)));
 }
Ejemplo n.º 3
0
 public MethodSerializerTests()
 {
     rulesConfig = ServiceHost.GetService <IRulesConfiguration>();
     rulesConfig.RuleForType <MethodSerializerTests>();
 }