コード例 #1
0
        private Path Learn(object source, object target)
        {
            Path path = null;
            var sourceProps = source.GetProps();
            var targetProps = target.GetProps();
            var sci = new SmartConventionInfo
            {
                SourceType = source.GetType(),
                TargetType = target.GetType()
            };

            for (var i = 0; i < sourceProps.Count(); i++)
            {
                var s = sourceProps.ElementAt(i);
                sci.SourceProp = s;

                for (var j = 0; j < targetProps.Count(); j++)
                {
                    var t = targetProps.ElementAt(j);
                    sci.TargetProp = t;

                    if (!this.Match(sci)) continue;
                    if (path == null)
                        path = new Path
                        {
                            Source = sci.SourceType,
                            Target = sci.TargetType,
                            Pairs = new Dictionary<string, string> { { sci.SourceProp.Name, sci.TargetProp.Name } }
                        };
                    else path.Pairs.Add(sci.SourceProp.Name, sci.TargetProp.Name);
                }
            }
            return path;
        }
コード例 #2
0
 protected virtual bool Match(SmartConventionInfo c)
 {
     return c.SourceProp.Name == c.TargetProp.Name;
 }
コード例 #3
0
 protected abstract bool Match(SmartConventionInfo c);