Пример #1
0
        ///-------------------------------------------------------------------------------------------------------------
        /// <summary>
        ///
        /// </summary>
        ///-------------------------------------------------------------------------------------------------------------
        void IVsCodeBehindCodeGenerator.BeginGenerate(string document, string codeBehindFile, string className_Full, bool create)
        {
            DisposeGenerateState();

            _itemCode       = VsHierarchyItem.CreateFromMoniker(codeBehindFile, _hierarchy);
            _itemDesigner   = GetDesignerItem(_itemCode, false);
            _create         = create;
            _className_Full = className_Full;

            if (_itemCode != null)
            {
                // Get the CodeDomProvider for the language (MergedCodeDomProvider C#/VB)
                _codeDomProvider = CreateCodeDomProvider(_itemCode.VsItemID);

                if (_codeDomProvider != null)
                {
                    // Get the field names so we can preserve location and access
                    bool caseSensitive = IsCaseSensitive(_codeDomProvider);

                    _codeFields     = GetFieldNames(_itemCode, _className_Full, caseSensitive, false, 30);
                    _designerFields = GetFieldNames(_itemDesigner, _className_Full, caseSensitive, false, 0);

                    // Generate the class
                    string     designerContents = _itemDesigner.GetDocumentText();
                    TextReader reader           = new StringReader(designerContents);
                    _ccu = _codeDomProvider.Parse(reader);
                    GenerateClass();
                }
            }
        }
Пример #2
0
        ///-------------------------------------------------------------------------------------------------------------
        /// <summary>
        ///
        /// </summary>
        ///-------------------------------------------------------------------------------------------------------------
        bool IVsCodeBehindCodeGenerator.IsGenerateAllowed(string document, string codeBehindFile, bool create)
        {
            VsHierarchyItem itemCode     = VsHierarchyItem.CreateFromMoniker(codeBehindFile, _hierarchy);
            VsHierarchyItem itemDesigner = GetDesignerItem(itemCode, false);

            if ((itemDesigner != null && itemDesigner.IsBuildActionCompile()) ||
                (itemDesigner == null && create))
            {
                return(true);
            }

            return(false);
        }
Пример #3
0
        ///-------------------------------------------------------------------------------------------------------------
        /// <summary>
        ///	 Gets a VshierarchyItem for the designer file if possible.
        ///	 Will create new file if specified and not existing.
        /// </summary>
        ///-------------------------------------------------------------------------------------------------------------
        public /*protected, but public for FSharp.Project.dll*/ virtual VsHierarchyItem GetDesignerItem(VsHierarchyItem itemCode, bool create)
        {
            VsHierarchyItem itemDesigner = null;

            if (itemCode != null)
            {
                // Calculate codebehind and designer file paths
                string codeBehindFile = itemCode.FullPath();
                string designerFile   = null;
                if (_isPartialClassDisabled)
                {
                    designerFile = codeBehindFile;
                }
                else if (!string.IsNullOrEmpty(codeBehindFile))
                {
                    designerFile = codeBehindFile.Insert(codeBehindFile.LastIndexOf("."), ".designer");
                }

                // Try to locate existing designer file
                if (!string.IsNullOrEmpty(designerFile))
                {
                    itemDesigner = VsHierarchyItem.CreateFromMoniker(designerFile, _hierarchy);
                    if (itemDesigner != null)
                    {
                        return(itemDesigner);
                    }
                }

                // Create empty designer file if requested
                if (create && !string.IsNullOrEmpty(designerFile))
                {
                    ProjectItem projectItemCode = itemCode.ProjectItem();
                    if (projectItemCode != null)
                    {
                        ProjectItems projectItems = projectItemCode.Collection;
                        if (projectItems != null)
                        {
                            try
                            {
                                using (StreamWriter sw = File.CreateText(designerFile))
                                {
                                    sw.WriteLine(" ");
                                }

                                projectItems.AddFromFileCopy(designerFile);
                            }
                            catch
                            {
                            }

                            itemDesigner = VsHierarchyItem.CreateFromMoniker(designerFile, _hierarchy);
                            if (itemDesigner != null)
                            {
                                return(itemDesigner);
                            }
                        }
                    }
                }
            }

            return(itemDesigner);
        }