StyleCop SDK

Developer’s Guide

 

 

 

Created by:

Jason Allor (jasonall)

 

Microsoft Corporation

Version 3.1.5

 

 

StyleCop was developed to facilitate maintaining a consistent C# coding style across the company.  Historically, different product groups at Microsoft have worked with drastically different coding styles. Some groups have even used varying code styles within a single product, sometimes even in the same code module.

 

With the advent and adoption of the C# programming language at Microsoft, many teams have seen an opportunity to enforce a consistent set of coding guidelines across the company.  StyleCop was written to make it easier for developers to adhere to these guidelines, and to provide a simple way to analyze a code base for style uniformity.

 

StyleCop provides an extensibility model to allow developers to add new rules, which can be plugged in and run alongside the default rules shipped with StyleCop.

 

 

Architecture

 

Creating a project:

 

To create a StyleCop rules add-in, create a new class library project in Visual Studio .NET and add a reference to StyleCopCore.dll.   Currently, there are two versions of StyleCop available, one for .Net Framework 1.1 (Visual Studio 2003), and another for version 2.0 of the Framework (Visual Studio 2005).  To create a StyleCop add-in for Visual Studio 2003 (v1.1 CLR), you must develop the add-in using VS 2003 and reference the StyleCopCore binary that ships with StyleCop 2003. Similarly, to build a plugin for Visual Studio 2005 (v2.0 CLR), you must use Visual Studio 2005 and reference StyleCopCore from StyleCop 2005.  If you need to support both versions of the CLR, you will need to build two separate projects.

 

NOTE: Because Whidbey has not shipped yet, there are multiple versions of Visual Studio 2005 available. StyleCop is currently supported for Visual Studio .NET 2005 PD5 and Beta1. This is subject to change as new releases of Whidbey are made available. You must build your add-in using the same version of Whidbey that the StyleCop will run under.

 

Once the project has been created and StyleCopCore has been referenced, create a class within the project and inherit the class from StyleCopAddin. This class contains various abstract methods and properties which must be overridden in your derived class. This is described in more detail in the StyleCopAddin section of this document.

 

Installation:

 

Once the add-in has been built, there are three ways to install the add-in so that it will be loaded by StyleCop. First, the add-in may be placed underneath StyleCop’s installation path. StyleCop will automatically discover and load add-ins under its installation path.

 

Secondly, additional add-in discovery paths can be added to the system registry. StyleCop will parse each of these paths and load any add-ins found under the path or any of its sub-directories. Add-in search paths for StyleCop 2003 should be added under the following key: HKCU\Software\Microsoft\StyleCop2003\Addins. Add-in search paths for StyleCop 2005 (VS PD5) should be added under HKCU\Software\Microsoft\StyleCop2005PD5\Addins. Search paths for StyleCop 2005 (VS Beta1) should be added under HKCU\Software\Microsoft\StyleCop2005Beta1\Addins. (NOTE: This path will change to ...\StyleCop2005\Addins when the final version of Whidbey is released).

 

To add a search path to the registry, choose the correct registry path and add a new string value under the StyleCopXXX\Addins key. The name of the value can be any unique string. The value data must specify the full path to the add-in search path.

 

The StyleCopCmd tool provides a third way to specify additional add-in search paths. Search paths can be specified on the command line using the –p flag. See the StyleCop User Guide document for more information.

 

Specifying violation types:

 

StyleCop rules add-ins must register a list of violation types that are exported from the add-in. The add-in will reference these violation types when registering a rules violation found in a C# code file. The violation types list is provided in the form of an Xml document. When the add-in is loaded, StyleCop will call the add-in’s AddinXml property. The add-in must hand back a fully-formed Xml document containing the complete list of violation types that can be discovered by the add-in. The format of the Xml file is as follows:

 

<stylecopaddin id={unique add-in id} name={friendly name}

   <violationtype id={unique violation type id} name={friendly name for the violation type}>

      <context>{context message string for the violation type}</context>

   </violationtype>

</stylecopaddin>

 

The {unique add-in id} field must be filled in with a unique guid that identifies the add-in. The {friendly name} field must provide a short name for the add-in. This name will appear in the StyleCop Settings dialog to identify the add-in. Each violation type must also be given a unique guid and friendly name. Finally, each violation type must contain a context node which provides a context message for the violation type. When a violation on this type is discovered in a code file, this message will be presented to the developer to explain the violation.

 

For example, the following violation types list file is exported by the “File Headers” add-in that ships with StyleCop:

 

<?xml version="1.0" encoding="utf-8" ?>

<stylecopaddin id="31B0AB2A-8EED-4815-9F2D-C5A439EA9809" name="File headers">

   <violationtype id="C4E60EC4-A3FB-4D1E-92EC-48A5A2F0A81D" name="FileHeaderMissing">

      <context>The file has no header, the header Xml is invalid, or the header is not at the top of the file.</context>

   </violationtype>

   <violationtype id="29BA77C5-B9DB-4EEA-AAC1-9B864AC9D5AB" name="FileHeaderCopyrightMissing">

      <context>The 'copyright' tag is missing from the file header.</context>

   </violationtype>

   <violationtype id="0386A13B-DBB2-47E3-AAA1-397AA6D1B715" name="FileHeaderCopyrightEmpty">

      <context>The 'copyright' tag in the file header is empty.</context>

   </violationtype>

   <violationtype id="FE78735E-4DA4-44C8-935B-01AD2F3D38BD" name="FileHeaderCopyrightFileMissing">

      <context>The 'file' attribute is missing from the file header 'copyright' tag.</context>

   </violationtype>

   <violationtype id="C5BD564A-6DF8-430E-80C2-D1E5CD86B227" name="FileHeaderFileNameMismatch">

      <context>The 'file' attribute in the file header's 'copyright' tag does not contain the name of the file.</context>

   </violationtype>

   <violationtype id="6A3A7A40-C91B-40C5-B159-FDF855D1483D" name="FileHeaderSummaryMissing">

      <context>The 'summary' tag is missing from the file header, or it is empty.</context>

   </violationtype>

   <violationtype id="A2AD697C-C44E-4613-9AED-5E095B67B346" name="FileHeaderCompanyTagInvalid">

      <context>The 'company' attribute in the file header's 'copyright' tag is missing or empty.</context>

   </violationtype>

</stylecopaddin>

 

A violation type’s context string may contain in-place string parameters that can be filled in with specific information when a violation is discovered. For example, consider the following violation type context message:

 

                The {0} does not have an access modifier.

 

This can be filled in later to provide the type of element that is missing its access modifier. For more information, see the StyleCopAddin.AddViolation method.

 

 

StyleCopAddin

 

Every StyleCop add-in class must inherit from the StyleCopAddin class.

 

System.Object

    Microsoft.Tools.StyleCop.StyleCopAddin

 

Members

 

Public Properties

Description

Id

Returns the unique ID of the add-in.

Name

Gets the name of the add-in.

Protected Abstract Properties

Description

AddinXml

Gets the add-in’s violation type list document.

Public Abstract Methods

Description

ProcessFile

Analyze one code file.

Public Virtual Methods

Description

GetSettingsPages

Allows the add-in to place pages on the settings dialog.

SolutionOpened

Signals that the user has opened a new Visual Studio solution.

