Ejemplo n.º 1
0
        public BootstrapperBuilder WithRepository(IDescriptorRepository repository)
        {
            Assume.IsRequired(repository, nameof(repository));

            this.repository = repository;
            return(this);
        }
        private static String RetrieveQualifiedName(QualifiedNameSyntax qualifiedNameNode)
        {
            Assume.IsRequired(qualifiedNameNode, nameof(qualifiedNameNode));

            var name    = "";
            var current = qualifiedNameNode;

            while (current != null)
            {
                var identifier = current.Right.Identifier;
                name = String.IsNullOrEmpty(name)
                    ? identifier.Text
                    : $"{identifier.Text}.{name}";

                if (current.Left is IdentifierNameSyntax)
                {
                    identifier = ((IdentifierNameSyntax)current.Left).Identifier;
                    name       = $"{identifier.Text}.{name}";
                }

                current = current.Left as QualifiedNameSyntax;
            }

            return(name);
        }
Ejemplo n.º 3
0
        public BootstrapperBuilder WithExecutor(IExecutor executor)
        {
            Assume.IsRequired(executor, nameof(executor));

            this.executor = executor;
            return(this);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ReplaceTextInteractiveRunnable"/> class.
        /// </summary>
        public ReplaceTextInteractiveRunnable(IServiceFactory serviceFactory)
        {
            Assume.IsRequired(serviceFactory, nameof(serviceFactory));

            this.serviceFactory     = serviceFactory;
            this.interactiveService = serviceFactory.GetService <IInteractiveService>();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="PositionedCommandCallActualArgument"/> class.
        /// </summary>
        public PositionedCommandCallActualArgument(Int32 position, Object value)
        {
            Assume.IsRequired(position >= 0, "position must be positive or zero!");

            Position = position;
            Value    = value;
        }
        /// <summary>
        /// Runs an algorithm with the specified parameter.
        /// </summary>
        public override SyntaxNode Run(SyntaxNode parameter, CompilationContext context)
        {
            if (parameter == null)
            {
                return(null);
            }
            Assume.IsRequired(context, nameof(context));

            var sourceText          = parameter.WithoutTrivia().ToFullString();
            var commentedSourceText = $"/* {sourceText} */";
            var editor = context.DocumentEditor;

            // handle root element
            if (parameter.Parent == null)
            {
                editor.RemoveNode(parameter);
                return(parameter.SyntaxTree.WithChangedText(SourceText.From(commentedSourceText)).GetRoot());
            }

            // if it is not root element then insert after it and remove the original one
            var comment         = SyntaxFactory.Comment(commentedSourceText);
            var commentedResult = SyntaxFactory.EmptyStatement().WithLeadingTrivia(comment);

            editor.InsertBefore(parameter, commentedResult);

            return(commentedResult);
        }
        public override SyntaxNode Run(SyntaxNode parameter, CompilationContext context)
        {
            if (parameter == null)
            {
                return(null);
            }
            Assume.IsRequired(context, nameof(context));

            var declaration = parameter as ClassDeclarationSyntax;

            if (declaration == null)
            {
                return(parameter);
            }

            var visibilityModifiers = Array(SyntaxKind.PublicKeyword, SyntaxKind.PrivateKeyword, SyntaxKind.ProtectedKeyword, SyntaxKind.InternalKeyword);

            var modifiers = from modifier in declaration.Modifiers
                            where visibilityModifiers.Any(visibilityModifier => visibilityModifier == modifier.Kind())
                            select modifier;

            var tokenList = RetrieveVisibilityTokenList(visibility);

            var newNode = declaration.WithModifiers(
                TokenList(tokenList.Concat(declaration.Modifiers)
                          .Except(modifiers)))
                          .NormalizeWhitespace();

            context.DocumentEditor.ReplaceNode(declaration, newNode);

            return(newNode);
        }
Ejemplo n.º 8
0
        public static IEnumerable <TAttribute> GetCustomAttributes <TAttribute>(this Type type, Boolean inherit)
            where TAttribute : Attribute
        {
            Assume.IsRequired(type, nameof(type));

            return(type.GetCustomAttributes(inherit)
                   .OfType <TAttribute>());
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Runs an algorithm with the specified parameter.
        /// </summary>
        public override SyntaxNode Run(SyntaxNode parameter, CompilationContext context)
        {
            if (parameter == null)
            {
                return(null);
            }
            Assume.IsRequired(context, nameof(context));

            context.DocumentEditor.RemoveNode(parameter);
            return(null);
        }
Ejemplo n.º 10
0
        public void RegisterService <TService>(TService service) where TService : class
        {
            Assume.IsRequired(service, nameof(service));

            var serviceType = typeof(TService);

            if (registeredServices.ContainsKey(serviceType))
            {
                throw new ArgumentException($"This service type has already been registered: {serviceType.FullName}.");
            }

            registeredServices.Add(serviceType, service);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Creates a new or gets an existing text range from text document
        /// </summary>
        /// <param name="start">The start position of text range</param>
        /// <param name="stop">The stop position of text range</param>
        public TextRange CreateOrGetTextRange(Int32 start, Int32 stop)
        {
            Assume.IsRequired(start >= 0, "start must be positive or zero!");
            Assume.IsRequired(start <= stop, "start must be lesser than stop!");

            var indexOfTextRange = textRanges.IndexOfKey(new TextRange(start, stop));

            if (indexOfTextRange != -1)
            {
                return(textRanges.Values[indexOfTextRange]);
            }

            return(createTextRange(start, stop));
        }
Ejemplo n.º 12
0
 public AutoCommandDescriptorRepository(IEnumerable <Type> runnableTypes)
 {
     Assume.IsRequired(runnableTypes, nameof(runnableTypes));
     commandDescriptors = RetrieveCommandDescriptors(runnableTypes);
 }