Represents an attribute as it is being rendered.
Пример #1
0
        /// <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);
            }
        }
Пример #2
0
        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;
        }
Пример #3
0
        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;
        }
Пример #4
0
 internal Constant(string attribute, string expression)
     : base(attribute, expression)
 {
     Extension = null;
     Path = null;
     binding = new AttributeBinding(new Attribute() { Name = attribute, Value = expression }, null);
 }
Пример #5
0
        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);
        }
Пример #6
0
        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);
        }
Пример #7
0
        /// <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;
        }