Ejemplo n.º 1
0
        /// <summary>
        /// Converts a object to it's string representantion
        /// </summary>
        /// <param name="instance">
        /// object to be converted to string
        /// </param>
        /// <returns>
        /// A string representation of object
        /// </returns>
        public static string ToString(object value)
        {
            if (value == null)
            {
                return(null);
            }

            else if (value is DataType)
            {
                return(ToString((DataType)value));
            }
            else if (value is DataMember)
            {
                return(ToString((DataMember)value));
            }
            else if (DataType.IsMapped(value.GetType()))
            {
                DataType dtype = value.GetType();
                return(ToString(value, dtype.AllDataMembers));
            }
            else
            {
                return(CoreConverter.ToString(value));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns true if a member is properly mapped to be stored as a foreign key, with the primary key fully mapped
        /// </summary>
        public bool IsForeignKey(MemberInfo member)
        {
            System.Type type = MemberExpression.GetReturnType(member);

            if (!DataType.IsMapped(type))
            {
                return(false);
            }

            DataType dtype = type;

            foreach (var pk in dtype.PrimaryKey)
            {
                if (!this.IsMapped(member.Name + "." + pk.Member))
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Converts an instance to it's string representantion
        /// </summary>
        /// <param name="instance">
        /// Instance to be converted to string
        /// </param>
        /// <param name="dmembers">
        /// Members that will be serialized
        /// </param>
        /// <returns>
        /// A string representation of instance
        /// </returns>
        public static string ToString(object instance, IEnumerable <DataMember> dmembers)
        {
            if (instance == null)
            {
                return(null);
            }

            if (!DataType.IsMapped(instance.GetType()))
            {
                throw new ArgumentOutOfRangeException("instance", "Instance's Type is not mapped as a DataType");
            }

            DataType dtype  = instance.GetType();
            string   result = "DataType=" + ToString(dtype) + '&';

            foreach (DataMember dmember in dmembers)
            {
                var memberValue = dmember.Member.GetValue(instance);
                result += dmember.Member.Expression + '=' + ToString(memberValue);
            }

            return(result.TrimEnd('&'));
        }