コード例 #1
0
ファイル: NotEmptyRule.cs プロジェクト: d7kolen/d7k-dto
        public static object DefaultValue(Type type)
        {
            if (type == typeof(string))
            {
                return("");
            }

            if (type.IsArray)
            {
                return(Activator.CreateInstance(type, 0));
            }

            if (type.IsInterface)
            {
                return(DtoFactory.Dto(type));
            }

            //Nullable available 0 default
            if (type.Name == typeof(int?).Name)
            {
                var argType = type.GenericTypeArguments[0];
                if (s_availableZeroTypes.Contains(argType))
                {
                    return(Convert.ChangeType(0, argType));
                }
            }

            return(Activator.CreateInstance(type));
        }
コード例 #2
0
 public TSource CreateDto <TSource>()
 {
     return(DtoFactory.Dto <TSource>());
 }