Пример #1
0
        private static async Task <int> ListSymbolsAsync(ListSymbolsCommandLineOptions options)
        {
            if (!options.TryGetProjectFilter(out ProjectFilter projectFilter))
            {
                return(1);
            }

            if (!TryParseOptionValueAsEnum(options.Depth, ParameterNames.Depth, out DocumentationDepth depth, DocumentationDepth.Member))
            {
                return(1);
            }

            if (!TryParseOptionValueAsEnumFlags(options.WrapList, ParameterNames.WrapList, out WrapListOptions wrapListOptions))
            {
                return(1);
            }

            if (!TryParseMetadataNames(options.IgnoredAttributes, out ImmutableArray <MetadataName> ignoredAttributes))
            {
                return(1);
            }

            if (!TryParseMetadataNames(options.IgnoredSymbols, out ImmutableArray <MetadataName> ignoredSymbols))
            {
                return(1);
            }

            if (!TryParseOptionValueAsEnumFlags(options.IgnoredParts, ParameterNames.IgnoredParts, out SymbolDefinitionPartFilter ignoredParts))
            {
                return(1);
            }

            if (!TryParseOptionValueAsEnum(options.Layout, ParameterNames.Layout, out SymbolDefinitionListLayout layout, SymbolDefinitionListLayout.NamespaceList))
            {
                return(1);
            }

            if (!TryParseOptionValueAsEnumFlags(options.Visibility, ParameterNames.Visibility, out VisibilityFilter visibilityFilter, SymbolFilterOptions.Default.Visibility))
            {
                return(1);
            }

            ImmutableArray <SymbolFilterRule> rules = (ignoredSymbols.Any())
                ? ImmutableArray.Create <SymbolFilterRule>(new IgnoredNameSymbolFilterRule(ignoredSymbols))
                : ImmutableArray <SymbolFilterRule> .Empty;

            ImmutableArray <AttributeFilterRule> attributeRules = ImmutableArray.Create <AttributeFilterRule>(
                IgnoredAttributeNameFilterRule.Default,
                new IgnoredAttributeNameFilterRule(ignoredAttributes));

            var symbolFilterOptions = new SymbolFilterOptions(
                visibility: visibilityFilter,
                symbolGroups: GetSymbolGroupFilter(),
                rules: rules,
                attributeRules: attributeRules);

            var command = new ListSymbolsCommand(
                options: options,
                symbolFilterOptions: symbolFilterOptions,
                wrapListOptions: wrapListOptions,
                layout: layout,
                ignoredParts: ignoredParts,
                projectFilter: projectFilter);

            CommandResult result = await command.ExecuteAsync(options.Path, options.MSBuildPath, options.Properties);

            return((result == CommandResult.Success) ? 0 : 1);

            SymbolGroupFilter GetSymbolGroupFilter()
            {
                switch (depth)
                {
                case DocumentationDepth.Member:
                    return(SymbolGroupFilter.TypeOrMember);

                case DocumentationDepth.Type:
                    return(SymbolGroupFilter.Type);

                case DocumentationDepth.Namespace:
                    return(SymbolGroupFilter.None);

                default:
                    throw new InvalidOperationException();
                }
            }
        }
