London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!
AI OnAI Off
London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!
That's true, the EmptyDefinition property is never set
private static SiteDefinition EmptyDefinition;
// ...
public static SiteDefinition Empty
{
get
{
return EmptyDefinition ?? new SiteDefinition
{
StartPage = ContentReference.EmptyReference
};
}
internal set
{
EmptyDefinition = value;
}
}
This property will always be recreated.
Create a custom class if you must have a singleton :P
public class SiteDefinitionCustom : IReadOnly<SiteDefinitionCustom>, IReadOnly
{
private static SiteDefinition EmptyDefinition;
public bool IsReadOnly { get; private set; }
public static SiteDefinition Empty
{
get
{
// horrible but will work 😁
if(EmptyDefinition is null)
{
EmptyDefinition = new SiteDefinition
{
StartPage = ContentReference.EmptyReference
};
}
return EmptyDefinition;
}
internal set
{
EmptyDefinition = value;
}
}
public object CreateWritableClone()
{
throw new NotImplementedException();
}
public void MakeReadOnly()
{
throw new NotImplementedException();
}
SiteDefinitionCustom IReadOnly<SiteDefinitionCustom>.CreateWritableClone()
{
throw new NotImplementedException();
}
}
The description of SiteDefinition.Empty says: This is a singleton instance which can be compared against using object comparison. However, if SiteDefinition.Empty is compared to itself, the result returned is false meaning this instance is not a singleton (SiteDefinition.Empty == SiteDefinition.Empty => false).
For comparison, on the .net-framework, SiteDefinition.Empty used to be initialized in WebIdentityInitialization initialization module.