Add-EnumMember? how to do that?

Jul 26, 2011 at 2:33 PM

how to add member to enum?

I try to use add-classmember cmdlet but it raised error...how can I resolve this? any work-around?

Jul 27, 2011 at 11:27 AM

I found a workaround (it is based on file type

NOTE : it is ok for enum but not checked for other types.

 

function Get-EnumItem(
	[string]$fileName,
	[string]$projectName,
	[string]$enumName)
	{
		$file = Get-ProjectItem -project:$projectName -path:$fileName
		if($file)
		{
			if($file.filecodemodel.codeelements.count -gt 0)
			{	
				foreach ($i in $file.filecodemodel.codeelements) {
					$z=findItem -obj:$i -typeId:10 -typeName:$enumName
					if($z) {
						return $z
					}
				}
			}
		}
		else
		{
			Write-Host "$fileName not found in project:$projectName!!..." -ForegroundColor:Red
		}
	}
	
function findItem([Object]$obj,[int]$typeId,[string]$typeName)# typeId comes from EnvDTE.vsCMElement enum
{
	if ($obj){
		if($obj.kind -eq $typeId -and $enumName -eq $obj.name)
		{
			return $obj;
		}
		if($obj.members.count -gt 0)
		{
			foreach($i in $obj.members)
			{
				if($i.kind -ne 0)
				{
					$z= findItem -obj:$i -typeId:$typeId -typeName:$typeName
					if($z)
					{
						return $z
					}
				}
			}
		}
		
	}
}

 

 

NOTE : "kind" property is one of the following (10 is enumType which is used in the above function):

   public enum vsCMElement
    {
        // Summary:
        //     An element not in the list.
        vsCMElementOther = 0,
        //
        // Summary:
        //     A class element.
        vsCMElementClass = 1,
        //
        // Summary:
        //     A function element.
        vsCMElementFunction = 2,
        //
        // Summary:
        //     A variable element.
        vsCMElementVariable = 3,
        //
        // Summary:
        //     A property element.
        vsCMElementProperty = 4,
        //
        // Summary:
        //     A namespace element.
        vsCMElementNamespace = 5,
        //
        // Summary:
        //     A parameter element.
        vsCMElementParameter = 6,
        //
        // Summary:
        //     An attribute element.
        vsCMElementAttribute = 7,
        //
        // Summary:
        //     An interface element.
        vsCMElementInterface = 8,
        //
        // Summary:
        //     A delegate element.
        vsCMElementDelegate = 9,
        //
        // Summary:
        //     An enumerator element.
        vsCMElementEnum = 10,
        //
        // Summary:
        //     A structure element.
        vsCMElementStruct = 11,
        //
        // Summary:
        //     A union element.
        vsCMElementUnion = 12,
        //
        // Summary:
        //     A local declaration statement element.
        vsCMElementLocalDeclStmt = 13,
        //
        // Summary:
        //     A function invoke statement element.
        vsCMElementFunctionInvokeStmt = 14,
        //
        // Summary:
        //     A property set statement element.
        vsCMElementPropertySetStmt = 15,
        //
        // Summary:
        //     An assignment statement element.
        vsCMElementAssignmentStmt = 16,
        //
        // Summary:
        //     An inherits statement element.
        vsCMElementInheritsStmt = 17,
        //
        // Summary:
        //     An implements statement element.
        vsCMElementImplementsStmt = 18,
        //
        // Summary:
        //     An option statement element.
        vsCMElementOptionStmt = 19,
        //
        // Summary:
        //     A VB attributes statement element.
        vsCMElementVBAttributeStmt = 20,
        //
        // Summary:
        //     A VB attribute group element.
        vsCMElementVBAttributeGroup = 21,
        //
        // Summary:
        //     An events declaration element.
        vsCMElementEventsDeclaration = 22,
        //
        // Summary:
        //     A user-defined type declaration element.
        vsCMElementUDTDecl = 23,
        //
        // Summary:
        //     A declare declaration element.
        vsCMElementDeclareDecl = 24,
        //
        // Summary:
        //     A define statement element.
        vsCMElementDefineStmt = 25,
        //
        // Summary:
        //     A type definition element.
        vsCMElementTypeDef = 26,
        //
        // Summary:
        //     An include statement element.
        vsCMElementIncludeStmt = 27,
        //
        // Summary:
        //     A using statement element.
        vsCMElementUsingStmt = 28,
        //
        // Summary:
        //     A macro element.
        vsCMElementMacro = 29,
        //
        // Summary:
        //     A map element.
        vsCMElementMap = 30,
        //
        // Summary:
        //     An IDL import element.
        vsCMElementIDLImport = 31,
        //
        // Summary:
        //     An IDL import library element.
        vsCMElementIDLImportLib = 32,
        //
        // Summary:
        //     An IDL co-class element.
        vsCMElementIDLCoClass = 33,
        //
        // Summary:
        //     An IDL library element.
        vsCMElementIDLLibrary = 34,
        //
        // Summary:
        //     An import statement element.
        vsCMElementImportStmt = 35,
        //
        // Summary:
        //     A map entry element.
        vsCMElementMapEntry = 36,
        //
        // Summary:
        //     A VC base element.
        vsCMElementVCBase = 37,
        //
        // Summary:
        //     An event element.
        vsCMElementEvent = 38,
        //
        // Summary:
        //     A module element.
        vsCMElementModule = 39,
    }