Beispiel #1
0
        /// <summary>
        /// Determines whether this instance [can map field] the specified model properties.
        /// </summary>
        /// <typeparam name="TModel"></typeparam>
        /// <param name="modelProperties">The model properties.</param>
        /// <param name="message">The message.</param>
        /// <returns></returns>
        public override bool CanMapField <TModel>(IModelProperties <TModel> modelProperties, out string message)
        {
            bool canRead = modelProperties.CanConvertTo(FieldType, Name);

            if (!canRead)
            {
                Type propertyType = modelProperties.GetPropertyType(Name);
                message = string.Format("{0}.{1} is not able to be read ({2}) Ampla field type is {3}.", typeof(TModel), Name, FieldType, propertyType);

                return(false);
            }
            message = null;
            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// Determines whether this instance [can map field] the specified model properties.
        /// </summary>
        /// <typeparam name="TModel"></typeparam>
        /// <param name="modelProperties">The model properties.</param>
        /// <param name="message">The message.</param>
        /// <returns></returns>
        public override bool CanMapField <TModel>(IModelProperties <TModel> modelProperties, out string message)
        {
            Type propertyType = modelProperties.GetPropertyType(Name);

            bool canRead  = modelProperties.CanConvertTo(FieldType, Name);
            bool canWrite = CanWrite && modelProperties.CanConvertFrom(FieldType, Name);

            bool canRoundTrip = CanRoundTrip(FieldType, propertyType);

            message = null;
            if (canRead && canWrite && canRoundTrip)
            {
                return(true);
            }

            string verb = !canRead && !canWrite ?"is not" : "may not be";

            message = string.Format("Model property '{0}' ({1}) {2} compatible with the Ampla field ({3})", Name, propertyType, verb, FieldType);
            return(false);
        }