コード例 #1
0
ファイル: ValueProvider.cs プロジェクト: worldspawn/cormo
        public T GetValue <T>(IInjectionPoint injectionPoint, IInstance <IValueProvider> providers)
        {
            if (injectionPoint == null)
            {
                throw new InjectionException("Value needs injection point");
            }
            var converter = TypeDescriptor.GetConverter(typeof(T));

            if (converter == null)
            {
                throw new UnsatisfiedDependencyException(injectionPoint);
            }

            var name = GetValueName(injectionPoint);

            foreach (var value in providers.OrderByDescending(x => x.Priority)
                     .Select(x => x.GetValue(name))
                     .Where(x => x != null))
            {
                try
                {
                    return((T)converter.ConvertFromString(value));
                }
                catch (Exception e)
                {
                    // TODO log
                }
            }

            return(GetDefaultValue <T>(injectionPoint));
        }