Exemple #1
0
        public static PropertyInfo[] GetProperties(Type type)
        {
            PropertyInfo[] properties = null;
            if (TypeProperties.TryGetValue(type.Name, out properties))
            {
                return(properties);
            }

            properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public);
            var filteredProperties = properties.Where(x => !AttributeDiscovery.ShouldIgnoreColumn(x)).ToArray();

            TypeProperties[type.Name] = filteredProperties;

            return(filteredProperties);
        }
Exemple #2
0
        internal static object GetValue(object instance, PropertyInfo property)
        {
            var attribute = AttributeDiscovery.GetColumnAttribute(property);

            if (attribute == null)
            {
                var value1 = property.GetValue(instance);
                if (value1 == null)
                {
                    return("NULL");
                }
                return(value1.ToString());
            }

            if (attribute.Type == SqlLiteType.Text)
            {
                if (property.PropertyType == typeof(string))
                {
                    var value2 = property.GetValue(instance);
                    if (value2 == null)
                    {
                        return("NULL");
                    }
                    return($"'{value2.ToString().Replace("'", "''")}'");
                }
                if (property.PropertyType == typeof(DateTime))
                {
                    var value3 = (DateTime)property.GetValue(instance);
                    return(value3.ToSqlLiteString());
                }
            }

            var value4 = property.GetValue(instance);

            if (value4 == null)
            {
                return("NULL");
            }
            return(value4.ToString());
        }