• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jpacelli62 / Faaast / 9208093962

23 May 2024 12:36PM UTC coverage: 62.219% (-0.1%) from 62.332%
9208093962

push

github

Jérôme PACELLI
Add Quotes in Alias<T>

505 of 876 branches covered (57.65%)

Branch coverage included in aggregate %.

0 of 9 new or added lines in 3 files covered. (0.0%)

1 existing line in 1 file now uncovered.

1906 of 2999 relevant lines covered (63.55%)

17.22 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Faaast.Orm.QueryBuilder/TableAlias.cs
1
using System;
2
using System.Linq.Expressions;
3
using Faaast.Orm.Mapping;
4

5
namespace Faaast.Orm
6
{
7
    public class TableAlias<T>
8
    {
9
        private readonly string[] _allColumns;
10

11
        public TableMapping Mapping { get; private set; }
×
12

13
        public string Alias { get; private set; }
×
14

NEW
15
        public string Quotes { get; private set; }
×
16

17
        public string this[Expression<Func<T, object>> property]
18
        {
19
            get {
×
20
                var body = property.Body;
×
21
                switch (body.NodeType)
×
22
                {
23
                    case ExpressionType.Convert:
24
                        return ((UnaryExpression)body).Operand is MemberExpression member ? this[member.Member.Name] : throw new ArgumentException("Cannot read property value");
×
25
                    case ExpressionType.MemberAccess:
26
                        return this[((MemberExpression)body).Member.Name];
×
27
                }
28

29
                throw new NotImplementedException();
×
30
            }
×
31
        }
32

33
        public string this[string property] => this.Mapping.PropertyToColumn.TryGetValue(property, out var column) ?
×
34
                    this.FormatPrefix(column.Name) :
×
35
                    throw new ArgumentException($"Property \"{this.Mapping.ObjectClass.Name}.{property}\" is not mapped to a database column");
×
36

NEW
37
        private string WithoutAlias(string value) => string.IsNullOrWhiteSpace(this.Alias) ? string.Format(this.Quotes, value) : null;
×
38

NEW
39
        private string FormatPrefix(string value) => this.WithoutAlias(value) ?? string.Concat(this.Alias, '.', string.Format(this.Quotes, value));
×
40

NEW
41
        private string FormatSuffix(string value) => this.WithoutAlias(value) ?? string.Concat(string.Format(this.Quotes, value), " as ", this.Alias);
×
42

NEW
43
        public TableAlias(TableMapping mapping, string alias = null, string quotes = "{0}")
×
44
        {
×
45
            this.Mapping = mapping;
×
46
            this.Alias = alias;
×
NEW
47
            this.Quotes = quotes;
×
48
            _allColumns = new string[mapping.Table.Columns.Count];
×
49
            var i = 0;
×
50
            foreach (var column in mapping.Table.Columns)
×
51
            {
×
52
                _allColumns[i++] = this.FormatPrefix(column.Name);
×
53
            }
×
54

NEW
55
            this.Quotes = quotes;
×
UNCOV
56
        }
×
57

58
        public string[] AllColumns => _allColumns;
×
59

60
        public static implicit operator string(TableAlias<T> alias) => alias.FormatSuffix(alias.Mapping.Table.Name);
×
61
    }
62
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc