public ParsingTypeInfo Register <T>(Func <T> factory) { var type = typeof(T); var options = ExtractArgs <OptionAttribute, ParsingOptionInfo>(type, pair => new ParsingOptionInfo(pair.Item1, pair.Item2), attr => optionAttributes.Add(attr)); var values = ExtractArgs <ValueAttribute, ParsingValueInfo>(type, pair => new ParsingValueInfo(pair.Item1, pair.Item2)); ParsingTypeInfo typeInfo = CreateTypeInfo(type, options, values, factory); typeValidator.Verify(typeInfo, optionAttributes); return(typeInfo); }
private ParsingTypeInfo CreateTypeInfo <T>(Type type, IEnumerable <ParsingOptionInfo> optionInfos, IEnumerable <ParsingValueInfo> valueInfos, Func <T> factory) { ParsingTypeInfo typeInfo; var commandAttribute = type.GetTypeInfo().GetCustomAttribute <CommandAttribute>(); if (commandAttribute != null) { typeInfo = new ParsingCommandTypeInfo(valueInfos, optionInfos, factory, commandAttribute); } else { typeInfo = new ParsingTypeInfo(valueInfos, optionInfos, factory); } return(typeInfo); }