Exemple #1
0
        /// <summary>
        ///     Returns the GUID of the specified property.
        /// </summary>
        public static Guid GetGuidProperty(this IVsHierarchy hierarchy, VsHierarchyPropID property)
        {
            Requires.NotNull(hierarchy, nameof(hierarchy));
            Verify.HResult(hierarchy.GetGuidProperty(HierarchyId.Root, (int)property, out Guid result));

            return(result);
        }
        public static void ImplementGetProperty(this IVsHierarchy hierarchy, VsHierarchyPropID propId, object result)
        {
            var mock = Mock.Get(hierarchy);

            mock.Setup(h => h.GetProperty(It.IsAny <uint>(), It.Is <int>(p => p == (int)propId), out result))
            .Returns(0);
        }
        /// <summary>
        ///     Gets the value of the specified property if the hierarchy supports it, or returns a HRESULT if there was an error.
        /// </summary>
        public static int GetProperty <T>(this IVsHierarchy hierarchy, VsHierarchyPropID property, T defaultValue, [MaybeNull] out T result)
        {
#pragma warning disable CS8717 // Needs https://github.com/dotnet/roslyn/issues/38638
            return(GetProperty(hierarchy, HierarchyId.Root, property, defaultValue, out result));

#pragma warning restore CS8717
        }
        public static void ImplementGetGuid(this IVsHierarchy hierarchy, VsHierarchyPropID propId, int hr)
        {
            Guid result;
            var  mock = Mock.Get(hierarchy);

            mock.Setup(h => h.GetGuidProperty(It.IsAny <uint>(), It.Is <int>(p => p == (int)propId), out result))
            .Returns(hr);
        }
        /// <summary>
        ///     Returns the GUID of the specified property.
        /// </summary>
        public static Guid GetGuidProperty(this IVsHierarchy hierarchy, VsHierarchyPropID property)
        {
            Requires.NotNull(hierarchy, nameof(hierarchy));
            HResult hr = hierarchy.GetGuidProperty(HierarchyId.Root, (int)property, out Guid result);

            if (hr.Failed)
            {
                throw hr.Exception;
            }

            return(result);
        }
Exemple #6
0
 public static T GetProperty <T>(this IVsHierarchyItem item, VsHierarchyPropID propId, T defaultValue = default(T))
 {
     return(item.GetProperty <T> ((int)propId, defaultValue));
 }
        /// <summary>
        ///     Gets the value of the specified property of the specified item if the hierarchy supports it, or returns a HRESULT if there was an error.
        /// </summary>
        public static int GetProperty <T>(this IVsHierarchy hierarchy, HierarchyId item, VsHierarchyPropID property, T defaultValue, [MaybeNull] out T result)
        {
            Requires.NotNull(hierarchy, nameof(hierarchy));

            if (item.IsNilOrEmpty || item.IsSelection)
            {
                throw new ArgumentException(null, nameof(item));
            }

            HResult hr = hierarchy.GetProperty(item, (int)property, out object resultObject);

            if (hr.IsOK)
            {
                // NOTE: We consider it a bug in the underlying project system or the caller if this cast fails
                result = (T)resultObject;
                return(HResult.OK);
            }

            if (hr == HResult.MemberNotFound)
            {
                result = defaultValue;
                return(HResult.OK);
            }

            result = default !;
        /// <summary>
        ///     Gets the value of the specified property of the specified item if the hierarchy supports it, or throws an exception if there was an error.
        /// </summary>
        public static T GetProperty <T>(this IVsHierarchy hierarchy, HierarchyId item, VsHierarchyPropID property, [MaybeNull] T defaultValue = default)
        {
#pragma warning disable CS8717 // Needs https://github.com/dotnet/roslyn/issues/38638
            HResult hr = GetProperty(hierarchy, item, property, defaultValue, out T result);
#pragma warning restore CS8717
            if (hr.Failed)
            {
                throw hr.Exception;
            }

            return(result);
        }
 /// <summary>
 ///     Gets the value of the specified property if the hierarchy supports it, or throws an exception if there was an error.
 /// </summary>
 public static T GetProperty <T>(this IVsHierarchy hierarchy, VsHierarchyPropID property, T defaultValue = default)
 {
     return(GetProperty(hierarchy, HierarchyId.Root, property, defaultValue));
 }
 public static int GetProperty <T>(this IVsHierarchy hierarchy, VsHierarchyPropID property, T defaultValue, out T result)
 {
     return(GetProperty(hierarchy, HierarchyId.Root, property, defaultValue, out result));
 }
        public static T GetProperty <T>(this IVsHierarchy hierarchy, HierarchyId item, VsHierarchyPropID property, T defaultValue = default)
        {
            HResult hr = GetProperty(hierarchy, item, property, defaultValue, out T result);

            if (hr.Failed)
            {
                throw hr.Exception;
            }

            return(result);
        }
Exemple #12
0
        /// <summary>
        ///     Gets the value of the specified property of the specified item if the hierarchy supports it, or throws an exception if there was an error.
        /// </summary>
        public static T?GetProperty <T>(this IVsHierarchy hierarchy, HierarchyId item, VsHierarchyPropID property, T?defaultValue = default)
        {
            Verify.HResult(GetProperty(hierarchy, item, property, defaultValue, out T? result));

            return(result);
        }
Exemple #13
0
 public static T GetProperty <T>(this IVsSolution solution, VsHierarchyPropID propId, T defaultValue = default(T))
 {
     return(solution.GetProperty <T> ((int)propId, defaultValue));
 }
Exemple #14
0
        /// <summary>
        ///     Gets the value of the specified property if the hierarchy supports it.
        /// </summary>
        public static T GetProperty <T>(this IVsHierarchy hierarchy, HierarchyId item, VsHierarchyPropID property, T defaultValue)
        {
            Requires.NotNull(hierarchy, nameof(hierarchy));

            if (item.IsNilOrEmpty || item.IsSelection)
            {
                throw new ArgumentException(null, nameof(item));
            }

            object  resultObject;
            HResult hr = hierarchy.GetProperty(item, (int)property, out resultObject);

            if (hr == VSConstants.DISP_E_MEMBERNOTFOUND)
            {
                return(defaultValue);
            }

            if (hr.Failed)
            {
                throw hr.Exception;
            }

            // NOTE: We consider it a bug in the underlying project system or the caller if this cast fails
            return((T)resultObject);
        }
        /// <summary>
        ///     Gets the value of the specified property of the specified item if the hierarchy supports it, or throws an exception if there was an error.
        /// </summary>
        public static T GetProperty <T>(this IVsHierarchy hierarchy, HierarchyId item, VsHierarchyPropID property, [MaybeNull] T defaultValue = default)
        {
#pragma warning disable CS8717 // Needs https://github.com/dotnet/roslyn/issues/38638
            Verify.HResult(GetProperty(hierarchy, item, property, defaultValue, out T result));
#pragma warning restore CS8717

            return(result);
        }