SolutionClosing

Signals that the user has closed the current Visual Studio solution.

Public Methods

Description

AddViolation

Adds one violation against a code file.

 

 

StyleCopAddin.Id

 

Gets the ID of the add-in. Every StyleCop add-in must have its own unique GUID string.

 

public string Id { get; }

 

Property Value

 

A string that contains the unique ID of the add-in.

 

 

StyleCopAddin.Name

 

Gets the name of the add-in.

 

public string Name { get; }

 

Property Value

 

A string that contains the name of the add-in.

 

Remarks

 

The name will be presented to the user on the enable/disable rules settings page.

 

 

StyleCopAddin.AddinXml

 

Gets the add-in’s violation type list document. Every StyleCop add-in must override this property.

 

public string Id { get; }

 

Property Value

 

An XmlDocument containing the violation type list for the add-in.

 

 

StyleCopAddin.ProcessFile

 

This method is called by the StyleCop core module when it is time for the add-in to run its analyze routines on a particular code file. Every StyleCop add-in must override this method.

 

public void ProcessFile(CodeFile file);

 

Parameters

 

file

The CodeFile object that represents the file to process.

 

Remarks

 

The add-in should call the StyleCopAddin.AddViolation method to report a rules violation in the code file.

 

 

StyleCopAddin.GetSettingsPages

 

This method allows the add-in to provide one or more property pages to display on the StyleCop settings dialog.

 

public IPropertyControlPage[] GetSettingsPages();

 

Return Value

 

Return an array of Control objects implementing IPropertyControlPage, or null if the add-in has no property pages to display.

 

 

StyleCopAddin.SolutionOpened

 

This method is called when the user opens a new Visual Studio solution.

 

public void SolutionOpened();

 

 

StyleCopAddin.SolutionClosing

 

This method is called when the user closes the current Visual Studio solution.

 

public void SolutionOpened();

 

 

StyleCopAddin.AddViolation

 

This method allows the add-in to provide one or more property pages to display on the StyleCop settings dialog.

 

public void AddViolation(Element element, string violationId, params object[] values);

 

Parameters

 

element

The code Element that contains the violation.

 

violationId

The ID of the violation type. 

 

values

Optional array of string values to insert into the violation message text.

 

 

StyleCopAddin.AddViolation

 

This method allows the add-in to provide one or more property pages to display on the StyleCop settings dialog.

 

public void AddViolation(Element element, int line, string violationId, params object[] values);

 

Parameters

 

element

The code Element that contains the violation.

 

line

The line in the file on which the violation appears.

 

violationId

The ID of the violation type. 

 

values

Optional array of string values to insert into the violation message text.

 

 

Element

 

Describes one code element within a file.

 

System.Object

    Microsoft.Tools.StyleCop.Element

        Microsoft.Tools.StyleCop.ClassBase

            Microsoft.Tools.StyleCop.Class

            Microsoft.Tools.StyleCop.Interface

            Microsoft.Tools.StyleCop.Struct

        Microsoft.Tools.StyleCop.CodeFile

        Microsoft.Tools.StyleCop.Enum

        Microsoft.Tools.StyleCop.ScopedElement

            Microsoft.Tools.StyleCop.Constructor.ClassInitializer

            Microsoft.Tools.StyleCop.Enum.Item

            Microsoft.Tools.StyleCop.MethodBase

                Microsoft.Tools.StyleCop.Accessor

                Microsoft.Tools.StyleCop.Constructor

                Microsoft.Tools.StyleCop.Delegate

                Microsoft.Tools.StyleCop.Event

                Microsoft.Tools.StyleCop.Indexer

                Microsoft.Tools.StyleCop.Method

                Microsoft.Tools.StyleCop.Property

            Microsoft.Tools.StyleCop.MemberVariable

        Microsoft.Tools.StyleCop.Namespace

        Microsoft.Tools.StyleCop.Using

 

Members

 

Public Types

Description

Type

Describes the various types of elements.

Public Properties

Description

AccessModifier

The element’s access modifier.

ActualAccess

The actual visibility of the element, taking into account the access of the item’s parents all the way up the stack.

AnalyzerTag

A tag that can be used by the add-in analyzer while analyzing the file.

Children

An array of Element objects representing the child elements of this element.

CodeView

Describes the code within the element.

Declaration

Describes the element declaration.

ElementType

The Element.Type of this element.

FullNamespaceName

The fully qualified name of the element, from the namespace down.

Header

The header for the element described by this class.

LineNumber

The line number that the item begins on within the file.

Name

The name of the element described by this class.

Parent

The parent element that this element is contained under.

 

 

Element.Type

 

Enum that describes the various types of code elements processed by StyleCop and its add-ins.

 

Members

 

Values

Description

Accessor

An accessor inside of a property or an event.

Class

A class.

Constructor

A constructor.

Delegate

A delegate.

Destructor

A destructor.

Enum

An enum.

EnumItem

An item in an enum element.

Event

An event declaration.

File

A code file.

Indexer

An array indexer into a class.

Inner

The inner code from a code scope.

Interface

An interface.

MemberVariable

A member variable.

Method

A method.

Namespace

A namespace.

Property

A property.

Struct

A struct.

Unknown

An unknown element.  This usually indicates a syntax error in the code being analyzed.

Using

A using statement.

 

 

Element.AccessModifier

 

Gets the element’s access modifier type.

 

public AccessModifierType AccessModifier { get; }

 

Property Value

 

The AccessModifierType of the element.

 

 

Element.ActualAccess

 

Gets the actual access of the element as viewed outside of the class. This takes into account the access of the item’s parents.

 

public AccessModifierType ActualAccess { get; }

 

Property Value

 

The access of the element as viewed outside of the class.

 

 

Element.AnalyzerTag

 

Gets or sets a tag that can be used by the add-in while analyzing the file. The contents of this tag are reset to null before each add-in is called.

 

public object AnalyzerTag { get; set; }

 

Property Value

 

An object tag that can be used by the add-in to temporarily store data about the element while analyzing the file.

 

 

Element.Children

 

Gets the collection of child elements that this element contains. The objects in the collection all derive from the Element class.

 

public ICollection Children { get; }

 

Property Value

 

An ICollection object containing the children of this element.

 

 

Element.CodeView

 

Gets a value describing the code contained within the element.

 

public CodeView CodeView { get; }

 

Property Value

 

A CodeView object describing the code contained within the element.

 

 

Element.Declaration

 

Gets a value describing the element’s declaration code.

 

public Declaration Declaration { get; }

 

Property Value

 

A Declaration object describing the element’s declaration code.

 

 

Element.ElementType

 

Gets a value describing the type of the element.

 

public Element.Type ElementType { get; }

 

Property Value

 

An Element.Type value describing the type of the element.

 

 

Element.FullNamespaceName

 

Gets the fully-qualified namespace name of the element.

 

public string FullNamespaceName { get; }

 

Property Value

 

A string containing the fully-qualified namespace name of the element.

 

 

Element.Header

 

Gets the Xml header code from above the element, or null if there is no element header for this element.

 

public string Header { get; }

 

Property Value

 

A string value containing the Xml element header.

 

 

Element.LineNumber

 

Gets the line number that the element appears on in the code.

 

public int LineNumber { get; }

 

Property Value

 

