IVsaItems.CreateItem Method

Creates a new instance of one of the IVsaItem types, as defined in the VsaItemType enumeration.

public IVsaItem CreateItem( 
   string name,
   VsaItemType itemType,
   VsaItemFlag itemFlag
);

Returns a reference to the IVsaItem object created.

name

The name to associate with the new item.

In cases where the item is a reference item type, the name parameter must be exactly the same as the name of the referenced assembly, as set with the IVsaReferenceItem.AssemblyName property. In JScript, however, if you do not specify an AssemblyName, JScript will use the ItemName as the name of the assembly.

itemType

The type of item created, as defined in the VsaItemType enumeration.

itemFlag

The optional flag to specify the initial content of a Code item.

The newly created object has its IVsaItem.Name property set to the value of the name parameter and is added to the IVsaItems collection with the name parameter used as the index into the collection.

Once created, you can retrieve the item from the collection using calling the Item(string) property passing in the name value, provided the Name property has not been updated.

Use the itemType parameter to set the newly created item's type. The item type is determined by values of the VsaItemType Enumeration. The following table shows the item types and their corresponding derived classes.

VsaItemType

Derived Class

Reference

IVsaReferenceItem

AppGlobal

IVsaGlobalItem

Code

IVsaCodeItem

The itemFlag parameter controls the initial contents of the item, as defined by the VsaItemFlag enumeration when the VsaItemType enumeration is set to Code. For item types other than Code, you must specify None. The following table shows the VsaItemFlag values and the associated initial code for each.

VsaItemFlag

Initial Code

None

None

Class

An empty class

Module

An empty module

JScript .NET does not support the VsaItemFlag.Class flag, although users can create their own classes by adding a class declaration to their code. JScript .NET treats the Module and None flags as equivalent, allowing the user to write any code (classes, global methods, and so on) inside the item.

Upon creating an item, the IVsaEngine.IsDirty property returns true until the item is saved.

The following table shows the exceptions that the CreateItem method can throw.

Exception Type

Condition

EngineClosed

The IVsaEngine.Close method has been called and the engine is closed.

EngineNotInitialized

The engine has not been initialized.

EngineRunning

The engine is running.

ItemNameInUse

The specified name parameter is already in use in the current IVsaItems collection.

ItemNameInvalid

The name of the item is not valid.

ItemTypeNotSupported

The itemType parameter specified is not supported

ItemFlagNotSupported

The type of the itemFlag parameter specified is not supported, or is invalid for the itemType parameter.

Show: