Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 6025180

Browse files
committed
simplify GetFieldDefinition
1 parent c1ca2b4 commit 6025180

File tree

2 files changed

+10
-17
lines changed

2 files changed

+10
-17
lines changed

src/ServiceStack.OrmLite/ModelDefinition.cs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -123,26 +123,20 @@ public FieldDefinition GetFieldDefinition<T>(Expression<Func<T, object>> field)
123123

124124
public FieldDefinition GetFieldDefinition(string fieldName)
125125
{
126-
if (fieldName == null)
127-
return null;
128-
129-
var comparison = StringComparison.OrdinalIgnoreCase;
130-
FieldDefinition bestMatch = null;
131-
132-
for (var i = 0; i < FieldDefinitionsArray.Length; ++i)
126+
if (fieldName != null)
133127
{
134-
if (string.Equals(FieldDefinitionsArray[i].Name, fieldName, comparison))
128+
foreach (var f in FieldDefinitionsArray)
135129
{
136-
bestMatch = FieldDefinitionsArray[i];
137-
if (comparison == StringComparison.Ordinal)
138-
return bestMatch;
139-
140-
comparison = StringComparison.Ordinal; // Keep looking for a better match
141-
--i; // Check the current field again, now using case-sensitive comparison
130+
if (f.Name == fieldName)
131+
return f;
132+
}
133+
foreach (var f in FieldDefinitionsArray)
134+
{
135+
if (string.Equals(f.Name, fieldName, StringComparison.OrdinalIgnoreCase))
136+
return f;
142137
}
143138
}
144-
145-
return bestMatch;
139+
return null;
146140
}
147141

148142
public void AfterInit()

tests/ServiceStack.OrmLite.Tests/Issues/ColumnGuessingTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System.Linq;
22
using NUnit.Framework;
3-
using ServiceStack.Text;
43

54
namespace ServiceStack.OrmLite.Tests.Issues
65
{

0 commit comments

Comments
 (0)