An integer containing the line number that the element starts on in the code.

 

 

Element.Name

 

Gets the name of the element that this class describes

 

public bool Name { get; }

 

Property Value

 

A string value containing the name of the element.

 

 

Element.Parent

 

Gets the parent element that contains this element, or null if this element describes the root file.

 

public Element Parent { get; }

 

Property Value

 

A Element object describing the parent of this element.

 

 

ClassBase

 

A base class for all elements types that resemble classes, including classes, structs, and interfaces.

 

System.Object

    Microsoft.Tools.StyleCop.Element

        Microsoft.Tools.StyleCop.ClassBase

            Microsoft.Tools.StyleCop.Class

            Microsoft.Tools.StyleCop.Interface

            Microsoft.Tools.StyleCop.Struct

 

Members

 

Public Properties

Description

BaseClass

The element’s access modifier.

BaseClassName

The actual visibility of the element, taking into account the access of the item’s parents all the way up the stack.

Public Methods

Description

IsPropertyType

Indicates whether the given type is used by a property in this class.

 

 

ClassBase.BaseClass

 

Gets the ClassBase object representing the class’s base class. This returns null if the item has no base class or if the base class is not accessible to StyleCop.

 

public ClassBase BaseClass { get; }

 

Property Value

 

The base class of this item.

 

 

ClassBase.BaseClassName

 

Gets the name of the item’s base class, or null if the item has no base class.

 

public string BaseClassName { get; }

 

Property Value

 

The name of the item’s base class.

 

 

ClassBase.IsPropertyType

 

Indicates whether the class contains a property that returns a value of the given type.

 

public bool IsPropertyType(string type);

 

Parameters

 

type

The property type to search for.

 

Return Value

 

Returns true if the class contains a property with a return value of the given type.

 

 

Class

 

Describes a code class.

 

System.Object

    Microsoft.Tools.StyleCop.Element

        Microsoft.Tools.StyleCop.ClassBase

            Microsoft.Tools.StyleCop.Class

 

Members

 

Public Properties

Description

Abstract

Indicates whether this is an abstract class.

Partial

Indicates whether this is a partial class.

Sealed

Indicates whether this is a sealed class.

Public Static Methods

Description

IsClassMember

Indicates whether the given class contains a member with the given name.

 

 

Class.Abstract

 

Gets a value indicating whether the class is marked abstract.

 

public bool Abstract { get; }

 

Property Value

 

Indicates whether the class is abstract.

 

 

Class.Partial

 

Gets a value indicating whether the class is marked partial.

 

public bool Partial { get; }

 

Property Value

 

Indicates whether this is a partial class.

 

 

Class.Sealed

 

Gets a value indicating whether the class is sealed.

 

public bool Sealed { get; }

 

Property Value

 

Indicates whether the class is sealed.

 

 

Class.IsClassMember

 

A static method that indicates whether the given class contains a member with the given name.

 

public static Element IsClassMember(string name, ClassBase parentClass);

 

Parameters

 

name

The name of the member to search for in the class.

 

parentClass

The class to search for an element with the given name.

 

Return Value

 

                Returns a Element object representing the class member matching the given name if found, or null if the class does not contain a member with the given name.

 

 

Interface

 

Describes an interface in the code.

 

System.Object

    Microsoft.Tools.StyleCop.Element

        Microsoft.Tools.StyleCop.ClassBase

            Microsoft.Tools.StyleCop.Interface

 

Members

 

This class has no publicly visible members. See the ClassBase  class for more information.

 

 

Struct

 

Describes a code struct.

 

System.Object

    Microsoft.Tools.StyleCop.Element

        Microsoft.Tools.StyleCop.ClassBase

            Microsoft.Tools.StyleCop.Struct

 

Members

 

This class contains no publicly visible members. See the ClassBase  class for more information.

 

 

CodeFile

 

Describes one code file to analyze for rules violations.

 

System.Object

    Microsoft.Tools.StyleCop.Element

        Microsoft.Tools.StyleCop.CodeFile

 

Members

 

Public Properties

Description

Cache

Determines whether the code file has been loaded from cache or processed from scratch.

CodeString

A string containing the complete contents of the file.

Contents

The Element contents of the file.

FileName

The name of the file.

Path

The path to the file.

Public Methods

Description

GetCodeDocument

Gets the document object representing this code file.

 

 

CodeFile.Cache

 

StyleCop caches information about analyzed code files.  If the user runs StyleCop on the file again without changing the file in any way since the last analyze run, StyleCop loads the file information, including all violations within the file, from the cache rather than analyzing the file again. This value indicates whether the file was loaded from the cache or whether it has been loaded from scratch.

 

public bool Cache { get; }

 

Property Value

 

A boolean value that determines whether the file was loaded from cache or whether it was processed from scratch.

 

 

CodeFile.CodeString

 

Gets a value containing the contents of the file in a string.

 

public string CodeString { get; }

 

Property Value

 

A string containing the contents of the file.

 

 

CodeFile.Contents

 

Gets a Element object containing information about the contents of the file. This object is the head of a tree of Element objects representing the contents of the file.

 

public Element Contents { get; }

 

Property Value

 

A Element object containing information about the contents of the file.

 

 

CodeFile.FileName

 

Gets the name of the file.

 

public string FileName { get; }

 

Property Value

 

A string containing the name of the file.

 

 

CodeFile.Path

 

Gets the path to the file.

 

public string Path { get; }

 

Property Value

 

A string containing the path to the file.

 

 

CodeFile.GetCodeDocument

 

Gets the document object representing this code file.

 

public CodeDocument GetCodeDocument();

 

Return Value

 

                Returns an object derived from CodeDocument, representing the code file.

 

 

Enum

 

Describes an enum element.

 

System.Object

    Microsoft.Tools.StyleCop.Element

        Microsoft.Tools.StyleCop.Enum

 

Members

 

Public Properties

Description

BaseType

Gets the base type of the enum.

Items

Gets the collection of items in the enum.

Public Methods

Description

GetItem

Gets the enum item at the given index.

 

 

Enum.BaseType

 

Gets the base type of the enum, or null if there is no base type.

 

public string BaseType { get; }

 

Property Value

 

A string containing the name of the base type for the enum.

 

 

Enum.Items

 

Gets the collection of items in the enum. Each item is presented by an Enum.Item class object.

 

public ICollection Items { get; }

 

Property Value

 

The collection of Enum.Item objects representing the items in the enum.

 

 

Enum.GetItem

 

Gets the enum item at the given index.

 

public Enum.Item GetItem(int index);

 

Parameters

 

index

The index of the enum item to retrieve.

 

Return Value

 

Returns an Enum.Item representing the item at the given index.

 

 

ScopedElement

 

The base class for all element types that contain executable code. For example, methods, member variables, property accessors, enum items, etc.

 

System.Object

    Microsoft.Tools.StyleCop.Element

        Microsoft.Tools.StyleCop.ScopedElement

            Microsoft.Tools.StyleCop.Constructor.ClassInitializer

            Microsoft.Tools.StyleCop.Enum.Item

            Microsoft.Tools.StyleCop.MethodBase

                Microsoft.Tools.StyleCop.Accessor

                Microsoft.Tools.StyleCop.Constructor

                Microsoft.Tools.StyleCop.Delegate

                Microsoft.Tools.StyleCop.Event

                Microsoft.Tools.StyleCop.Indexer

                Microsoft.Tools.StyleCop.Method

                Microsoft.Tools.StyleCop.Property

            Microsoft.Tools.StyleCop.MemberVariable

 

