C# 如何在Visual Studio扩展的属性窗口对象列表中修改名称

C# 如何在Visual Studio扩展的属性窗口对象列表中修改名称,c#,visual-studio,plugins,C#,Visual Studio,Plugins,我正在为VisualStudio编写一个扩展,并创建了一个类,用于在“属性”窗口中显示自定义信息。我想修改“属性”窗口顶部的对象列表中显示的文本,但找不到执行此操作的方法。我发现这个页面似乎描述了我想要的: 然而,这种描述似乎不起作用。首先,说明中指出“使用IProvideClassInfo接口提供的name属性从对象本身检索以粗体显示在对象类型左侧的对象名称”,但IProvideClassInfo没有名为“name”的属性。描述中还指出,类“IProvideClassInfo”的方法“Get

我正在为VisualStudio编写一个扩展,并创建了一个类,用于在“属性”窗口中显示自定义信息。我想修改“属性”窗口顶部的对象列表中显示的文本,但找不到执行此操作的方法。我发现这个页面似乎描述了我想要的:

然而,这种描述似乎不起作用。首先,说明中指出“使用IProvideClassInfo接口提供的name属性从对象本身检索以粗体显示在对象类型左侧的对象名称”,但IProvideClassInfo没有名为“name”的属性。描述中还指出,类“IProvideClassInfo”的方法“GetClassInfo”返回一个“ITypeInfo”,但该函数的输出参数类型为“type”,而不是“ITypeInfo”

我希望在“属性”窗口中显示其信息的类当前看起来如下所示:

public class MyProperties
{
    [Description("MyDescription")]
    [Category("MyCategory")]
    public string MyProperty { get { return "The text"; } }
}
属性“MyProperty”显示得很好,具有正确的描述和类别,但是我没有成功地修改对象列表中的文本。我试图让类“MyClass”扩展接口“IProvideClassInfo”,但当信息显示在属性窗口中时,方法“GetClassInfo”似乎没有执行


我在这里遗漏了什么?

我在a中问了这个问题,答案是您需要实现接口或从类派生

需要实现的相应方法是GetComponentName(gridview标题中的粗体/名字)和GetClassName(gridview标题中的浅色/第二个名称)

但是,如果仅实现这两种方法,则属性网格中将不会显示其他属性。AnkhSVN在他们的解决方案中解决了这一问题(非常感谢您提供了此解决方案):

