Skip to content

Commit ef68027

Browse files
committed
Cache types and removed unused reference.
1 parent 0e751e0 commit ef68027

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

src/UnityEventAggregator/BaseClass.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ namespace UnityEventAggregator
77
{
88
public class BaseClass : MonoBehaviour
99
{
10+
private Type[] _typeCache;
11+
1012
void Start()
1113
{
1214
GetListenerTypes().Each(x => EventAggregator.Register(this, x));
@@ -19,12 +21,18 @@ void OnDestroy()
1921

2022
IEnumerable<Type> GetListenerTypes()
2123
{
22-
return GetType()
23-
.GetInterfaces()
24-
.Where(x => x.IsGenericType)
25-
.Where(x => x.GetGenericTypeDefinition() == typeof(IListener<>))
26-
.Select(x => x.GetGenericArguments())
27-
.First();
24+
if (_typeCache != null) return _typeCache;
25+
26+
var types = GetType()
27+
.GetInterfaces()
28+
.Where(x => x.IsGenericType)
29+
.Where(x => x.GetGenericTypeDefinition() == typeof(IListener<>))
30+
.Select(x => x.GetGenericArguments())
31+
.First();
32+
33+
_typeCache = types;
34+
35+
return types;
2836
}
2937
}
3038
}

src/UnityEventAggregator/UnityEventAggregator.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
<Reference Include="System.Core" />
3636
<Reference Include="System.Xml.Linq" />
3737
<Reference Include="System.Data.DataSetExtensions" />
38-
<Reference Include="Microsoft.CSharp" />
3938
<Reference Include="System.Data" />
4039
<Reference Include="System.Xml" />
4140
<Reference Include="UnityEngine">

0 commit comments

Comments
 (0)