protected void FixAttributes() { var type = this.GetType().GetTypeInfo(); foreach (var attrType in this.DefiningAttributes) { var attrName = attrType.Name.Replace("Attribute", ""); var additional = AdditionalAttributes.Where(x => x.Name == attrName).FirstOrDefault(); if (additional == null) { additional = new CodeFirstAttribute(attrName); AdditionalAttributes.Add(additional); } var propInfos = attrType.GetTypeInfo().DeclaredProperties.Where(x => x.CanWrite); foreach (var propInfo in propInfos) { var prop = additional.Properties.Where(x => x.Name == propInfo.Name).FirstOrDefault(); if (prop == null) { var thisPropInfo = type.DeclaredProperties.Where(x => x.Name == propInfo.Name).FirstOrDefault(); if (thisPropInfo != null) { var value = thisPropInfo.GetValue(this); if (thisPropInfo.PropertyType == typeof(string)) { value = "\"" + value + "\""; } additional.Properties.Add(new CodeFirstAttributeProperty(propInfo.Name, value)); } } } } }
/// <inheritdoc /> protected override void BuildRenderTree(RenderTreeBuilder builder) { Requires.Argument(builder, nameof(builder)) .IsNotNull() .Check(); var sequenceGenerator = new SequenceGenerator(); builder.OpenElement(sequenceGenerator.GetNextValue(), TagName); builder.AddAttribute(sequenceGenerator.GetNextValue(), CLASS_ATTRIBUTE_NAME, CssClasses); builder.AddMultipleAttributes(sequenceGenerator.GetNextValue(), AdditionalAttributes?.Where(pair => pair.Key != CLASS_ATTRIBUTE_NAME)); builder.AddContent(sequenceGenerator.GetNextValue(), ChildContent); builder.CloseElement(); }
protected override void BuildRenderTree(RenderTreeBuilder builder) { var sequenceGenerator = new SequenceGenerator(); builder.OpenElement(sequenceGenerator.GetNextValue(), TagName); builder.AddAttribute(sequenceGenerator.GetNextValue(), "class", CssClasses); if (TagName == HtmlTagNames.BUTTON || TagName == HtmlTagNames.INPUT) { builder.AddAttribute(sequenceGenerator.GetNextValue(), "type", Type.GetCssClassPart()); } else { builder.AddAttribute(sequenceGenerator.GetNextValue(), "role", "button"); } builder.AddMultipleAttributes(sequenceGenerator.GetNextValue(), AdditionalAttributes?.Where(pair => pair.Key != "class")); builder.AddContent(sequenceGenerator.GetNextValue(), ChildContent); builder.CloseElement(); }
protected override void BuildRenderTree(RenderTreeBuilder builder) { base.BuildRenderTree(builder); // If _fixedEditContext changes, tear down and recreate all descendants. // This is so we can safely use the IsFixed optimization on Cascadi ngValue, // optimizing for the common case where _fixedEditContext never changes. builder.OpenRegion(mEditContext.GetHashCode()); if (!IsInTableRow) { builder.OpenElement(112, "div"); builder.AddAttribute(113, "data-form-id", Id.ToString()); string defaultCssClass = "m-form-container"; if (EnableValidation) { defaultCssClass += " m-form-validation"; } builder.AddAttribute(11, "class", RenderHelper.GetCssClass(AdditionalAttributes, defaultCssClass)); if (AdditionalAttributes != null) { builder.AddMultipleAttributes(1, AdditionalAttributes.Where(a => a.Key != "class")); } builder.OpenElement(0, "form"); builder.AddAttribute(1, "id", Id.ToString()); builder.AddMultipleAttributes(1, AdditionalAttributes); builder.AddAttribute(2, "onsubmit", EventCallback.Factory.Create(this, NotifyContainer)); if (EnableValidation) { builder.AddAttribute(11, "class", "m-form-validation"); } builder.CloseElement(); } RenderFragment child(EditContext context) => (builder2) => { if (Fields != null) { RenderFragment child3() => (builder3) => { builder3.AddMarkupContent(1, "\r\n"); builder3.AddContent(2, this.Fields); builder3.AddMarkupContent(3, "\r\n"); }; builder2.OpenComponent <CascadingValue <MForm <T> > >(4); builder2.AddAttribute(5, "Value", this); builder2.AddAttribute(6, "ChildContent", child3()); builder2.CloseComponent(); } if (EnableValidation) { builder2.OpenComponent <DataAnnotationsValidator>(0); builder2.CloseComponent(); } if (EnableValidationSummary && !IsInTableRow) { builder2.OpenComponent <ValidationSummary>(1); builder2.CloseComponent(); } if (FieldList.Any()) { foreach (var groupResult in GroupByRow(FieldList)) { Process(builder2, groupResult); } } else { if (!PreventDefaultRendering) { foreach (var groupResult in GroupByRow(ReflectionHelper.GetProperties(Model).Select(pi => GetField(pi)))) { // Console.WriteLine(property.PropertyType.FullName); Process(builder2, groupResult); } } } if (!IsInTableRow) { builder2.AddMarkupContent(27, $"<button form=\"{Id}\" type=\"submit\" style=\"display: none;\">Submit</button>\r\n"); } }; builder.OpenComponent <CascadingValue <EditContext> >(3); builder.AddAttribute(4, "IsFixed", true); builder.AddAttribute(5, "Value", mEditContext); builder.AddAttribute(6, "ChildContent", child(mEditContext)); builder.CloseComponent(); if (!IsInTableRow) { builder.CloseComponent(); //div } builder.CloseRegion(); }