Example #1
0
        public static BlazorComponentLifecycleEvent GetEquivalentComponentLifecycleEvent(WebFormsPageLifecycleEvent lcEvent)
        {
            var lcEventIndex = (int)lcEvent;

            if (lcEventIndex < (int)Constants.FirstOnInitializedEvent)
            {
                return(BlazorComponentLifecycleEvent.SetParametersAsync);
            }
            else if (lcEventIndex < (int)Constants.FirstOnParametersSetEvent)
            {
                return(BlazorComponentLifecycleEvent.OnInitialized);
            }
            else if (lcEventIndex < (int)Constants.FirstOnAfterRenderEvent)
            {
                return(BlazorComponentLifecycleEvent.OnParametersSet);
            }
            else if (lcEventIndex < (int)Constants.FirstDisposeEvent)
            {
                return(BlazorComponentLifecycleEvent.OnAfterRender);
            }
            else
            {
                return(BlazorComponentLifecycleEvent.Dispose);
            }
        }
Example #2
0
        private void ProcessLifecycleEventMethod(MethodDeclarationSyntax methodDeclaration, WebFormsPageLifecycleEvent lifecycleEvent)
        {
            var statements = (IEnumerable <StatementSyntax>)methodDeclaration.Body.Statements;

            // Dont do anything if the method is empty, no reason to move over nothing
            if (statements.Any())
            {
                statements = statements.AddComment(string.Format(Constants.NewEventRepresentationCommentTemplate, lifecycleEvent.ToString()));

                var blazorLifecycleEvent = LifecycleManagerService.GetEquivalentComponentLifecycleEvent(lifecycleEvent);

                if (_newLifecycleLines.ContainsKey(blazorLifecycleEvent))
                {
                    // Add spacing between last added method
                    statements = statements.Prepend(CodeSyntaxHelper.GetBlankLine());
                    _newLifecycleLines[blazorLifecycleEvent] = _newLifecycleLines[blazorLifecycleEvent].Concat(statements);
                }
                else
                {
                    _newLifecycleLines.Add(blazorLifecycleEvent, statements);
                }
            }
        }