Exemplo n.º 1
0
        private string GetDataValues(IBaseData data_)
        {
            PropertyInfo[] propertyInfos = data_.GetType().GetProperties();
            string         type;
            PropertyInfo   propertyInfo;
            object         fieldValue;
            string         valueString = string.Empty;
            StringBuilder  sb          = new StringBuilder();

            for (int i = 0; i < propertyInfos.Length; i++)
            {
                propertyInfo = propertyInfos[i];
                if (propertyInfo.GetSetMethod(true) == null)
                {
                    continue;
                }
                fieldValue  = propertyInfo.GetValue(data_, null);
                type        = SqLiteHelper.GetColumnType(propertyInfo.PropertyType.Name);
                valueString = type == SqLiteHelper.TEXT ? string.Format("{0}{1}{2}", "'", fieldValue.ToString(), "'") : fieldValue.ToString();
                if (i == 0)
                {
                    sb.Append(valueString);
                }
                else
                {
                    sb.Append(string.Format(",{0}", valueString));
                }
            }

            return(sb.ToString());
        }
Exemplo n.º 2
0
        private string CreateTableColumnsString <TBaseData>() where TBaseData : IBaseData
        {
            List <PropertyInfo> propertyInfos = new List <PropertyInfo>(
                typeof(TBaseData).GetProperties().Where(prop_ => Attribute.IsDefined(prop_, typeof(DbFieldAttribute)))
                );

            StringBuilder sb        = new StringBuilder();
            string        fieldType = string.Empty;

            for (int i = 0; i < propertyInfos.Count; i++)
            {
                fieldType = SqLiteHelper.GetColumnType(propertyInfos[i].PropertyType.Name);
                if (i == 0)
                {
                    sb.AppendFormat("{0} {1}", propertyInfos[i].Name, fieldType);
                }
                else
                {
                    sb.AppendFormat(", {0} {1}", propertyInfos[i].Name, fieldType);
                }
            }

            sb.Append(", Timestamp DATETIME DEFAULT CURRENT_TIMESTAMP");

            return(sb.ToString());
        }