public object CreateElement(CustomElement element, Hashtable attributes = null, params object[] children) { element.attributes = attributes; foreach (var child in children) { if (child is Slot) { element.slots.Add((Slot)child); } } return(this.Raw($"<{element.Selector} element-id=\"{this.elementId}\"{CreateAttributeString(attributes, element)} ssr>{string.Join(null, element.Render())}</{element.Selector}>")); }
private string CreateAttributeString(Hashtable attributes = null, CustomElement element = null) { var attributeString = ""; if (attributes == null) { return(attributeString); } foreach (var key in attributes.Keys) { var val = attributes[key]; if ((string)key == "ref") { val = $"{this.elementId}.{val}"; } var type = val.GetType(); if (type == typeof(Boolean)) { if ((bool)val) { attributeString += $" {key}"; } } else if (element != null) { if ((string)key == "ref" || (string)key == "class" || (string)key == "id") { attributeString += $" {key}=\"{val}\""; } else if (element.CustomAttributes.Contains(key)) { val = JsonConvert.SerializeObject(val, new JsonSerializerSettings { StringEscapeHandling = StringEscapeHandling.EscapeHtml }); attributeString += $" {key}={HttpUtility.HtmlEncode(val)}"; } } else { attributeString += $" {key}=\"{val}\""; } } return(attributeString); }