コード例 #1
0
        private bool ShouldGenerateField(IntermediateNode parent)
        {
            var parameters = parent.FindDescendantNodes <TagHelperDirectiveAttributeParameterIntermediateNode>();

            for (var i = 0; i < parameters.Count; i++)
            {
                var parameter = parameters[i];
                if (parameter.TagHelper.IsRefTagHelper() && parameter.BoundAttributeParameter.Name == "suppressField")
                {
                    if (parameter.HasDiagnostics)
                    {
                        parent.Diagnostics.AddRange(parameter.GetAllDiagnostics());
                    }

                    parent.Children.Remove(parameter);

                    if (parameter.AttributeStructure == AttributeStructure.Minimized)
                    {
                        return(false);
                    }

                    // We do not support non-minimized attributes here because we can't allow the value to be dynamic.
                    // As a design/experience decision, we don't let you write @ref:suppressField="false" even though
                    // we could parse it. The rationale is that it's misleading, you type something that looks like code,
                    // but it's not really.
                    parent.Diagnostics.Add(ComponentDiagnosticFactory.Create_RefSuppressFieldNotMinimized(parameter.Source));
                }
            }

            if (parent is ComponentIntermediateNode component && component.Component.IsGenericTypedComponent())
            {
                // We cannot automatically generate a 'ref' field for generic components because we don't know
                // how to write the type.
                parent.Diagnostics.Add(ComponentDiagnosticFactory.Create_RefSuppressFieldRequiredForGeneric(parent.Source));
                return(false);
            }

            return(true);
        }