示例#1
0
            internal override AttributeBinding Evaluate(AjaxPage page)
            {
                var path = Path;

                string sourcePath;

                if (Parameters.TryGetValue("source", out sourcePath) && sourcePath.Length > 0)
                {
                    path = sourcePath + "." + path;
                }

                var result = page.EvaluatePath(path);

                if (result.IsValid)
                {
                    if (result.Value == null)
                    {
                        string nullValue;
                        if (Parameters.TryGetValue("nullValue", out nullValue))
                        {
                            result.Value = nullValue;
                        }
                    }
                    else
                    {
                        string format;
                        if (Parameters.TryGetValue("format", out format) && !string.IsNullOrEmpty(format) && result.Value is IFormattable)
                        {
                            result.Value = ((IFormattable)result.Value).ToString(format, null);
                        }
                        else
                        {
                            string transformText;
                            if (transform == null && Parameters.TryGetValue("transform", out transformText) && transformText.Length > 0)
                            {
                                transform = Transform.Compile(transformText);
                            }

                            if (result.IsValid && transform != null)
                            {
                                IEnumerable transformed;
                                result.IsValid = transform.TryExecute(page, (IEnumerable)result.Value, out transformed);
                                result.Value   = result.IsValid ? transformed : null;
                            }
                        }
                    }
                }

                return(new AttributeBinding(Attribute, result));
            }
示例#2
0
            internal override AttributeBinding Evaluate(AjaxPage page)
            {
                // Evaluate the binding path
                var result = page.EvaluatePath(Path);

                // Invalid result
                if (result.Property == null)
                {
                    result.IsValid = false;
                }

                // # syntax
                else if (Extension == "#")
                {
                    string format = null;
                    Parameters.TryGetValue("format", out format);

                    string value;
                    result.IsValid = Adapter.TryGetDisplayValue(result.Property, format, result.Value, out value);
                    result.Value   = value;
                }

                // @ syntax
                else if (Extension == "@")
                {
                    if (string.IsNullOrEmpty(Path))
                    {
                        if (!(page.Context.DataItem is Adapter))
                        {
                            throw new ApplicationException("No path was specified for the \"@\" markup extension, and the source is not an adapter.");
                        }
                        result.Value = page.Context.DataItem;
                    }
                    else
                    {
                        ExoWeb.OnBeforeCreateAdapter(this, result.Source, result.Property);

                        result = new BindingResult()
                        {
                            Value    = new Adapter(result, Parameters),
                            IsValid  = result.IsValid,
                            Property = result.Property,
                            Source   = result.Source
                        };
                    }
                }

                return(new AttributeBinding(Attribute, result));
            }
示例#3
0
文件: Binding.cs 项目: vc3/ExoWeb
            internal override AttributeBinding Evaluate(AjaxPage page)
            {
                var path = Path;

                string sourcePath;
                if (Parameters.TryGetValue("source", out sourcePath) && sourcePath.Length > 0)
                    path = sourcePath + "." + path;

                var result = page.EvaluatePath(path);

                if (result.IsValid)
                {
                    if (result.Value == null)
                    {
                        string nullValue;
                        if (Parameters.TryGetValue("nullValue", out nullValue))
                            result.Value = nullValue;
                    }
                    else
                    {
                        string format;
                        if (Parameters.TryGetValue("format", out format) && !string.IsNullOrEmpty(format) && result.Value is IFormattable)
                            result.Value = ((IFormattable)result.Value).ToString(format, null);
                        else
                        {
                            string transformText;
                            if (transform == null && Parameters.TryGetValue("transform", out transformText) && transformText.Length > 0)
                                transform = Transform.Compile(transformText);

                            if (result.IsValid && transform != null)
                            {
                                IEnumerable transformed;
                                result.IsValid = transform.TryExecute(page, (IEnumerable)result.Value, out transformed);
                                result.Value = result.IsValid ? transformed : null;
                            }
                        }
                    }
                }

                return new AttributeBinding(Attribute, result);
            }
示例#4
0
文件: Binding.cs 项目: vc3/ExoWeb
            internal override AttributeBinding Evaluate(AjaxPage page)
            {
                // Evaluate the binding path
                var result = page.EvaluatePath(Path);

                // Invalid result
                if (result.Property == null)
                    result.IsValid = false;

                // # syntax
                else if (Extension == "#")
                {
                    string format = null;
                    Parameters.TryGetValue("format", out format);

                    string value;
                    result.IsValid = Adapter.TryGetDisplayValue(result.Property, format, result.Value, out value);
                    result.Value = value;
                }

                // @ syntax
                else if (Extension == "@")
                {
                    if (string.IsNullOrEmpty(Path))
                    {
                        if (!(page.Context.DataItem is Adapter))
                            throw new ApplicationException("No path was specified for the \"@\" markup extension, and the source is not an adapter.");
                        result.Value = page.Context.DataItem;
                    }
                    else
                    {
                        var args = ExoWeb.OnBeforeCreateAdapter(this, result.Source, result.Property);

                        result = new BindingResult()
                        {
                            Value = new Adapter(result, args != null ? args.ModifiedParameters ?? Parameters : Parameters),
                            IsValid = result.IsValid,
                            Property = result.Property,
                            Source = result.Source
                        };
                    }
                }

                return new AttributeBinding(Attribute, result);
            }