Members

 

Public Properties

Description

Body

A hierarchical tree describing the code contents.

 

ScopedElement.Body

 

Gets the head of a tree of Scope objects that describe the code contents.

 

public Scope Body { get; }

 

Property Value

 

A Scope object describing the code contents.

 

 

Constructor.ClassInitializer

 

Represents the initialization code on a constructor.

 

System.Object

    Microsoft.Tools.StyleCop.Element

        Microsoft.Tools.StyleCop.ScopedElement

            Microsoft.Tools.StyleCop.Constructor.ClassInitializer

 

Members

 

This class has no publicly visible members. See the ScopedElement  class for more information.

 

 

Enum.Item

 

Represents one item within an enum.

 

System.Object

    Microsoft.Tools.StyleCop.Element

        Microsoft.Tools.StyleCop.ScopedElement

            Microsoft.Tools.StyleCop.Enum.Item

 

Members

 

This class has no publicly visible members. See the ScopedElement  class for more information.

 

 

MethodBase

 

The base class for all element types that contain executable code. For example, methods, member variables, property accessors, enum items, etc.

 

System.Object

    Microsoft.Tools.StyleCop.Element

        Microsoft.Tools.StyleCop.ScopedElement

            Microsoft.Tools.StyleCop.MethodBase

                Microsoft.Tools.StyleCop.Accessor

                Microsoft.Tools.StyleCop.Constructor

                Microsoft.Tools.StyleCop.Delegate

                Microsoft.Tools.StyleCop.Event

                Microsoft.Tools.StyleCop.Indexer

                Microsoft.Tools.StyleCop.Method

                Microsoft.Tools.StyleCop.Property

 

Members

 

Public Properties

Description

ReturnType

The type of the value returned from this element.

Parameters

The collection of parameters passed into the element.

Public Methods

Description

GetParameter

Gets the parameter at the given index.

 

MethodBase.ReturnType

 

Gets the type of the value returned from this element, or null if the element does not have a return value.

 

public string ReturnType { get; }

 

Property Value

 

The type of the value returned from this element.

 

 

MethodBase.Parameters

 

Gets the collection of parameters passed into this element. Each parameter is represented by a Parameter object.

 

public ICollection Parameters { get; }

 

Property Value

 

The collection of Parameter objects representing the parameters passed into this element.

 

MethodBase.GetParameter

 

Gets the parameter at the given index.

 

public Parameter GetParameter(int index);

 

Parameters

 

index

The index of the parameter to retrieve.

 

Return Value

 

Returns the Parameter at the given index.

 

 

Accessor

 

Describes one accessor within a property, indexer, or event.

 

System.Object

    Microsoft.Tools.StyleCop.Element

        Microsoft.Tools.StyleCop.ScopedElement

            Microsoft.Tools.StyleCop.MethodBase

                Microsoft.Tools.StyleCop.Accessor

 

Members

 

Public Types

Description

Type

An enum listing the various types of accessors.

Public Properties

Description

AccessorType

The type of this accessor.

 

 

Accessor.Type

 

An enum listing the possible accessor types.

 

Members

 

Values

Description

Get

A get accessor on a property or indexer.

Set

A set accessor on a property or indexer.

Add

An add accessor on an event.

Remove

A remove accessor on an event.

 

 

Accessor.AccessorType

 

Gets the type of the accessor.

 

public Accessor.Type AccessorType { get; }

 

Property Value

 

The type of the accessor.

 

 

Constructor

 

Describes a constructor or destructor.

 

System.Object

    Microsoft.Tools.StyleCop.Element

        Microsoft.Tools.StyleCop.ScopedElement

            Microsoft.Tools.StyleCop.MethodBase

                Microsoft.Tools.StyleCop.Constructor

 

Members

 

Public Properties

Description

Initializer

Gets the class initializer code for the constructor.

 

 

Constructor.Initializer

 

Gets the initialization code for the constructor.

 

public Constructor.ClassInitializer Initializer { get; }

 

Property Value

 

A ClassInitializer object representing the initialization code for the constructor.

 

 

Delegate

 

Describes a delegate element.

 

System.Object

    Microsoft.Tools.StyleCop.Element

        Microsoft.Tools.StyleCop.ScopedElement

            Microsoft.Tools.StyleCop.MethodBase

                Microsoft.Tools.StyleCop.Delegate

 

Members

 

This class has no publicly visible members. See the MethodBase class for more information.

 

 

Event

 

Describes an event element.

 

System.Object

    Microsoft.Tools.StyleCop.Element

        Microsoft.Tools.StyleCop.ScopedElement

            Microsoft.Tools.StyleCop.MethodBase

                Microsoft.Tools.StyleCop.Event

 

Members

 

Public Properties

Description

EventDelegate

Gets the name of the delegate that is used for firing the event.

 

Event.EventDelegate

 

Gets the name of the delegate that is used for firing the event.

 

public string EventDelegate { get; }

 

Property Value

 

The name of the delegate that is used for firing the event.

 

 

Indexer

 

Describes a class indexer element.

 

System.Object

    Microsoft.Tools.StyleCop.Element

        Microsoft.Tools.StyleCop.ScopedElement

            Microsoft.Tools.StyleCop.MethodBase

                Microsoft.Tools.StyleCop.Indexer

 

Members

 

This class has no publicly visible members. See the MethodBase class for more information.

 

 

Method

 

Describes a method element.

 

System.Object

    Microsoft.Tools.StyleCop.Element

        Microsoft.Tools.StyleCop.ScopedElement

            Microsoft.Tools.StyleCop.MethodBase

                Microsoft.Tools.StyleCop.Method

 

Members

 

This class has no publicly visible members. See the MethodBase class for more information.

 

 

Property

 

Describes a property element.

 

System.Object

    Microsoft.Tools.StyleCop.Element

        Microsoft.Tools.StyleCop.ScopedElement

            Microsoft.Tools.StyleCop.MethodBase

                Microsoft.Tools.StyleCop.Property

 

Members

 

This class has no publicly visible members. See the MethodBase class for more information.

 

 

MemberVariable

 

Describes a member variable or field within a class.

 

System.Object

    Microsoft.Tools.StyleCop.Element

        Microsoft.Tools.StyleCop.ScopedElement

            Microsoft.Tools.StyleCop.MemberVariable

 

Members

 

Public Properties

Description

Const

Indicates whether the field is marked const.

EqualsCode

Gets the initialization code that appears after the equals sign in the variable declaration.

Readonly

Indicates whether the field is marked readonly.

VariableType

Gets the type of the field.

 

MemberVariable.Const

 

Gets a value indicating whether the field is marked const.

 

public bool Const { get; }

 

Property Value

 

True if the field is const, false if it is not.

 

 

MemberVariable.EqualsCode

 

Gets the initialization code that appears after the equals sign in the variable declaration, if any.

 

public WordList EqualsCode { get; }

 

Property Value

 

The initialization code for the field.

 

 

MemberVariable.Readonly

 

Gets a value indicating whether the field is marked readonly.

 

