コード例 #1
0
ファイル: Cormorant.cs プロジェクト: sbarski/cormorant
        public static IDatabaseModel MapsToTable(this IDatabaseModel databaseModel, string databaseName)
        {
            if (_tableMappings == null)
            {
                _tableMappings = new Dictionary <string, string>();
            }

            if (!_tableMappings.ContainsKey(databaseModel.GetType().FullName) && !_tableMappings.ContainsValue(databaseName))
            {
                _tableMappings.Add(databaseModel.GetType().FullName, databaseName);
            }

            return(databaseModel);
        }
コード例 #2
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());
        }
コード例 #3
0
ファイル: Cormorant.cs プロジェクト: sbarski/cormorant
        private static Dictionary <string, string> GetFieldNameMappings(IDatabaseModel databaseModel)
        {
            var nameMapping = _nameMappings
                              .Where(m => string.Equals(m.Item1, databaseModel.GetType().FullName))
                              .ToDictionary(c => c.Item2, k => k.Item3);

            return(nameMapping);
        }
コード例 #4
0
ファイル: Cormorant.cs プロジェクト: sbarski/cormorant
        private static string GetTableName(IDatabaseModel databaseModel)
        {
            var tableMappingName = _tableMappings.FirstOrDefault(m => string.Equals(m.Key, databaseModel.GetType().FullName)).Value;

            if (!string.IsNullOrEmpty(tableMappingName))
            {
                return(tableMappingName);
            }

            return(databaseModel.GetType().Name);
        }
コード例 #5
0
ファイル: Cormorant.cs プロジェクト: sbarski/cormorant
        public static IDatabaseModel MapsToField(this IDatabaseModel databaseModel, Expression <Func <Object> > property, string databasePropertyName)
        {
            if (_nameMappings == null)
            {
                _nameMappings = new List <Tuple <string, string, string> >();
            }



            var propertyName = (property.Body as MemberExpression ?? ((UnaryExpression)property.Body).Operand as MemberExpression).Member.Name;

            var tuple = new Tuple <string, string, string>(databaseModel.GetType().FullName, propertyName, databasePropertyName);

            if (_nameMappings.Contains(tuple))
            {
                return(databaseModel);
            }

            _nameMappings.Add(tuple);

            return(databaseModel);
        }
コード例 #6
0
 /// <summary>
 /// Returns an empty string if the [TableName] attribute isn't added to the property
 /// </summary>
 public static string TableName(this IDatabaseModel value)
 {
     return(value.GetType()
            .GetCustomAttribute <TableNameAttribute>()
            .TableName);
 }