Ejemplo n.º 1
0
        /// <summary>
        /// Gets the files of files that could have a reference to the <paramref name="member"/>
        /// int the <paramref name="ownerClass"/>.
        /// </summary>
        static List <ProjectItem> GetPossibleFiles(IClass ownerClass, IEntity member)
        {
            List <ProjectItem> resultList = new List <ProjectItem>();

            if (ProjectService.OpenSolution == null)
            {
                foreach (IViewContent vc in WorkbenchSingleton.Workbench.ViewContentCollection)
                {
                    string name = vc.PrimaryFileName;
                    if (!string.IsNullOrEmpty(name) && ParserService.CreateParser(name) != null)
                    {
                        FileProjectItem tempItem = new FileProjectItem(null, ItemType.Compile);
                        tempItem.Include = name;
                        resultList.Add(tempItem);
                    }
                }
                return(resultList);
            }

            if (member == null)
            {
                // get files possibly referencing ownerClass
                while (ownerClass.DeclaringType != null)
                {
                    // for nested classes, treat class as member
                    member     = ownerClass;
                    ownerClass = ownerClass.DeclaringType;
                }
                if (member == null)
                {
                    GetPossibleFilesInternal(resultList, ownerClass.ProjectContent, ownerClass.IsInternal);
                    return(resultList);
                }
            }
            if (member.IsPrivate)
            {
                List <string> fileNames = GetFileNames(ownerClass);
                foreach (string fileName in fileNames)
                {
                    ProjectItem item = FindItem(fileName);
                    if (item != null)
                    {
                        resultList.Add(item);
                    }
                }
                return(resultList);
            }

            if (member.IsProtected)
            {
                // TODO: Optimize when member is protected
            }

            GetPossibleFilesInternal(resultList, ownerClass.ProjectContent, ownerClass.IsInternal || member.IsInternal && !member.IsProtected);
            return(resultList);
        }
        public static IParser GetParser(string fileName)
        {
            IParser p;

            if (presetParsersUnitTestOnly == null)
            {
                p = ParserService.CreateParser(fileName);
            }
            else
            {
                presetParsersUnitTestOnly.TryGetValue(System.IO.Path.GetExtension(fileName), out p);
            }
            return(p);
        }
Ejemplo n.º 3
0
        static void GenerateWebProxy(string proxyNamespace, string fileName, ServiceDescriptionCollection serviceDescriptions, XmlSchemas schemas)
        {
            ServiceDescriptionImporter importer = new ServiceDescriptionImporter();

            foreach (ServiceDescription description in serviceDescriptions)
            {
                importer.AddServiceDescription(description, null, null);
            }

            foreach (XmlSchema schema in schemas)
            {
                importer.Schemas.Add(schema);
            }

            CodeNamespace   codeNamespace = new CodeNamespace(proxyNamespace);
            CodeCompileUnit codeUnit      = new CodeCompileUnit();

            codeUnit.Namespaces.Add(codeNamespace);
            ServiceDescriptionImportWarnings warnings = importer.Import(codeNamespace, codeUnit);

            CodeDomProvider provider = null;

            IParser parser = ParserService.CreateParser(fileName);

            if (parser != null)
            {
                provider = parser.Language.CodeDomProvider;
            }

            if (provider != null)
            {
                StreamWriter         sw      = new StreamWriter(fileName);
                CodeGeneratorOptions options = new CodeGeneratorOptions();
                options.BracingStyle = "C";
                provider.GenerateCodeFromCompileUnit(codeUnit, sw, options);
                sw.Close();
            }
        }