Пример #1
0
        public ValueToString(int stringBuilderCapacity, IFormatProvider[] providers, char[] delimiters, Func <Type, MemberInfo, int> membersOrder = null)
        {
            if (!DataType.IsPrimitiveType(typeof(T)) && !typeof(T).HasDefaultConstructor())
            {
                throw new NotSupportedException("No default constructor.");
            }

            bool isSupported = DataTypeUtils.IsAllPrimitive(typeof(T));

            if (!isSupported)
            {
                throw new NotSupportedException("Not all types are primitive.");
            }

            var countOfType = DataType.IsPrimitiveType(typeof(T)) ? 1 : DataTypeUtils.GetPublicMembers(typeof(T), membersOrder).Count();

            if (providers.Length != countOfType)
            {
                throw new ArgumentException("providers.Length != dataType.Length");
            }

            Type                  = typeof(T);
            MembersOrder          = membersOrder;
            StringBuilderCapacity = stringBuilderCapacity;
            Providers             = providers;
            Delimiters            = delimiters;

            to   = CreateToMethod().Compile();
            from = CreateFromMethod().Compile();
        }
Пример #2
0
        public DataToObjects(Type type, Func <Type, MemberInfo, int> membersOrder = null)
        {
            if (!DataType.IsPrimitiveType(type) && !type.HasDefaultConstructor())
            {
                throw new NotSupportedException("No default constructor.");
            }

            bool isSupported = DataTypeUtils.IsAllPrimitive(type);

            if (!isSupported)
            {
                throw new NotSupportedException("Not all types are primitive.");
            }

            Type         = type;
            MembersOrder = membersOrder;

            to   = CreateToMethod().Compile();
            from = CreateFromMethod().Compile();
        }