private static T GetOrCreateProperty()

in EnvDTE.Host/Callback/Util/ProjectExtensions.cs [187:199]


    private static T GetOrCreateProperty<T>([NotNull] this IProject project, Lifetime lifetime, Key key, Func<IProject, T> calculateValue)
    {
        using (ReadLockCookie.Create())
        {
            var curr = project.GetProperty(key);
            if (curr is not null) return curr.GetType() == typeof(T) ? (T)curr : default;
        }

        var newValue = calculateValue(project);
        lifetime.StartMainWrite(() => project.SetProperty(key, newValue)).NoAwait();

        return newValue;
    }