Condividi tramite


DocumentProperties Class

Definition

Important

This API is not CLS-compliant.

This class can be used as a base class for document properties which are displayed in the Properties Window when the document is active. Simply add some public properties and they will show up in the properties window.

public ref class DocumentProperties abstract : Microsoft::VisualStudio::Shell::LocalizableProperties, IDisposable, Microsoft::VisualStudio::Shell::Interop::ISelectionContainer
[System.CLSCompliant(false)]
public abstract class DocumentProperties : Microsoft.VisualStudio.Shell.LocalizableProperties, IDisposable, Microsoft.VisualStudio.Shell.Interop.ISelectionContainer
public abstract class DocumentProperties : Microsoft.VisualStudio.Shell.LocalizableProperties, IDisposable, Microsoft.VisualStudio.Shell.Interop.ISelectionContainer
[<System.CLSCompliant(false)>]
type DocumentProperties = class
    inherit LocalizableProperties
    interface ISelectionContainer
    interface IDisposable
type DocumentProperties = class
    inherit LocalizableProperties
    interface ISelectionContainer
    interface IDisposable
Public MustInherit Class DocumentProperties
Inherits LocalizableProperties
Implements IDisposable, ISelectionContainer
Inheritance
DocumentProperties
Attributes
Implements

Examples

The following example shows a DocumentProperties object with one visible property.

using Microsoft.VisualStudio.Package;  
using System.ComponentModel;  

namespace MyLanguagePackage  
{  
    class MyDocumentProperties : DocumentProperties  
    {  
        private string m_encoding;  

        public MyDocumentProperties(CodeWindowManager mgr) : base(mgr)  
        {  
        }  

        [DisplayNameAttribute("Encoding")]  
        [CategoryAttribute("General")]  
        [DescriptionAttribute("Changes encoding scheme")]  
        public string Encoding  
        {  
            get  
            {  
                return m_encoding;  
            }  
            set  
            {  
                m_encoding = value;  
                // Write value to source text.  
                // This can be done through a custom method  
                // (called SetProperyValue in this example) on your  
                // language service class like this:  
                Source src = this.GetSource();  
                if (src != null)  
                {  
                    MyLanguageService service = src.LanguageService as MyLanguageService;  
                    if (service != null)  
                    {  
                        service.SetPropertyValue(src, "Encoding", m_encoding);  
                    }  
                }  
            }  
        }  
    }  
}  

Remarks

Document properties appear in the Properties window when that document is opened in Visual Studio. Normally, source file documents do not have properties and so the Properties window is empty. However, a language service can supply properties that can be associated with any document type supported by that language service. For example, if your language service supports embedding an encoding scheme in the source file, this could be displayed as a document property. When the property is changed, the source file is updated.

It is up to the language service to determine how document-specific properties are persisted or saved. Typically, the properties are loaded from and saved to the source file itself. The properties can be obtained when the document is parsed. When a property is updated, the value can be inserted immediately into the source file so when the source file is saved, the property is saved with it.

Notes to Implementers

If you need to support document-specific properties in your language service, you need to derive a class from the DocumentProperties class and add public properties representing the properties that can be viewed and changed. See the example in this topic to see how this is typically implemented. You must override the CreateDocumentProperties(CodeWindowManager) method in the LanguageService class to return an instance of your DocumentProperties object.

Notes to Callers

Visual Studio manages the Properties window. The default implementation of the CreateDocumentProperties(CodeWindowManager) method returns a DocumentProperties object that has no viewable properties so the Properties window shows nothing. If you implement your own version of the DocumentProperties class with public properties that have the correct attributes, those properties automatically appear in the Properties window. Changes made to a property in the Properties window affect your DocumentProperties object immediately. See the example to see which attributes need to be applied to a property.

Constructors

DocumentProperties(CodeWindowManager)

Initializes a new instance of the DocumentProperties class.

Properties

Visible

Determines if the DocumentProperties object is visible in the Properties window.

Methods

Close()

Closes down the DocumentProperties object so that its properties are no longer visible in the Properties window.

CountObjects(UInt32, UInt32)

Returns the number of objects managed by this DocumentProperties object.

CreateDesignPropertyDescriptor(PropertyDescriptor)

Returns a DesignPropertyDescriptor wrapper on the given property descriptor.

(Inherited from LocalizableProperties)
Dispose()

Cleans up the object.

Dispose(Boolean)

Cleans up the object and its resources.

Finalize()

Does final cleanup of the object.

GetAttributes()

Gets a collection of attributes for this component.

(Inherited from LocalizableProperties)
GetClassName()

Returns the class name of this object.

(Inherited from LocalizableProperties)
GetCodeWindowManager()

Retrieves the code window manager associated with this DocumentProperties object.

GetComponentName()

Returns the name of this object.

(Inherited from LocalizableProperties)
GetConverter()

Returns a type converter for this object.

(Inherited from LocalizableProperties)
GetDefaultEvent()

Returns the default event for this object.

(Inherited from LocalizableProperties)
GetDefaultProperty()

Gets the default property for a component.

(Inherited from LocalizableProperties)
GetEditor(Type)

Retrieves the editor for this object.

(Inherited from LocalizableProperties)
GetEvents()

Gets the collection of events for a specified component.

(Inherited from LocalizableProperties)
GetEvents(Attribute[])

Gets the collection of events for a specified component using a specified array of attributes as a filter.

(Inherited from LocalizableProperties)
GetObjects(UInt32, UInt32, Object[])

Returns a list of objects managed by this DocumentProperties object.

GetProperties()

Gets the collection of properties.

(Inherited from LocalizableProperties)
GetProperties(Attribute[])

Returns the properties for selected object using the attribute array as a filter.

(Inherited from LocalizableProperties)
GetPropertyOwner(PropertyDescriptor)

Returns the brows-able object.

(Inherited from LocalizableProperties)
GetSource()

Returns a Source object associated with this DocumentProperties object.

Refresh()

Call this method when you want the document properties window updated with new information.

SelectObjects(UInt32, Object[], UInt32)

Called to manage the selection of multiple objects in the Properties window.

Applies to