//版权所有2008 AnkhSVN项目
//
//根据Apache许可证2.0版(以下简称“许可证”)获得许可;
//除非遵守许可证,否则不得使用此文件。
//您可以通过以下方式获得许可证副本:
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
//除非适用法律要求或书面同意,软件
//根据许可证进行的分发是按“原样”进行分发的,
//无任何明示或暗示的保证或条件。
//请参阅许可证以了解管理权限和权限的特定语言
//许可证下的限制。
使用制度;
使用System.Collections.Generic;
使用系统文本;
使用系统组件模型;
名称空间Ankh.Scc
{
/// 
///设计用于在VS属性网格中显示的类的基类
/// 
公共抽象类AnkhPropertyGridItem:CustomTypeDescriptor
{
/// 
///获取gridview标头中显示的灯光/秒名称
/// 
[可浏览(错误)]
受保护的抽象字符串类名
{
得到;
}
/// 
///获取gridview标题中显示的粗体/名字
/// 
[可浏览(错误)]
受保护的抽象字符串组件名
{
得到;
}
/// 
///返回此类型描述符表示的类的名称。
/// 
/// 
///包含此类型描述符正在描述的组件实例名称的。默认值为null。
/// 
公共重写密封字符串GetComponentName()
{
返回组件名称;
}
/// 
///返回此类型描述符表示的类的完全限定名。
/// 
/// 
///包含此类型描述符所描述类型的完全限定类名的。默认值为null。
/// 
公共重写密封字符串GetClassName()
{
返回类名;
}
类型转换器(rawDescriptor);
类型转换器Raw
{
获取{return}rawsdescriptor???(_rawsdescriptor=TypeDescriptor.GetConverter(this,true));}
}
/// 
///返回此类型描述符表示的对象的属性描述符集合。
/// 
/// 
///包含此类型描述符表示的对象的属性描述的。默认值为。
/// 
公共重写PropertyDescriptorCollection GetProperties()
{
返回Raw.GetProperties(this);
}
/// 
///返回此类型描述符表示的类型的类型转换器。
/// 
/// 
///此类型描述符表示的类型的。默认值是新创建的。
/// 
公共覆盖类型转换器GetConverter()
{
返回原材料;
}
/// 
///返回此类型说明符表示的对象的已筛选属性说明符集合。
/// 
///用作筛选器的属性数组。可以为null。
/// 
///包含此类型描述符表示的对象的属性描述的。默认值为。
/// 
公共重写属性DescriptorCollection GetProperties(属性[]属性)
{
返回Raw.GetProperties(null,null,attributes);
}
/// 
///返回表示当前值的值。
/// 
/// 
///表示当前值的。
/// 
公共重写字符串ToString()
{
返回类名;
}
/// 
///返回包含指定属性描述符描述的属性的对象。
/// 
///要检索所属对象的属性描述符。
/// 
///拥有由t指定的给定属性的
// Copyright 2008 The AnkhSVN Project
//
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.

using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;

namespace Ankh.Scc
{
    /// <summary>
    /// Base class for classes that are designed to be shown in the VS Property grid
    /// </summary>
    public abstract class AnkhPropertyGridItem : CustomTypeDescriptor
    {
        /// <summary>
        /// Gets the light/second name shown in the gridview header
        /// </summary>
        [Browsable(false)]
        protected abstract string ClassName
        {
            get;
        }

        /// <summary>
        /// Gets the bold/first name shown in the gridview header
        /// </summary>
        [Browsable(false)]
        protected abstract string ComponentName
        {
            get;
        }


        /// <summary>
        /// Returns the name of the class represented by this type descriptor.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.String"/> containing the name of the component instance this type descriptor is describing. The default is null.
        /// </returns>
        public override sealed string GetComponentName()
        {
            return ComponentName;
        }

        /// <summary>
        /// Returns the fully qualified name of the class represented by this type descriptor.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.String"/> containing the fully qualified class name of the type this type descriptor is describing. The default is null.
        /// </returns>
        public override sealed string GetClassName()
        {
            return ClassName;
        }

        TypeConverter _rawDescriptor;
        TypeConverter Raw
        {
            get { return _rawDescriptor ?? (_rawDescriptor = TypeDescriptor.GetConverter(this, true)); }
        }

        /// <summary>
        /// Returns a collection of property descriptors for the object represented by this type descriptor.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.ComponentModel.PropertyDescriptorCollection"/> containing the property descriptions for the object represented by this type descriptor. The default is <see cref="F:System.ComponentModel.PropertyDescriptorCollection.Empty"/>.
        /// </returns>
        public override PropertyDescriptorCollection GetProperties()
        {
            return Raw.GetProperties(this);
        }

        /// <summary>
        /// Returns a type converter for the type represented by this type descriptor.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.ComponentModel.TypeConverter"/> for the type represented by this type descriptor. The default is a newly created <see cref="T:System.ComponentModel.TypeConverter"/>.
        /// </returns>
        public override TypeConverter GetConverter()
        {
            return Raw;
        }

        /// <summary>
        /// Returns a filtered collection of property descriptors for the object represented by this type descriptor.
        /// </summary>
        /// <param name="attributes">An array of attributes to use as a filter. This can be null.</param>
        /// <returns>
        /// A <see cref="T:System.ComponentModel.PropertyDescriptorCollection"/> containing the property descriptions for the object represented by this type descriptor. The default is <see cref="F:System.ComponentModel.PropertyDescriptorCollection.Empty"/>.
        /// </returns>
        public override PropertyDescriptorCollection GetProperties(Attribute[] attributes)
        {
            return Raw.GetProperties(null, null, attributes);
        }

        /// <summary>
        /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </returns>
        public override string ToString()
        {
            return ClassName;
        }

        /// <summary>
        /// Returns an object that contains the property described by the specified property descriptor.
        /// </summary>
        /// <param name="pd">The property descriptor for which to retrieve the owning object.</param>
        /// <returns>
        /// An <see cref="T:System.Object"/> that owns the given property specified by the type descriptor. The default is null.
        /// </returns>
        public override object GetPropertyOwner(PropertyDescriptor pd)
        {
            return this;
        }
    }
}