public bool Readonly { get; }

 

Property Value

 

True if the field is readonly, false if it is not.

 

 

MemberVariable.VariableType

 

Gets the type of the field.

 

public string VariableType { get; }

 

Property Value

 

A string containing the type of the field.

 

 

Namespace

 

Describes a namespace element.

 

System.Object

    Microsoft.Tools.StyleCop.Element

        Microsoft.Tools.StyleCop.Namespace

 

Members

 

This class has no publicly visible members. See the Element class for more information.

 

 

Using

 

Describes a using element.

 

System.Object

    Microsoft.Tools.StyleCop.Element

        Microsoft.Tools.StyleCop.Namespace

 

Members

 

This class has no publicly visible members. See the Element class for more information.

 

 

CodeView

 

Represents a view of the code within an element.

 

System.Object

    Microsoft.Tools.StyleCop.CodeView

 

Members

 

Public Properties

Description

Generated

Indicates whether the code was marked as generated.

LineNumber

The line number that the code begins on.

Words

The list of words that make up the code.

 

CodeView.Generated                                             

 

Gets a value indicating whether the code was marked as generated.

 

public bool Generated { get; }

 

Property Value

 

True if the code was generated, false if not.

 

 

CodeView.LineNumber

 

Gets the line number that the code begins on in the file.

 

public int LineNumber { get; }

 

Property Value

 

The line number that the code begins on.

 

 

CodeView.Words

 

Gets the collection of words that make up the code view.

 

public WordList Words { get; }

 

Property Value

 

The collection of words that make up the code.

 

 

Declaration

 

The declaration class describes an element declaration.

 

System.Object

    Microsoft.Tools.StyleCop.Declaration

 

Members

 

Public Properties

Description

AccessModifier

Indicates whether the element has an access modifier defined.

AccessModifierType                      

The access level of the element.

ElementType

The type of the element.

Name

The name of the element.

Other                   

Indicates whether the element has an unknown word in its declaration.

Static

Indicates whether the element is marked static.

Unsafe

Indicates whether the element is marked unsafe.

Words

The list of words that make up the declaration.

 

 

Declaration.AccessModifier

 

Gets a value indicating whether the item has an access modifier explicitly defined.

 

public bool AccessModifier { get; }

 

Property Value

 

Indicates whether the item has an access modifier defined.

 

 

Declaration.AccessModifierType

 

Gets the element access modifier type.

 

public AccessModifierType AccessModifierType { get; }

 

Property Value

 

An AccessModiferType value indicating the access level of the element.

 

 

Declaration.ElementType

 

Gets the type of the element.

 

public Element.Type ElementType { get; }

 

Property Value

 

An Element.Type value indicating the type of the element.

 

 

Declaration.Name

 

Gets a value indicating whether the item has a name defined.

 

public bool Name { get; }

 

Property Value

 

A boolean value indicating whether the item has a name.

 

 

Declaration.Other

 

Gets a value indicating whether the item has an unknown word in its declaration.

 

public bool Other { get; }

 

Property Value

 

Indicates whether the item has an unknown word in its declaration.

 

 

Declaration.Static

 

Gets a value indicating whether the item is marked static.

 

public bool Static { get; }

 

Property Value

 

Indicates whether the item is marked static.

 

 

Declaration.Unsafe

 

Gets a value indicating whether the item is marked unsafe.

 

public bool Unsafe { get; }

 

Property Value

 

Indicates whether the item is marked unsafe.

 

 

Declaration.Words

 

Gets the collection of words that make up the declaration.

 

public WordList Words { get; }

 

Property Value

 

A WordList object containing the list of words that make up the declaration.

 

 

Parameter

 

Describes one parameter in a method or constructor declaration.

 

System.Object.

    Microsoft.Tools.StyleCop.Parameter

 

Members

 

Public Properties

Description

Attribute

The attribute applied to the parameter.

LineNumber

The line number that the parameter appears on.

Name

The name of the parameter.

Type

The type of the parameter.

 

 

Parameter.Attribute

 

Gets the attribute applied to the parameter, if any. For example, out, ref, params, etc.

 

public string Attribute { get; }

 

Property Value

 

The attribute applied to the parameter.

 

 

Parameter.LineNumber

 

Gets the line number that the parameter appears on in the code file.

 

public int LineNumber { get; }

 

Property Value

 

The line number that the parameter appears on in the code file.

 

 

Parameter.Name

 

Gets the name of the parameter.

 

public string Name { get; }

 

Property Value

 

The name of the parameter.

 

 

Parameter.Type

 

Gets the type of the parameter.

 

public string Type { get; }

 

Property Value

 

The type of the parameter.

 

 

Scope

 

Describes a scope of code within a larger code block.

 

System.Object.

    Microsoft.Tools.StyleCop.Scope

 

Members

 

Public Properties

Description

Children

The children of this scope.

Index

The index of this scope in its parent scope’s child list.

Parameters

The collection of parameters and variables exposed to this scope.

Parent

The parent of this scope object.

Public Methods

Description

GetChild

Gets the child object at the given index.

 

 

Scope.Children

 

Gets the collection of children under this scope. The child list consists of Word and Scope objects.

 

public ICollection Children { get; }

 

Property Value

 

The collection of children under this scope.

 

 

Scope.Index

 

Gets the index of this scope in its parent scope’s child list.

 

public int Index { get; }

 

Property Value

 

The index of this scope in its parent scope’s child list.

 

 

Scope.Parameters

 

Gets the list of parameters and variables visible to this scope. The list consists of Parameter objects.

 

public ICollection Parameters { get; }

 

Property Value

 

The list of parameters visible to this scope.

 

 

Scope.Parent

 

Gets the parent of this scope. The parent will either be another Scope object or an object deriving from ScopedElement.

 

public object Parent { get; }

 

Property Value

 

The parent of this scope.

 

 

Scope.GetChild

 

Gets the child object at the given index.

 

public object GetChild(int index);

 

Parameters

 

index

The index of the child object to retrieve.

 

Return Value

 

Returns the object at the given index. This will either be a Word object or a Scope object.

 

 

 

Word

 

Describes one word in the code.

 

System.Object

    Microsoft.Tools.StyleCop.Word

        Microsoft.Tools.StyleCop.AnonymousParameter

        Microsoft.Tools.StyleCop.BracketWord

        Microsoft.Tools.StyleCop.WhiteSpace

 

Members

 

Public Types

Description

Type

The various possible word types.

Public Properties

Description

BlockType

The block type that the word appears in.

EndLineNumber

The line number in the code file where this word ends.

Generated

Indicates whether the word appears in a block of generated code.

LineNumber

The line number in the code file on which the word appears.

Text

The word text.

WordType

The type of the word.

Public Methods

Description

ToString

Returns the word text.

 

 

Word.Type

 

An enum listing the possible accessor types.

 

Members

 

Values

Description

Add

The keyword add

AddressOf

An address-of symbol: &

Arithmetic

An arithmetic symbol: +, -, *, /, etc.

As

The keyword as

AssemblyTag

An assembly tag.

Assignment

An equals sign symbol: =

Base

The keyword base

Break

The keyword break

Case

The keyword case

Catch

The keyword catch

Checked

The keyword checked

CloseCurlyBracket

A closing curly bracket symbol: }

