Nemerle.VisualStudio.Project.NemerleProjectNode.AddComponent C# (CSharp) Method

AddComponent() public method

Add Components to the Project. Used by the environment to add components specified by the user in the Component Selector dialog to the specified project
public AddComponent ( VSADDCOMPOPERATION dwAddCompOperation, uint cComponents, System rgpcsdComponents, System hwndDialog, VSADDCOMPRESULT pResult ) : int
dwAddCompOperation VSADDCOMPOPERATION The component operation to be performed.
cComponents uint Number of components to be added
rgpcsdComponents System array of component selector data
hwndDialog System Handle to the component picker dialog
pResult VSADDCOMPRESULT Result to be returned to the caller
return int
        public override int AddComponent(VSADDCOMPOPERATION dwAddCompOperation, uint cComponents, System.IntPtr[] rgpcsdComponents, System.IntPtr hwndDialog, VSADDCOMPRESULT[] pResult)
        {
            //initalize the out parameter
            pResult[0] = VSADDCOMPRESULT.ADDCOMPRESULT_Success;

            var selectedNodes = GetSelectedNodes();

            IReferenceContainer references = selectedNodes.Count == 1 && selectedNodes[0] is NemerleMacroReferenceContainerNode
                                                                                ? GetMacroReferenceContainer()
                                                                                : GetReferenceContainer();

            if (null == references)
            {
                // This project does not support references or the reference container was not created.
                // In both cases this operation is not supported.
                return VSConstants.E_NOTIMPL;
            }
            for (int cCount = 0; cCount < cComponents; cCount++)
            {
                VSCOMPONENTSELECTORDATA selectorData = new VSCOMPONENTSELECTORDATA();
                IntPtr ptr = rgpcsdComponents[cCount];
                selectorData = (VSCOMPONENTSELECTORDATA)Marshal.PtrToStructure(ptr, typeof(VSCOMPONENTSELECTORDATA));
                if (null == references.AddReferenceFromSelectorData(selectorData))
                {
                    //Skip further proccessing since a reference has to be added
                    pResult[0] = VSADDCOMPRESULT.ADDCOMPRESULT_Failure;
                    return VSConstants.S_OK;
                }
            }
            return VSConstants.S_OK;
        }