Esempio n. 1
0
        public virtual DataModelBindingBuilder <TSourceModel, TSourceField, TTargetModel, TTargetField> Bind(ModelFieldBindingTarget <TTargetField> bindingTarget,
                                                                                                             ModelFieldBindingSource <TSourceField> bindingSource,
                                                                                                             DataModelBinding <TSourceField, TTargetField> binding)
        {
            var sourcePathBase = bindingSource.Path;
            var targetPathBase = bindingTarget.Path;

            foreach (var inputFieldBinding in binding.FieldBindings)
            {
                var target = new ModelFieldBindingTarget <TTargetField>(
                    targetPathBase.Concat(inputFieldBinding.BindingTarget.Path).ToArray(),
                    inputFieldBinding.TargetField
                    );

                if (IsBound(target))
                {
                    continue;
                }

                var source = new ModelFieldBindingSource <TSourceField>(
                    sourcePathBase.Concat(inputFieldBinding.BindingSource.Path).ToArray(),
                    inputFieldBinding.SourceField
                    );

                var fieldBinding = new ModelFieldBinding <TSourceField, TTargetField>(
                    source,
                    target,
                    inputFieldBinding.Transformation
                    );

                FieldBindings.Add(fieldBinding);
            }

            return(this);
        }
Esempio n. 2
0
 public virtual bool IsBound(ModelFieldBindingTarget <TTargetField> bindingTarget)
 {
     return(FieldBindings.Any(q => q.BindingTarget.Path.SequenceEqual(bindingTarget.Path)));
 }
Esempio n. 3
0
        public virtual DataModelBindingBuilder <TSourceModel, TSourceField, TTargetModel, TTargetField> Bind(ModelFieldBindingTarget <TTargetField> bindingTarget,
                                                                                                             ModelFieldBindingSource <TSourceField> bindingSource,
                                                                                                             IBindingTransformFactory bindingTransformFactory)
        {
            if (bindingSource == null)
            {
                throw new ArgumentNullException(nameof(bindingSource));
            }

            if (bindingTarget == null)
            {
                throw new ArgumentNullException(nameof(bindingTarget));
            }

            var bindingTransformation = bindingTransformFactory.CreateTransformation(
                bindingSource.Field, bindingTarget.Field
                );

            var fieldBinding = new ModelFieldBinding <TSourceField, TTargetField>(
                bindingSource, bindingTarget, bindingTransformation
                );

            FieldBindings.Add(fieldBinding);

            return(this);
        }
Esempio n. 4
0
 public BindingPair(ModelFieldBindingSource <TSourceField> source, ModelFieldBindingTarget <TTargetField> target)
 {
     Source = source ?? throw new ArgumentNullException(nameof(source));
     Target = target ?? throw new ArgumentNullException(nameof(target));
 }