Skip to content

Commit 499ecc3

Browse files
committed
Simplify searching for base properties
Signed-off-by: Dimitar Dobrev <[email protected]>
1 parent 914b977 commit 499ecc3

File tree

2 files changed

+14
-25
lines changed

2 files changed

+14
-25
lines changed

src/AST/ClassExtensions.cs

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static Method GetBaseMethod(this Class @class, Method @override)
5656
}
5757

5858
public static Property GetBaseProperty(this Class @class, Property @override,
59-
bool onlyFirstBase = false, bool getTopmost = false)
59+
bool onlyFirstBase = false)
6060
{
6161
foreach (var @base in @class.Bases)
6262
{
@@ -66,44 +66,33 @@ public static Property GetBaseProperty(this Class @class, Property @override,
6666
(onlyFirstBase && @base.Class.IsInterface))
6767
continue;
6868

69-
Property baseProperty;
70-
if (!getTopmost)
71-
{
72-
baseProperty = @base.Class.GetBaseProperty(@override, onlyFirstBase);
73-
if (baseProperty != null)
74-
return baseProperty;
75-
}
76-
7769
var properties = @base.Class.Properties.Concat(@base.Class.Declarations.OfType<Property>());
78-
baseProperty = (from property in properties
79-
where property.OriginalName == @override.OriginalName &&
80-
property.Parameters.SequenceEqual(@override.Parameters,
81-
ParameterTypeComparer.Instance)
82-
select property).FirstOrDefault();
70+
Property baseProperty = (from property in properties
71+
where property.OriginalName == @override.OriginalName &&
72+
property.Parameters.SequenceEqual(@override.Parameters,
73+
ParameterTypeComparer.Instance)
74+
select property).FirstOrDefault();
8375

8476
if (baseProperty != null)
8577
return baseProperty;
8678

87-
if (getTopmost)
88-
{
89-
baseProperty = @base.Class.GetBaseProperty(@override, onlyFirstBase, true);
90-
if (baseProperty != null)
91-
return baseProperty;
92-
}
79+
baseProperty = @base.Class.GetBaseProperty(@override, onlyFirstBase);
80+
if (baseProperty != null)
81+
return baseProperty;
9382
}
9483
return null;
9584
}
9685

9786
public static bool HasNonAbstractBasePropertyInPrimaryBase(this Class @class, Property property)
9887
{
99-
var baseProperty = @class.GetBaseProperty(property, true, true);
88+
var baseProperty = @class.GetBaseProperty(property, true);
10089
return baseProperty != null && !baseProperty.IsPure &&
10190
!((Class) baseProperty.OriginalNamespace).IsInterface;
10291
}
10392

10493
public static Property GetPropertyByName(this Class @class, string propertyName)
10594
{
106-
Property property = @class.Properties.FirstOrDefault(m => m.Name == propertyName);
95+
Property property = @class.Properties.Find(m => m.Name == propertyName);
10796
if (property != null)
10897
return property;
10998

@@ -119,10 +108,10 @@ public static Property GetPropertyByName(this Class @class, string propertyName)
119108

120109
public static Property GetPropertyByConstituentMethod(this Class @class, Method method)
121110
{
122-
var property = @class.Properties.FirstOrDefault(p => p.GetMethod == method);
111+
var property = @class.Properties.Find(p => p.GetMethod == method);
123112
if (property != null)
124113
return property;
125-
property = @class.Properties.FirstOrDefault(p => p.SetMethod == method);
114+
property = @class.Properties.Find(p => p.SetMethod == method);
126115
if (property != null)
127116
return property;
128117

src/Generator/Generators/CSharp/CSharpSources.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1403,7 +1403,7 @@ private void GenerateProperties(Class @class)
14031403
// check if overriding a property from a secondary base
14041404
Property rootBaseProperty;
14051405
var isOverride = prop.IsOverride &&
1406-
(rootBaseProperty = @class.GetBaseProperty(prop, true, true)) != null &&
1406+
(rootBaseProperty = @class.GetBaseProperty(prop, true)) != null &&
14071407
(rootBaseProperty.IsVirtual || rootBaseProperty.IsPure);
14081408

14091409
if (isOverride)

0 commit comments

Comments
 (0)