コード例 #1
0
 public void Apply(ITypeConventionContext context)
 {
     Type type = context.Target;
     if (type.IsPrimitive || type == typeof (Decimal))
     {
         context.SetFactory(typeof (DefaultSource<>).MakeGenericType(type));
     }
     else if (type == typeof (string))
     {
         context.SetFactory(typeof (DefaultStringSource));
     }
 }
コード例 #2
0
        public void Apply(ITypeConventionContext context)
        {
            var type = context.Target;

            if (type.IsPrimitive || type == typeof(Decimal))
            {
                context.SetFactory(typeof(DefaultSource <>).MakeGenericType(type));
            }
            else if (type == typeof(string))
            {
                context.SetFactory(typeof(DefaultStringSource));
            }
        }
コード例 #3
0
        public void Apply(ITypeConventionContext context)
        {
            var type = context.Target;
            if (type.IsPrimitive || type == typeof(Decimal) || type == typeof(string)) { return; }

            var ctor = type.GetConstructors(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)
                        .OrderBy(x => x.GetParameters().Count())
                        .FirstOrDefault();

            if (ctor == null) { return; }

            var ctorSourceType = typeof (CtorSource<>).MakeGenericType(type);

            context.SetFactory(ctorSourceType, ctor);
        }
コード例 #4
0
        public void Apply(ITypeConventionContext context)
        {
            var type = context.Target;

            if (type.IsPrimitive || type == typeof(Decimal) || type == typeof(string))
            {
                return;
            }

            var ctor = type.GetConstructors(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)
                       .OrderBy(x => x.GetParameters().Count())
                       .FirstOrDefault();

            if (ctor == null)
            {
                return;
            }

            var ctorSourceType = typeof(CtorSource <>).MakeGenericType(type);

            context.SetFactory(ctorSourceType, ctor);
        }