Skip to content

Commit 221cf92

Browse files
committed
Assign the cast of DescriptorBase to TDescriptor to field
Performs the cast only once
1 parent bfb468d commit 221cf92

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/Nest/CommonAbstractions/Fluent/DescriptorBase.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,15 @@ public abstract class DescriptorBase<TDescriptor, TInterface> : IDescriptor
99
where TDescriptor : DescriptorBase<TDescriptor, TInterface>, TInterface
1010
where TInterface : class
1111
{
12-
protected TInterface Self => (TDescriptor)this;
13-
protected TDescriptor Assign(Action<TInterface> assigner) => Fluent.Assign((TDescriptor)this, assigner);
12+
private readonly TDescriptor _self;
13+
14+
protected DescriptorBase()
15+
{
16+
_self = (TDescriptor)this;
17+
}
18+
19+
protected TInterface Self => _self;
20+
protected TDescriptor Assign(Action<TInterface> assigner) => Fluent.Assign(_self, assigner);
1421

1522
/// <summary>
1623
/// Hides the <see cref="Equals"/> method.

0 commit comments

Comments
 (0)