CloseParenthesis

A closing parenthesis symbol: )

CloseSquareBracket

A closing square bracket symbol: ]

Colon

A colon: :

Comma

A comma: ,

Comment

A comment

Const

The keyword const

Continue

The keyword continue

Decrement

A decrement symbol: --

Default

The keyword default

Dereference

A dereference symbol: *

Do

The keyword do

Else

The keyword else

EndOfLine

An end-of-line character: /r or /n

False

The keyword false

Finally

The keyword finally

Fixed

The keyword fixed

For

The keyword for

Foreach

The keyword foreach

Get

The keyword get

Goto

The keyword goto

Increment

An increment symbol: ++

If

The keyword if

In

The keyword in

Is

The keyword is

Lock

The keyword lock

Logical

A logical symbol: !, ||, |, etc.

Negative

A negative sign symbol: -

New

The keyword new

Null

The keyword null

Number

A number

OtherAssignment

All assignment types other than an equals sign: +=, %=, |=, etc.

OpenCurlyBracket

An opening curly bracket symbol: {

OpenParenthesis

An opening parenthesis symbol: (

OpenSquareBracket

An opening square bracket symbol: [

Other

An unknown word.

Out

The keyword out

Params

The keyword params

Pointer

A pointer symbol: ->

Positive

A positive sign symbol: +

Preprocessor

A preprocessor statement.

QuestionMark

A question mark symbol: ?

Readonly

The keyword readonly

Ref

The keyword ref

Relational

A relational symbol: ==, !=, etc.

Remove

The keyword remove

Return

The keyword return

Semicolon

A semicolon symbol: ;

Set

The keyword set

Sizeof

The keyword sizeof

Stackalloc

The keyword stackalloc

String

A string.

Switch

The keyword switch

This

The keyword this

Throw

The keyword throw

True

The keyword true

Try

The keyword try

Typeof

The keyword typeof

Unchecked

The keyword unchecked

Unsafe

The keyword unsafe

Using

The keyword using

Value

The keyword value

While

The keyword while

WhileDo

The do keyword in a do/while statement

Whitespace

A group of back-to-back whitespace characters consisting of spaces and tabs.

XmlHeader

An Xml header.

Yield

The keyword yield

 

 

Word.BlockType

 

Gets the block type that this word appears in.

 

public CodeBlock.Type BlockType { get; }

 

Property Value

 

The block type that this word appears in.

 

 

Word.EndLineNumber

 

Gets the line number in the code file where this word ends.

 

public int EndLineNumber { get; }

 

Property Value

 

The line number in the code where this word ends.

 

 

Word.Generated

 

Gets a value indicating where the word appears in a block of generated code.

 

public bool Generated { get; }

 

Property Value

 

Indicates whether the word appears in a block of generated code.

 

 

Word.LineNumber

 

Gets the line number in the code file on which the word appears.

 

public int LineNumber { get; }

 

Property Value

 

The line number in the code file on which the word appears.

 

 

Word.Text

 

Gets the text that makes up the word.

 

public string Text { get; }

 

Property Value

 

The text that makes up the word.

 

 

Word.WordType

 

Gets the type of the word.

 

public Word.Type WordType { get; }

 

Property Value

 

The type of the word.

 

 

Word.ToString

 

Returns the word text.

 

public string ToString();

 

 

AnonymousParameter

 

A word that describes a parameter in an anonymous method declaration.

 

System.Object

    Microsoft.Tools.StyleCop.Word

        Microsoft.Tools.StyleCop.AnonymousParameter

 

Members

 

Public Properties

Description

ParameterName

The name of the parameter.

ParameterType

The parameter type.

 

 

AnonymousParameter.ParameterName

 

Gets the name of the parameter.

 

public Word ParameterName { get; }

 

Property Value

 

The name of the parameter.

 

 

AnonymousParameter.ParameterType

 

Gets the type of the parameter.

 

public string ParameterType { get; }

 

Property Value

 

The type of the parameter.

 

 

BracketWord

 

A word that describes a bracket in the code.

 

System.Object

    Microsoft.Tools.StyleCop.Word

        Microsoft.Tools.StyleCop.BracketWord

 

Members

 

Public Types

Description

Type

The various types of brackets.

Public Properties

Description

BracketType

The type of the bracket.

MatchingBracket

The matching bracket for this bracket.

 

 

BracketWord.Type

 

An enum listing the possible bracket types.

 

Members

 

Values

Description

CloseCurlyBracket

A closing curly bracket: }

CloseParenthesis

A closing parenthesis: )

CloseSquareBracket

A closing square bracket: ]

OpenCurlyBracket

