Nested Type Usage Guidelines

A nested type is a type defined within the scope of another type. Nested types are very useful for encapsulating implementation details of a type, such as an enumerator over a collection, because they can have access to private state. Public nested types should be used rarely. Use them only in situations where both of the following are true The nested type logically belongs to the containing type. The nested type is not used often, or at least not directly. The following examples illustrates...

Xnu Coding Guidelines

TreeView treeViewl new TreeView void treeView1_BeforeLabelEdit object source, Note that in this case, no error is generated to the user. The label is read-only. The CancelEvent is not appropriate in cases where the developer would cancel the operation and return an exception. In these cases, the event does not derive from CancelEvent. You should raise an exception inside of the event handler in order to cancel. For example, the user might want to write validation logic in an edit control as...

Threading Design Guidelines

The following rules outline the design guidelines for implementing threading 1. Avoid providing static methods that alter static state. In common server scenarios, static state is shared across requests, which means multiple threads can execute that code at the same time. This opens up the possibility for threading bugs. Consider using a design pattern that encapsulates data into instances that are not shared across requests. 2. Static state must be thread safe. 3. Instance state does not need...

Customizing a Dispose Method Name

Occasionally a domain-specific name is more appropriate than Dispose. For example, a file encapsulation might want to use the method name Close. In this case, implement Dispose privately and create a public Close method that calls Dispose. The following code example illustrates this pattern. You can replace Close with a method name appropriate to your domain. ' Do not make this method overridable. ' A derived class should not be allowed ' to override this method. Public Sub Close ' Call the...

Guidelines for Exposing Functionality to COM

The common language runtime provides rich support for interoperating with COM components. A COM component can be used from within a managed type and a managed instance can be used by a COM component. This support is the key to moving unmanaged code to managed code one piece at a time however, it does present some issues for class library designers. In order to fully expose a managed type to COM clients, the type must expose functionality in a way that is supported by COM and abides by the COM...