Пример #1
0
        public ValueToString(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");
            }

            Providers  = providers;
            Delimiters = delimiters;

            Type         = typeof(T);
            MembersOrder = membersOrder;

            LambdaFromString = CreateFromStringMethod();
            fromString       = LambdaFromString.Compile();

            LambdaToString = CreateToStringMethod();
            toString       = LambdaToString.Compile();
        }
Пример #2
0
        public DataToString(Type type, IFormatProvider[] providers, char[] delimiters, Func <Type, MemberInfo, int> membersOrder = null)
        {
            var typeCount = DataType.IsPrimitiveType(type) ? 1 : DataTypeUtils.GetPublicMembers(type, membersOrder).Count();

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

            Providers  = providers;
            Delimiters = delimiters;

            Type         = type;
            MembersOrder = membersOrder;

            LambdaFromString = CreateFromStringMethod();
            fromString       = LambdaFromString.Compile();

            LambdaToString = CreateToStringMethod();
            toString       = LambdaToString.Compile();
        }