예제 #1
0
        public ITimestampStringConverter Resolve(string format)
        {
            string[] formatParts = format?.Split(new char[] { ':' }, count: 2, options: StringSplitOptions.RemoveEmptyEntries);

            string converterId   = formatParts?.FirstOrDefault();
            string configuration = formatParts?.Skip(1).FirstOrDefault();

            ITimestampStringConverter converter = String.IsNullOrWhiteSpace(converterId)
                                                ? CreateDefaultConverter()
                                                : ResolveConverterFromId(converterId);

            // if was not resolved and no configuration is provided but converterId has value,
            // value of the converterId may be the configuration for the default converter.
            if (converter == null &&
                String.IsNullOrWhiteSpace(configuration) &&
                String.IsNullOrWhiteSpace(converterId) == false)
            {
                converter     = CreateDefaultConverter();
                configuration = converterId;
            }

            if (String.IsNullOrWhiteSpace(configuration) == false)
            {
                converter.Configure(configuration);
            }

            return(converter);
        }