Пример #1
0
        public void AddBindings(
            DataModelBindingBuilder <TSourceModel, TSourceField, TTargetModel, TTargetField> builder,
            BindingPair <TSourceField, TTargetField> bindingPair)
        {
            if (builder.IsBound(bindingPair.Target))
            {
                return;
            }

            var castMethod = GetExplicitCast(
                bindingPair.Source.FieldType.Type,
                bindingPair.Source.FieldType.Type,
                bindingPair.Target.FieldType.Type
                );

            if (castMethod == null)
            {
                castMethod = GetExplicitCast(
                    bindingPair.Target.FieldType.Type,
                    bindingPair.Source.FieldType.Type,
                    bindingPair.Target.FieldType.Type
                    );
            }

            if (castMethod == null)
            {
                return;
            }

            builder.Bind(bindingPair.Target, bindingPair.Source, new TransformFactory(castMethod));
        }
Пример #2
0
        public void AddBindings(
            DataModelBindingBuilder <TSourceModel, TSourceField, TTargetModel, TTargetField> builder,
            BindingPair <TSourceField, TTargetField> bindingPair)
        {
            if (bindingPair.Target.FieldType.Type != typeof(string) || builder.IsBound(bindingPair.Target))
            {
                return;
            }

            builder.Bind(bindingPair.Target, bindingPair.Source, ConvertWithToStringTransformFactory.Instance);
        }
Пример #3
0
        public void AddBindings(
            DataModelBindingBuilder <TSourceModel, TSourceField, TTargetModel, TTargetField> builder,
            BindingPair <TSourceField, TTargetField> bindingPair)
        {
            if (!MatchingValidTypes(bindingPair.Source.FieldType, bindingPair.Target.FieldType))
            {
                return;
            }

            if (builder.IsBound(bindingPair.Target))
            {
                return;
            }

            builder.Bind(bindingPair.Target, bindingPair.Source, ValueCopyTransformFactory.Instance);
        }
Пример #4
0
        public void AddBindings(
            DataModelBindingBuilder <TSourceModel, TSourceField, TTargetModel, TTargetField> builder,
            BindingPair <TSourceField, TTargetField> bindingPair
            )
        {
            var binding = _bindings.FirstOrDefault(
                q => q.SourceModel.Equals(bindingPair.Source.Field.FieldModel) &&
                q.TargetModel.Equals(bindingPair.Target.Field.FieldModel)
                );

            if (binding == null)
            {
                return;
            }

            builder.Bind(bindingPair.Target, bindingPair.Source, binding);
        }
Пример #5
0
        public void AddBindings(
            DataModelBindingBuilder <TSourceModel, TSourceField, TTargetModel, TTargetField> builder,
            BindingPair <TSourceField, TTargetField> bindingPair)
        {
            if (bindingPair.Source.FieldType.Type != typeof(string) || builder.IsBound(bindingPair.Target))
            {
                return;
            }

            var tryParseMethod = GetTryParseMethod(bindingPair.Source.FieldType.Type, bindingPair.Target.FieldType.Type);

            if (tryParseMethod == null)
            {
                return;
            }

            builder.Bind(bindingPair.Target, bindingPair.Source, new TransformFactory(tryParseMethod));
        }
Пример #6
0
        public void AddBindings(DataModelBindingBuilder <TSourceModel, TSourceField, TTargetModel, TTargetField> builder, BindingPair <TSourceField, TTargetField> bindingPair)
        {
            if (!IsNumericType(bindingPair.Source.FieldType.Type) ||
                !IsNumericType(bindingPair.Target.FieldType.Type) ||
                builder.IsBound(bindingPair.Target))
            {
                return;
            }

            //  bind with just a copy operation
            //  since the transform APIs work with objects and box integers etc.
            //  a cast is required in consuming APIs, thus, they handle the cast for us
            builder.Bind(bindingPair.Target, bindingPair.Source,
                         CopyIdenticalValueTypesRule <TSourceModel, TSourceField, TTargetModel, TTargetField> .ValueCopyTransformFactory.Instance);
        }