TResult ExecuteLockAction <TResult>(Func <Microsoft.Build.Evaluation.Project, TResult> callback, LockType lockType = LockType.Read, TResult defaultValue = default(TResult))
        {
            var context = ContainingProject as IVsBrowseObjectContext;

            if (context == null)
            {
                context = ContainingProject.Object as IVsBrowseObjectContext;
            }

            if (context != null)
            {
                return(AsyncManager.Run(async() =>
                {
                    if (lockType == LockType.Read)
                    {
                        using (var access = await ProjectLockService.ReadLockAsync())
                        {
                            var configuredProject = await context.UnconfiguredProject.GetSuggestedConfiguredProjectAsync();

                            var project = await access.GetProjectAsync(configuredProject);

                            return callback(project);
                        }
                    }
                    else
                    {
                        using (var access = await ProjectLockService.WriteLockAsync())
                        {
                            var configuredProject = await context.UnconfiguredProject.GetSuggestedConfiguredProjectAsync();

                            var project = await access.GetProjectAsync(configuredProject);

                            return callback(project);
                        }
                    }
                }));
            }

            return(defaultValue);
        }