Ejemplo n.º 1
0
        /// <summary>
        /// extracts field value from entity, and converts value to a serialized form
        /// </summary>
        protected virtual object SerializeField(object fieldOwner, Field fieldInfo, bool optional)
        {
            Type enityType = fieldOwner.GetType();

            System.Reflection.PropertyInfo pinfo = enityType.GetProperty(fieldInfo.fieldName);

            if (pinfo == null)
            {
                if (!optional)
                {
                    throw new Exception(string.Format(ErrorStrings.ERR_PROPERTY_IS_MISSING, enityType.Name, fieldInfo.fieldName));
                }

                return(null);
            }

            object propValue = pinfo.GetValue(fieldOwner, null);

            return((fieldInfo.fieldType == FieldType.Object) ? (object)SerializeObjectField(propValue, fieldInfo) : _valueConverter.SerializeField(pinfo.PropertyType, fieldInfo, propValue));
        }