An opening curly bracket: {

OpenParenthesis

An opening parenthesis: (

OpenSquareBracket

An opening square bracket: [

 

 

BracketWord.BracketType

 

Gets the type of the bracket.

 

public BracketWord.Type BracketType { get; }

 

Property Value

 

The type of the bracket.

 

 

BracketWord.MatchingBracket

 

Gets the matching bracket for this bracket, or null if a matching bracket could not be found.

 

public BracketWord MatchingBracket { get; }

 

Property Value

 

The matching bracket for this bracket.

 

 

Whitespace

 

A word that describes a group of whitespace characters in the code.

 

System.Object

    Microsoft.Tools.StyleCop.Word

        Microsoft.Tools.StyleCop.Whitespace

 

Members

 

Public Properties

Description

SpaceCount

The number of tab characters in the whitespace.

TabCount

The number of tab characters in the whitespace.

Public Methods

Description

ToString

Returns the whitespace characters as a string.

 

 

Whitespace.SpaceCount

 

Gets the number of space characters in the whitespace.

 

public int SpaceCount { get; }

 

Property Value

 

The number of space characters in the whitespace.

 

 

Whitespace.TabCount

 

Gets the number of tab characters in the whitespace.

 

public int TabCount { get; }

 

Property Value

 

The number of tab characters in the whitespace.

 

 

Whitespace.ToString

 

Returns the whitespace characters as a text string.

 

public string ToString();

 

 

WordList

 

A word that describes a group of whitespace characters in the code.

 

System.Object

System.Collections.IEnumerable

    Microsoft.Tools.StyleCop.WordList

 

Members

 

Public Properties

Description

Collection

Gets the collection of words in the list.

Count

Gets the count of words in the list.

Public Indexers

Description

this

Gets the word at the given index.

Public Methods

Description

GetEnumerator

Gets an enumerator to walk through the words in the collection.

GetWord

Gets the word at the given index.

GetWordEfficient

Gets the word at the given index without doing any error checking.

GetRange

Gets a sub-collection of words from the list.

IndexOf

Determines the index of the given word in the collection.

LastIndexOf

Determines the index of the last matching word in the collection.

 

 

WordList.Collection

 

Gets the collection of words in the list.

 

public ICollection Collection { get; }

 

Property Value

 

The collection of words in the list.

 

 

WordList.Count

 

Gets the number of words in the list.

 

public int Count { get; }

 

Property Value

 

The number of words in the list.

 

 

WordList.this

 

Gets the word at the given index.

 

public Word this[int index];

 

Parameters

 

index

The index of the word to retrieve.

 

Return Value

 

Returns the word at the given index or null if the index is invalid

 

 

WordList.GetEnumerator

 

Gets an enumerator to walk through the words in the collection.

 

public IEnumerator GetEnumerator();

 

Return Value

 

Returns an enumerator to walk through the words in the collection.

 

 

WordList.GetWord

 

Gets the word at the given index.

 

public Word GetWord(int index);

 

Parameters

 

index

The index of the word to retrieve.

 

Return Value

 

Returns the word at the given index or null if the index is invalid

 

 

WordList.GetWordEfficient

 

Gets the word at the given index without performing any error checking. This method should only be used when it is guaranteed that the index will not exceed the boundaries of the collection. Otherwise, use the GetWord method.

 

public Word GetWordEfficient(int index);

 

Parameters

 

index

The index of the word to retrieve.

 

Return Value

 

Returns the word at the given index or null if the index is invalid

 

 

WordList.GetRange

 

Gets the collection of words specified by the given values.

 

public WordList GetRange(int index, int count);

 

Parameters

 

index

The index of the first word in the collection to return.

 

count

The number of words to return.

 

Return Value

 

Returns the collection of words matching the given parameters.

 

 

WordList.IndexOf

 

Gets the index of the first word in the collection that matches the given parameters.

 

public int IndexOf(Word.Type type);

 

Parameters

 

type

The type of word to search for.

 

Return Value

 

Returns the index of the first word in the collection that matches the given parameters or -1 if a matching word was not found.

 

 

WordList.IndexOf

 

Gets the index of the first word in the collection that matches the given parameters.

 

public int IndexOf(Word.Type type, string text);  

 

Parameters

 

type

The type of word to search for.

 

text

The text of the word to search for.

 

Return Value

 

Returns the index of the first word in the collection that matches the given parameters or -1 if a matching word was not found.

 

 

WordList.IndexOf

 

Gets the index of the first word in the collection that matches the given parameters.

 

public int IndexOf(Word.Type type, string text, int start);     

 

Parameters

 

type

The type of word to search for.

 

text

The text of the word to search for.

 

start

The index in the collection at which to being searching.

 

Return Value

 

Returns the index of the first word in the collection that matches the given parameters or -1 if a matching word was not found.

 

 

WordList.IndexOf

 

Gets the index of the first word in the collection that matches the given parameters.

 

public int IndexOf(Word.Type type, int start);    

 

Parameters

 

type

The type of word to search for.

 

start

The index in the collection at which to being searching.

 

Return Value

 

Returns the index of the first word in the collection that matches the given parameters or -1 if a matching word was not found.

 

 

WordList.IndexOf

 

Gets the index of the first word in the collection that matches the given parameters.

 

public int IndexOf(Word.Type type, string text, int start, int count); 

 

Parameters

 

type

The type of word to search for.

 

text

The text of the word to search for.

 

start

The index in the collection at which to being searching.

 

count

The number of words to search before quitting.

 

Return Value

 

Returns the index of the first word in the collection that matches the given parameters or -1 if a matching word was not found.

 

 

WordList.LastIndexOf

 

Gets the index of the last word in the collection that matches the given parameters.

 

public int LastIndexOf(Word.Type type);

 

Parameters

 

type

The type of word to search for.

 

Return Value

 

Returns the index of the last word in the collection that matches the given parameters or -1 if a matching word was not found.

 

 

WordList.LastIndexOf

 

Gets the index of the last word in the collection that matches the given parameters.

 

public int LastIndexOf(Word.Type type, string text);

 

Parameters

 

type

The type of word to search for.

 

text

The text of the word to search for.

 

Return Value

 

Returns the index of the last word in the collection that matches the given parameters or -1 if a matching word was not found.

 

 

WordList.LastIndexOf

 

Gets the index of the last word in the collection that matches the given parameters.

 

public int LastIndexOf(Word.Type type, string text, int start);

 

Parameters

 

type

The type of word to search for.

 

text

The text of the word to search for.

 

start

The index in the collection at which to being searching.

 

Return Value

 

Returns the index of the last word in the collection that matches the given parameters or -1 if a matching word was not found.

 

 

WordList.LastIndexOf

 

Gets the index of the last word in the collection that matches the given parameters.

 

public int LastIndexOf(Word.Type type, int start);

 

Parameters

 

type

The type of word to search for.

 

start

The index in the collection at which to being searching.

 

Return Value

 

Returns the index of the last word in the collection that matches the given parameters or -1 if a matching word was not found.

 

 

WordList.LastIndexOf

 

Gets the index of the last word in the collection that matches the given parameters.

 

public int LastIndexOf(Word.Type type, string text, int start, int count);

 

Parameters

 

type

The type of word to search for.

 

text

The text of the word to search for.

 

start

The index in the collection at which to being searching.

 

count

The number of words to search before quitting.

 

Return Value

 

Returns the index of the last word in the collection that matches the given parameters or -1 if a matching word was not found.

 

 

CodeBlock

 

Describes a block of code in the file.

 

System.Object

    Microsoft.Tools.StyleCop.CodeBlock

 

Members

 

Public Types

Description

Type

The various types of code blocks

 

 

CodeBlock.Type

 

An enum listing the possible code block types.

 

Members

 

Values

Description

AssemblyTag

An assembly tag

Code

Regular code

DoubleQuote

A double-quoted string

MultiLineComment

A comment that begins and ends with /* and */

Preprocessor

A preprocessor tag.

SingleLineComment

A comment beginning with //

SingleQuote

A single-quoted string

UnsafeCode

Code marked unsafe code

XmlHeader

An Xml header that appears above a code element

 

 

CodeDocument

 

A document object that models a code file and can be used to edit the contents of the file.

 

System.Object

    Microsoft.Tools.StyleCop.CodeDocument

 

Members

 

Public Methods

Description

UpdateCode

Replaces a portion of code in the document with the new text provided.

 

 

CodeDocument.UpdateCode

 

Replaces a portion of code in the document with the new text provided.

 

public bool UpdateCode(int line, int offset, int count, string text);

 

Parameters

 

line

The line in the file where the text replacement will occur.

 

offset

The offset from the beginning of the line where the replacement will begin.

 

count

The number of characters to replace.

 

text

The text to replace the existing code with.

 

Return Value

 

Returns true if the text was replaced successfully.

 

 

IPropertyControlPage

 

Interface which must be implemented by a page that appears on the StyleCop settings dialog. The page settings should be loaded and saved using the GetProjectProperty and SaveProjectProperty methods on the Host property of the current StyleCopCore object.

 

Members

 

Public Properties

Description

Dirty

Indicates whether the page is dirty.

TabName

The text that will appear on the page’s tab.

Public Methods

Description

Activate

Called whenever the page is shown or hidden.

Apply

Saves the data on the page.

Initialize

Initialize the page.

 

 

IPropertyControlPage.Dirty

 

Gets a value indicating whether the page is dirty.

 

public bool Dirty { get; }

 

Property Value

 

Indicates whether the page is dirty.

 

Remarks

 

Whenever the dirty state of a page changes, the page must call the IPropertyControlHost.DirtyChanged method to cause the property page control to enable or disable the Apply button appropriately.

 

IPropertyControlPage.TabName

 

Gets the text that will appear on the page’s tab.

 

public string TabName { get; }

 

Property Value

 

Gets the page’s tab name.

 

 

IPropertyControlPage.Activate

 

Called when the page is shown or hidden.

 

public void Activate(bool activated);

 

Parameters

 

activated

Indicates whether the control is being activated or deactivated.

 

 

IPropertyControlPage.Apply

 

Causes the page to save its dirty data.

 

public void Apply();

 

 

IPropertyControlPage.Initialize

 

Initializes the page. This is called when the page is first loaded.

 

public void Initialize(IPropertyControl propertyControl, object context);

 

Parameters

 

propertyControl

Interface into the property page control that is hosting this page.

 

context

Provides an array of objects. The first item in the array is a reference to the StyleCopCore object. The second item in the array is a string containing the ID of the project being edited.

 

 

IPropertyControl

 

Interface into the property page control that hosts the StyleCop settings pages.

 

Members

 

Properties

Description

Pages

Gets the list of pages currently loaded into the control.

ActivePage

Gets the currently active page.

Methods

Description

DirtyChanged

Causes the property page control to update the status of the Apply button.

 

 

IPropertyControl.Pages

 

Gets the list of pages currently loaded into the control.

 

public IPropertyControlPage[] Pages { get; }

 

Property Value

 

The list of pages currently loaded into the control.

 

 

IPropertyControl.ActivePage

 

Gets the currently active page on the control.

 

public IPropertyControlPage ActivePage { get; }

 

Property Value

 

The currently active page on the control.

 

 

IPropertyControl.DirtyChanged

 

Causes the property page control to update the enabled status of the Apply button based on whether any of the pages is currently dirty.

 

public void DirtyChanged();

 

 

StyleCopCore

 

The main StyleCopCore engine object.

 

System.Object

    Microsoft.Tools.StyleCop.StyleCopCore

 

Members

 

Public Properties

Description

Cancel

Indicates whether the current analyze run should cancel.

Addins

Gets the collection of add-ins currently loaded into the tool.

Host

An interface into the object hosting StyleCopCore.

 

 

StyleCopCore.Cancel

 

Gets or sets a value indicating whether the currently analyze run should be cancelled. Add-ins should check this value periodically to determine whether to cancel their currently running analyze operation.

 

public bool Cancel { get; set; }

 

Property Value

 

Indicates whether the cancel the current analyze run.

 

 

StyleCopCore.Addins

 

Gets the collection of add-ins currently loaded into the tool.

 

public ICollection Addins { get; }

 

Property Value

 

The collection of StyleCopAddin objects currently loaded into the tool.

 

 

StyleCopCore.Host

 

Gets the interface into the object that is hosting the StyleCopCore object.

 

public IStyleCopHost Host { get; }

 

Property Value

 

The interface into the object that is hosting the StyleCopCore object.

 

 

IStyleCopHost

 

An interface into the object that hosts StyleCopCore.

 

Members

 

Methods

Description

GetProjectProperty

Gets the given property value from the given project.

SaveProjectProperty

Sets the given property value in the given project.

 

 

IStyleCopHost.GetProjectProperty

 

Gets the value of the given property from the specified project.

 

public string GetProjectProperty(string projectId, string name);

 

Parameters

 

projectId

The ID of the project to retrieve the property value from.

 

name

The name of the property to retrieve from the project.

 

 

IStyleCopHost.SaveProjectProperty

 

Saves the value of the given property in the specified project.

 

public void SaveProjectProperty(string projectId, string name, string property);

 

Parameters

 

projectId

The ID of the project to save the property value in.

 

name

The name of the property to save in the project.

 

property

The value to save into the property.

 

 

AccessModifierType

 

Enum that describes the various access levels for C# elements.

 

Members

 

Values

Description

Internal

An internal element that is visible to everyone within the same assembly, but no one outside of the assembly.

Private

A private element that is only visible to other class members.

Protected

A protected element that is only visible to other class members and members of a class inheriting the class that this element belongs to.

ProtectedAndInternal

A protected element that is inside of an internal element.

ProtectedInternal

An element that is marked protected internal.

Public

A public element that is visible to everyone.

 

 

 

 

Samples

 

The following sample code implements a StyleCop add-in that checks to make sure all member variables begin with lower-case letters, and all other elements begin with upper-case elements, including const or readonly member variables.

 

 

using System;

using System.Collections;

using System.Globalization;

using Microsoft.StatusMonitor.StyleCop;

 

namespace NameChecker

{

       /// <summary>

       /// The list of violation types that can be found by this add-in module

       /// </summary>

       public enum ViolationType : int

       {

              WordStartsWithUpper = 0,

              WordStartsWithLower

       }

 

 

       /// <summary>

       /// Checks the case of the first letter of element names

       /// </summary>

       public class NameCase : StyleCopAddin

       {

              /// <summary>

              /// Constructor

              /// </summary>

              public NameCase() :

base("5ebc1cb7-6f5c-484a-b208-fd4c44733acb", "Name case", ViolationList.ItemsArray)

              {

              }

 

              /// <summary>

              /// Checks the elements within the given file

              /// </summary>

              /// <param name="file">The file to check</param>

              public override void ProcessFile(CodeFile file)

              {

                     this.ProcessElement(file.Contents);

              }

 

              /// <summary>

              /// Processes one element and its children

              /// </summary>

              /// <param name="element">The element to process</param>

              private void ProcessElement(Element element)

              {

                     switch (element.Type)

                     {

                           case Element.Type.Namespace:

                           case Element.Type.Class:

                           case Element.Type.Enum:

                           case Element.Type.Struct:

                           case Element.Type.Delegate:

                           case Element.Type.Event:

                           case Element.Type.Property:

                           case Element.Type.Method:

                                  this.CheckCase(element, true);

                                   break;

                           case Element.Type.MemberVariable:

                                  this.CheckCase(element, Common.IsConst(element));

                                  break;

                           default:

                                  break;

                     }

 

                     foreach (Element child in element.Children)

                     {

                           this.ProcessElement(child);

                     }

              }

 

              /// <summary>

              /// Checks the case of the first character in the given word

              /// </summary>

              /// <param name="element">The element that the word appears in</param>

              /// <param name="upper">True if the character should be upper, false if it should be lower</param>

              private void CheckCase(Element element, bool upper)

              {

                     string first = element.RealName.Substring(0, 1);

                     if (upper)

                     {

                           if (first != first.ToUpper())

                           {

                                  base.AddViolation(element, element.LineNumber, ViolationType.WordStartsWithLower, element.RealName);

                           }

                     }

                     else

                     {

                           if (first != first.ToLower())

                           {

                                  base.AddViolation(element, element.LineNumber, ViolationType.WordStartsWithUpper, element.RealName);

                           }

                     }

              }

       }

 

       /// <summary>

       /// The violation data

       /// </summary>

       internal class ViolationList

       {

              /// <summary>

              /// An array of all the violations

              /// </summary>

              private static readonly ViolationListItem[] Items =

              {

                     new ViolationListItem((int)ViolationType.WordStartsWithUpper, "Element must start with a lower-case letter: {0}"),

                     new ViolationListItem((int)ViolationType.WordStartsWithLower, "Element must start with an upper-case letter: {0}")

              };

 

              /// <summary>

              /// Gets the violations array

              /// </summary>

              public static ViolationListItem[] ItemsArray

              {

                     get { return Items; }

              }

       }

 

}