コード例 #1
0
ファイル: Configuration.cs プロジェクト: devager/Devager
        static Configuration()
        {
            mNumberFormat          = CultureInfo.InvariantCulture.NumberFormat;
            mDateTimeFormat        = CultureInfo.InvariantCulture.DateTimeFormat;
            mValidCommentChars     = new[] { '#', ';', '\'' };
            mArrayElementSeparator = ',';

            mFallbackConverter    = new FallbackStringConverter();
            mTypeStringConverters = new Dictionary <Type, ITypeStringConverter>()
            {
                { typeof(bool), new BoolStringConverter() },
                { typeof(byte), new ByteStringConverter() },
                { typeof(char), new CharStringConverter() },
                { typeof(DateTime), new DateTimeStringConverter() },
                { typeof(decimal), new DecimalStringConverter() },
                { typeof(double), new DoubleStringConverter() },
                { typeof(Enum), new EnumStringConverter() },
                { typeof(short), new Int16StringConverter() },
                { typeof(int), new Int32StringConverter() },
                { typeof(long), new Int64StringConverter() },
                { typeof(sbyte), new SByteStringConverter() },
                { typeof(float), new SingleStringConverter() },
                { typeof(string), new StringStringConverter() },
                { typeof(ushort), new UInt16StringConverter() },
                { typeof(uint), new UInt32StringConverter() },
                { typeof(ulong), new UInt64StringConverter() }
            };

            IgnoreInlineComments = false;
            IgnorePreComments    = false;
        }
コード例 #2
0
ファイル: Config.cs プロジェクト: U3DC/CatLib
 /// <summary>
 /// 增加转换器
 /// </summary>
 /// <param name="type">类型对应的转换器</param>
 /// <param name="converter">转换器</param>
 public void AddConverter(Type type, ITypeStringConverter converter)
 {
     Guard.NotNull(type, "type");
     Guard.NotNull(converter, "converter");
     typeStringConverters.Remove(type);
     typeStringConverters.Add(type, converter);
 }
コード例 #3
0
ファイル: Configuration.cs プロジェクト: devager/Devager
        internal static ITypeStringConverter FindTypeStringConverter(Type type)
        {
            ITypeStringConverter converter = null;

            if (!mTypeStringConverters.TryGetValue(type, out converter))
            {
                converter = mFallbackConverter;
            }

            return(converter);
        }
コード例 #4
0
ファイル: Config.cs プロジェクト: yangwei10723/CatLib
        /// <summary>
        /// 获取类型所需的转换器
        /// </summary>
        /// <param name="type">类型</param>
        /// <param name="converter">转换器</param>
        /// <returns></returns>
        private bool GetCoverter(Type type, out ITypeStringConverter converter)
        {
            bool status;

            do
            {
                status = typeStringConverters.TryGetValue(type, out converter);
                type   = type.BaseType;
            } while (!status && type != null);
            return(status);
        }
コード例 #5
0
        /// <summary>
        /// Registers a type converter to be used for setting value conversions.
        /// </summary>
        /// <param name="converter">The converter to register.</param>
        ///
        /// <exception cref="ArgumentNullException">When <paramref name="converter"/> is null.</exception>
        /// <exception cref="InvalidOperationException">When a converter for the converter's type is already registered.</exception>
        public static void RegisterTypeStringConverter(ITypeStringConverter converter)
        {
            if (converter == null)
            {
                throw new ArgumentNullException("converter");
            }

            var type = converter.ConvertibleType;

            if (mTypeStringConverters.ContainsKey(type))
            {
                throw new InvalidOperationException($"A converter for type '{type.FullName}' is already registered.");
            }

            mTypeStringConverters.Add(type, converter);
        }
コード例 #6
0
        static Configuration()
        {
            // For now, clone the invariant culture so that the
            // deprecated DateTimeFormat/NumberFormat properties still work,
            // but without modifying the real invariant culture instance.
            mCultureInfo = (CultureInfo)CultureInfo.InvariantCulture.Clone();

            ValidCommentChars      = new[] { '#', ';' };
            mPreferredCommentChar  = '#';
            mArrayElementSeparator = ',';

            mFallbackConverter = new FallbackStringConverter();

            // Add all stock converters.
            mTypeStringConverters = new Dictionary <Type, ITypeStringConverter>()
            {
                { typeof(bool), new BoolStringConverter() },
                { typeof(byte), new ByteStringConverter() },
                { typeof(char), new CharStringConverter() },
                { typeof(DateTime), new DateTimeStringConverter() },
                { typeof(decimal), new DecimalStringConverter() },
                { typeof(double), new DoubleStringConverter() },
                { typeof(Enum), new EnumStringConverter() },
                { typeof(short), new Int16StringConverter() },
                { typeof(int), new Int32StringConverter() },
                { typeof(long), new Int64StringConverter() },
                { typeof(sbyte), new SByteStringConverter() },
                { typeof(float), new SingleStringConverter() },
                { typeof(string), new StringStringConverter() },
                { typeof(ushort), new UInt16StringConverter() },
                { typeof(uint), new UInt32StringConverter() },
                { typeof(ulong), new UInt64StringConverter() }
            };

            IgnoreInlineComments  = false;
            IgnorePreComments     = false;
            SpaceBetweenEquals    = false;
            OutputRawStringValues = false;
        }