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
파일: Control.cs 프로젝트: vc3/ExoWeb
        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
파일: Control.cs 프로젝트: vc3/ExoWeb
        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
파일: Binding.cs 프로젝트: vc3/ExoWeb
 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;
        }