There are places where you can not declare new variables like in a base-constructor call (Exclaimer: this is an example to show-case the problem):
public class SportLicense : BaseEntity<SportLicense>
{
public SportLicense() : base(
tableName: new SportLicenseNames().EntityName,
recordIdFieldName: new SportLicenseNames().RecordIdFieldName)
{ }
}
It would be nice to declare the instance of SportLicenseNames
inline to avoid creating multiple instance. Sometimes it's just about optimizing performance, but often I do need the same instance a second and third time for another parameter of the base-constructor.
There are several similar scenarios where declaring a variable within an expression would be nice to avoid creating a method body (Exclaimer: this is an example to show-case the problem):
public static TEntity ThrowIfNull<TEntity, TId>(this TEntity entity, TId recordId)
where TEntity : Entity, new()
{
if (entity != null) return entity;
var e = new TEntity();
throw new($"Record not found in table '{e.EntityName}' with id '{recordId}'\r\nSELECT * FROM {e.EntityName} WHERE {e.GetPrimaryKeyColumn().Name} = '{recordId}'");
}
If it wasn't for the variable e
i could just use an expression-body. Sure I could have created another Instance of TEntity
- every time I needed a value of it in the string - but that'd just be wasteful.