示例#1
0
        public static string GenerateUpdateFields(IDatabaseModel model)
        {
            StringBuilder StringBuilder = new StringBuilder();

            foreach (FieldInfo Field in model.GetType().GetFields(System.Reflection.BindingFlags.Public
                                                                  | System.Reflection.BindingFlags.GetField | BindingFlags.Instance))
            {
                CustomAttributeData l_ExcludeFromUpdate = Field.CustomAttributes.FirstOrDefault(customAttributes => customAttributes.AttributeType == typeof(TableFieldExcludeFromUpdateAttribute));

                if (l_ExcludeFromUpdate != null && Convert.ToBoolean(l_ExcludeFromUpdate.ConstructorArguments.First().Value))
                {
                    continue;
                }

                CustomAttributeData l_TableFieldName = Field.CustomAttributes.FirstOrDefault(customAttributes => customAttributes.AttributeType == typeof(TableFieldNameAttribute));

                if (l_TableFieldName == null)
                {
                    continue;
                }

                string FieldName  = (string)l_TableFieldName.ConstructorArguments.First().Value;
                object FieldValue = Field.GetValue(model);
                StringBuilder.Append(StringBuilder.Length == 0 ? $"{FieldName} = {SQLiteDBCommon.SetValueForSql(FieldValue)}" : $", {FieldName} = {SQLiteDBCommon.SetValueForSql(FieldValue)}");
            }

            return(StringBuilder.ToString());
        }
示例#2
0
        public static List <object> ModelFieldValues(object model)
        {
            List <object> ModelFieldValues = new List <object>();

            foreach (var properties in model.GetType().GetFields(System.Reflection.BindingFlags.Public
                                                                 | System.Reflection.BindingFlags.GetField | BindingFlags.Instance))
            {
                object Value = properties.GetValue(model);
                ModelFieldValues.Add(SQLiteDBCommon.SetValueForSql(Value));
            }

            return(ModelFieldValues);
        }