Пример #2
0
        private static async Task <int> GenerateDocAsync(GenerateDocCommandLineOptions options)
        {
            if (options.MaxDerivedTypes < 0)
            {
                WriteLine("Maximum number of derived items must be equal or greater than 0.", Verbosity.Quiet);
                return(1);
            }

            if (!TryParseOptionValueAsEnum(options.Depth, ParameterNames.Depth, out DocumentationDepth depth, DocumentationOptions.Default.Depth))
            {
                return(1);
            }

            if (!TryParseOptionValueAsEnumFlags(options.IgnoredRootParts, ParameterNames.IgnoredRootParts, out RootDocumentationParts ignoredRootParts, DocumentationOptions.Default.IgnoredRootParts))
            {
                return(1);
            }

            if (!TryParseOptionValueAsEnumFlags(options.IgnoredNamespaceParts, ParameterNames.IgnoredNamespaceParts, out NamespaceDocumentationParts ignoredNamespaceParts, DocumentationOptions.Default.IgnoredNamespaceParts))
            {
                return(1);
            }

            if (!TryParseOptionValueAsEnumFlags(options.IgnoredTypeParts, ParameterNames.IgnoredTypeParts, out TypeDocumentationParts ignoredTypeParts, DocumentationOptions.Default.IgnoredTypeParts))
            {
                return(1);
            }

            if (!TryParseOptionValueAsEnumFlags(options.IgnoredMemberParts, ParameterNames.IgnoredMemberParts, out MemberDocumentationParts ignoredMemberParts, DocumentationOptions.Default.IgnoredMemberParts))
            {
                return(1);
            }

            if (!TryParseOptionValueAsEnumFlags(options.IncludeContainingNamespace, ParameterNames.IncludeContainingNamespace, out IncludeContainingNamespaceFilter includeContainingNamespaceFilter, DocumentationOptions.Default.IncludeContainingNamespaceFilter))
            {
                return(1);
            }

            if (!TryParseOptionValueAsEnumFlags(options.OmitMemberParts, ParameterNames.OmitMemberParts, out OmitMemberParts omitMemberParts, OmitMemberParts.None))
            {
                return(1);
            }

            if (!TryParseOptionValueAsEnum(options.Visibility, ParameterNames.Visibility, out Visibility visibility))
            {
                return(1);
            }

            if (!options.TryGetProjectFilter(out ProjectFilter projectFilter))
            {
                return(1);
            }

            var command = new GenerateDocCommand(
                options,
                depth,
                ignoredRootParts,
                ignoredNamespaceParts,
                ignoredTypeParts,
                ignoredMemberParts,
                omitMemberParts,
                includeContainingNamespaceFilter,
                visibility,
                projectFilter);

            CommandResult result = await command.ExecuteAsync(options.Path, options.MSBuildPath, options.Properties);

            return((result == CommandResult.Success) ? 0 : 1);
        }
Пример #3
0
        private static async Task <int> FindSymbolsAsync(FindSymbolsCommandLineOptions options)
        {
            if (!options.TryGetProjectFilter(out ProjectFilter projectFilter))
            {
                return(1);
            }

            if (!TryParseOptionValueAsEnumFlags(options.SymbolGroups, ParameterNames.SymbolGroups, out SymbolGroupFilter symbolGroups, SymbolFinderOptions.Default.SymbolGroups))
            {
                return(1);
            }

            if (!TryParseOptionValueAsEnumFlags(options.Visibility, ParameterNames.Visibility, out VisibilityFilter visibility, SymbolFinderOptions.Default.Visibility))
            {
                return(1);
            }

            if (!TryParseMetadataNames(options.WithAttributes, out ImmutableArray <MetadataName> withAttributes))
            {
                return(1);
            }

            if (!TryParseMetadataNames(options.WithoutAttributes, out ImmutableArray <MetadataName> withoutAttributes))
            {
                return(1);
            }

            if (!TryParseOptionValueAsEnumFlags(options.WithFlags, ParameterNames.WithFlags, out SymbolFlags withFlags, SymbolFlags.None))
            {
                return(1);
            }

            if (!TryParseOptionValueAsEnumFlags(options.WithoutFlags, ParameterNames.WithoutFlags, out SymbolFlags withoutFlags, SymbolFlags.None))
            {
                return(1);
            }

            ImmutableArray <SymbolFilterRule> .Builder rules = ImmutableArray.CreateBuilder <SymbolFilterRule>();

            if (withAttributes.Any())
            {
                rules.Add(new WithAttributeFilterRule(withAttributes));
            }

            if (withoutAttributes.Any())
            {
                rules.Add(new WithoutAttributeFilterRule(withoutAttributes));
            }

            if (withFlags != SymbolFlags.None)
            {
                rules.AddRange(SymbolFilterRuleFactory.FromFlags(withFlags));
            }

            if (withoutFlags != SymbolFlags.None)
            {
                rules.AddRange(SymbolFilterRuleFactory.FromFlags(withoutFlags, invert: true));
            }

            var symbolFinderOptions = new SymbolFinderOptions(
                visibility: visibility,
                symbolGroups: symbolGroups,
                rules: rules,
                ignoreGeneratedCode: options.IgnoreGeneratedCode,
                unusedOnly: options.UnusedOnly);

            var command = new FindSymbolsCommand(
                options: options,
                symbolFinderOptions: symbolFinderOptions,
                projectFilter: projectFilter);

            CommandResult result = await command.ExecuteAsync(options.Path, options.MSBuildPath, options.Properties);

            return((result == CommandResult.Success) ? 0 : 1);
        }