/// <summary> /// Creates a new attribute, optionally based on an existing attribute (and binding) and /// returns the new attribute after transforming its attribute or binding value. /// </summary> /// <param name="attributeName"></param> /// <param name="original"></param> /// <param name="transformValue"></param> /// <returns></returns> internal static AttributeBinding Transform(string attributeName, AttributeBinding original, Func <string, string> transformValue) { var exists = original != null; var attr = exists ? original.attribute : null; var result = exists ? original.binding : null; var bound = result != null; string value; if (bound) { value = result.Value == null ? "" : result.Value.ToString(); } else if (exists) { value = attr.Value; } else { value = ""; } value = transformValue(value); if (bound) { return(new AttributeBinding(new Attribute() { Name = attributeName, Value = attr.Value, Binding = attr.Binding }, new BindingResult() { Source = result.Source, Property = result.Property, IsValid = result.IsValid, Value = value })); } else if (!string.IsNullOrEmpty(value)) { return(new AttributeBinding(new Attribute() { Name = attributeName, Value = value }, null)); } else { return(null); } }
protected bool TryRenderIf(AjaxPage page, IEnumerable<string> templateNames, System.IO.TextWriter writer, out AttributeBinding ifBinding, out bool canRender) { if (If == null) { ifBinding = null; canRender = true; return true; } ifBinding = If.Evaluate(page); if (!ifBinding.IsValid) { canRender = false; return false; } canRender = JavaScriptHelpers.IsTruthy(ifBinding.Value); return true; }
protected bool TryContentTemplate(AjaxPage page, IEnumerable<string> templateNames, System.IO.TextWriter writer, out AttributeBinding contentTemplateBinding) { if (ContentTemplate == null) { contentTemplateBinding = null; return true; } contentTemplateBinding = ContentTemplate.Evaluate(page); return contentTemplateBinding.IsValid && contentTemplateBinding.Value is string; }
internal Constant(string attribute, string expression) : base(attribute, expression) { Extension = null; Path = null; binding = new AttributeBinding(new Attribute() { Name = attribute, Value = expression }, null); }
protected bool TryContentTemplate(AjaxPage page, IEnumerable <string> templateNames, System.IO.TextWriter writer, out AttributeBinding contentTemplateBinding) { if (ContentTemplate == null) { contentTemplateBinding = null; return(true); } contentTemplateBinding = ContentTemplate.Evaluate(page); return(contentTemplateBinding.IsValid && contentTemplateBinding.Value is string); }
protected bool TryRenderIf(AjaxPage page, IEnumerable <string> templateNames, System.IO.TextWriter writer, out AttributeBinding ifBinding, out bool canRender) { if (If == null) { ifBinding = null; canRender = true; return(true); } ifBinding = If.Evaluate(page); if (!ifBinding.IsValid) { canRender = false; return(false); } canRender = JavaScriptHelpers.IsTruthy(ifBinding.Value); return(true); }
/// <summary> /// Creates a new attribute, optionally based on an existing attribute (and binding) and /// returns the new attribute after transforming its attribute or binding value. /// </summary> /// <param name="attributeName"></param> /// <param name="original"></param> /// <param name="transformValue"></param> /// <returns></returns> internal static AttributeBinding Transform(string attributeName, AttributeBinding original, Func<string, string> transformValue) { var exists = original != null; var attr = exists ? original.attribute : null; var result = exists ? original.binding : null; var bound = result != null; string value; if (bound) value = result.Value == null ? "" : result.Value.ToString(); else if (exists) value = attr.Value; else value = ""; value = transformValue(value); if (bound) return new AttributeBinding(new Attribute() { Name = attributeName, Value = attr.Value, Binding = attr.Binding }, new BindingResult() { Source = result.Source, Property = result.Property, IsValid = result.IsValid, Value = value }); else if (!string.IsNullOrEmpty(value)) return new AttributeBinding(new Attribute() { Name = attributeName, Value = value }, null); else return null; }