예제 #1
0
            public void ConvertAndSet(object _object, string _line)
            {
                object value;

                if (method != null)
                {
                    value = method(_line);
                }
                else if (converter != null)
                {
                    value = converter.Convert(_line);
                }
                else
                {
                    throw new Exception("转换失败");
                }

                fieldInfo.SetValue(_object, value);
            }
예제 #2
0
        private static IEnumerable<T> MatchesDynamic<T>(Regex regex, string input, ICustomConverter<T> converter = null)
            where T : class, new()
        {
            string[] groupNames = regex.GetGroupNames();

            foreach (Match m in regex.Matches(input).OfType<Match>().Where(f => f.Success))
            {
                dynamic itm = new DynamicResult(m, groupNames);

                for (int i = 1; i < m.Groups.Count; ++i)
                {
                    string groupName = regex.GroupNameFromNumber(i);

                    if (converter != null)
                        converter.Convert(groupName, m.Groups[i], itm);
                }

                yield return itm;
            }
        }