예제 #1
0
        public static object StringToField(this IFieldInfoDescriptor fieldDescriptor, string value)
        {
            if (value == null)
            {
                return(null);
            }

            value = fieldDescriptor.StringTrim(value);

            if (string.Empty.Equals(value) && fieldDescriptor.Converter == null)
            {
                return(value);
            }

            if (fieldDescriptor.Converter == null && fieldDescriptor.Type == null)
            {
                return(value);
            }

            ConverterBase converterInstance =
                fieldDescriptor.Converter == null
                ? ConverterFactory.GetDefaultConverter(fieldDescriptor.Type, fieldDescriptor.ConverterFormat)
                : ConverterFactory.GetConverter(fieldDescriptor.Converter, fieldDescriptor.ConverterFormat);

            return(converterInstance == null
                ? value
                : converterInstance.StringToField(value));
        }
예제 #2
0
        internal static object StringToRecord(this IFieldInfoDescriptor fieldInfoDescriptor, string fieldString, char nullChar)
        {
            if (fieldString == null)
            {
                return(fieldInfoDescriptor.NullValue ?? null);
            }

            string stringNullRepresentation = new string(nullChar, fieldString.Length);

            if (fieldString == stringNullRepresentation)
            {
                return(fieldInfoDescriptor.NullValue ?? null);
            }

            fieldString = fieldInfoDescriptor.StringTrim(fieldString);
            ConverterBase converterInstance;

            if (string.Empty.Equals(fieldString) && fieldInfoDescriptor.Converter == null)
            {
                if (fieldInfoDescriptor.NullValue != null)
                {
                    fieldString = fieldInfoDescriptor.NullValue.ToString();
                }
                if (string.Empty.Equals(fieldString) && fieldInfoDescriptor.Converter == null)
                {
                    if (fieldInfoDescriptor.Type != null)
                    {
                        converterInstance = ConverterFactory.GetDefaultConverter(fieldInfoDescriptor.Type, fieldInfoDescriptor.ConverterFormat);
                        return(converterInstance == null
                            ? fieldString
                            : converterInstance.StringToField(fieldString));
                    }
                    return(fieldString);
                }
            }

            if (fieldInfoDescriptor.Converter == null && fieldInfoDescriptor.Type == null)
            {
                return(fieldString);
            }

            if (string.IsNullOrWhiteSpace(fieldString) && fieldInfoDescriptor.NullValue != null)
            {
                fieldString = fieldInfoDescriptor.NullValue.ToString();
            }

            converterInstance =
                fieldInfoDescriptor.Converter == null
                ? ConverterFactory.GetDefaultConverter(fieldInfoDescriptor.Type, fieldInfoDescriptor.ConverterFormat)
                : ConverterFactory.GetConverter(fieldInfoDescriptor.Converter, fieldInfoDescriptor.ConverterFormat);

            return(converterInstance == null
                ? fieldString
                : converterInstance.StringToField(fieldString));
        }