Skip to content

Commit 05e71dc

Browse files
committed
Fix ignoring redefined columns
Fixes #586
1 parent 0e056e7 commit 05e71dc

File tree

2 files changed

+47
-4
lines changed

2 files changed

+47
-4
lines changed

src/SQLite.cs

+14-4
Original file line numberDiff line numberDiff line change
@@ -1875,19 +1875,29 @@ public TableMapping(Type type, CreateFlags createFlags = CreateFlags.None)
18751875

18761876
var props = new List<PropertyInfo> ();
18771877
var baseType = type;
1878+
var propNames = new HashSet<string> ();
18781879
while (baseType != typeof(object)) {
18791880
var ti = baseType.GetTypeInfo();
1880-
props.AddRange(
1881+
var newProps = (
18811882
from p in ti.DeclaredProperties
1882-
where ((p.GetMethod != null && p.GetMethod.IsPublic) || (p.SetMethod != null && p.SetMethod.IsPublic) || (p.GetMethod != null && p.GetMethod.IsStatic) || (p.SetMethod != null && p.SetMethod.IsStatic))
1883-
select p);
1883+
where
1884+
!propNames.Contains(p.Name) &&
1885+
p.CanRead && p.CanWrite &&
1886+
(p.GetMethod != null) && (p.SetMethod != null) &&
1887+
(p.GetMethod.IsPublic && p.SetMethod.IsPublic) &&
1888+
(!p.GetMethod.IsStatic) && (!p.SetMethod.IsStatic)
1889+
select p).ToList();
1890+
foreach (var p in newProps) {
1891+
propNames.Add(p.Name);
1892+
}
1893+
props.AddRange (newProps);
18841894
baseType = ti.BaseType;
18851895
}
18861896

18871897
var cols = new List<Column> ();
18881898
foreach (var p in props) {
18891899
var ignore = p.IsDefined(typeof(IgnoreAttribute),true);
1890-
if (p.CanWrite && !ignore) {
1900+
if (!ignore) {
18911901
cols.Add (new Column (p, createFlags));
18921902
}
18931903
}

tests/IgnoreTest.cs

+33
Original file line numberDiff line numberDiff line change
@@ -125,5 +125,38 @@ public void BaseIgnores ()
125125
Assert.AreEqual ("World", oo.Name);
126126
}
127127

128+
public class RedefinedBaseClass
129+
{
130+
public string Name { get; set; }
131+
public List<string> Values { get; set; }
132+
}
133+
134+
public class RedefinedClass : RedefinedBaseClass
135+
{
136+
[Ignore]
137+
public new List<string> Values { get; set; }
138+
public string Value { get; set; }
139+
}
140+
141+
[Test]
142+
public void RedefinedIgnores ()
143+
{
144+
var db = new TestDb ();
145+
db.CreateTable<RedefinedClass> ();
146+
147+
var o = new RedefinedClass {
148+
Name = "Foo",
149+
Value = "Bar",
150+
Values = new List<string> { "hello", "world" },
151+
};
152+
153+
db.Insert (o);
154+
155+
var oo = db.Table<RedefinedClass> ().First ();
156+
157+
Assert.AreEqual ("Foo", oo.Name);
158+
Assert.AreEqual ("Bar", oo.Value);
159+
Assert.AreEqual (null, oo.Values);
160+
}
128161
}
129162
}

0 commit comments

Comments
 (0)