예제 #1
0
 public DataModelBindingBuilder(
     TSourceModel sourceModel, TTargetModel targetModel,
     IBindingPairProvider <TSourceModel, TSourceField, TTargetModel, TTargetField> defaultBindingPairProvider
     )
 {
     SourceModel = sourceModel;
     TargetModel = targetModel;
     _defaultBindigPairProvider = defaultBindingPairProvider;
 }
예제 #2
0
        /// <summary>
        /// Auto-bind fields using the provided binding pair provider.
        /// </summary>
        /// <param name="bindingPairProvider"></param>
        public virtual DataModelBindingBuilder <TSourceModel, TSourceField, TTargetModel, TTargetField> AutoBind(IBindingPairProvider <TSourceModel, TSourceField, TTargetModel, TTargetField> bindingPairProvider,
                                                                                                                 IEnumerable <DataModelBinding <TSourceField, TTargetField> > bindings = null)
        {
            var candidateBindingPairs = bindingPairProvider.GetBindingPairs(
                SourceModel, TargetModel
                ).ToArray();

            var autoBindingRules = _autoBindingRules;

            if (bindings != null)
            {
                autoBindingRules = _autoBindingRules
                                   .Concat(new[] { new CopyBindingsRule <TSourceModel, TSourceField, TTargetModel, TTargetField>(bindings) })
                                   .ToArray();
            }

            foreach (var bindingPair in candidateBindingPairs)
            {
                if (!bindingPair.Source.Field.CanRead || !bindingPair.Target.Field.CanWrite)
                {
                    continue;
                }

                foreach (var bindingRule in autoBindingRules)
                {
                    bindingRule.AddBindings(this, bindingPair);
                }
            }

            return(this);
        }
예제 #3
0
 public TypeBindingBuilder(TypeModel sourceModel, TypeModel targetModel,
                           IBindingPairProvider <TypeModel, PropertyField, TypeModel, PropertyField> defaultBindingPairProvider) :
     base(sourceModel, targetModel, defaultBindingPairProvider)
 {
 }
예제 #4
0
 public TypeBindingBuilder(Type sourceType, Type targetType,
                           IBindingPairProvider <TypeModel, PropertyField, TypeModel, PropertyField> defaultBindingPairProvider) :
     this(TypeModel.GetModelOf(sourceType), TypeModel.GetModelOf(targetType), defaultBindingPairProvider)
 {
 }