Ext.Net.TokenUtils.ReplaceIDTokens C# (CSharp) Method

ReplaceIDTokens() private method

private ReplaceIDTokens ( string script, Control seed ) : string
script string
seed System.Web.UI.Control
return string
        public static string ReplaceIDTokens(string script, Control seed)
        {
            script = TokenUtils.ReplaceDirectMethods(script, seed);

            Control control = null;

            string[] parts = null;

            foreach (Match match in ID_Pattern_RE.Matches(script))
            {
                parts = match.Value.Between("{", "}").Split('.');

                control = ControlUtils.FindControl(seed, parts[0]);

                if (control != null)
                {
                    if (parts.Length == 2)
                    {
                        PropertyInfo prop = control.GetType().GetProperty(parts[1]);

                        if (prop != null)
                        {
                            object value = prop.GetValue(control, null);

                            if (value == null)
                            {
                                value = ReflectionUtils.GetDefaultValue(prop);
                            }

                            if (value is string)
                            {
                                string val = TokenUtils.ParseTokens(value.ToString(), control);

                                if (TokenUtils.IsRawToken(val))
                                {
                                    val = JSON.Serialize(TokenUtils.ReplaceRawToken(val)).Chop();
                                }
                                else
                                {
                                    val = JSON.Serialize(val);
                                }

                                script = script.Replace(match.Value, val);
                            }
                            else
                            {
                                script = script.Replace(match.Value, JSON.Serialize(value));
                            }
                        }
                    }
                    else
                    {
                        if (control is Layout)
                        {
                            Component component = ((Layout)control).ParentComponent;
                            script = script.Replace(match.Value, component != null ? component.ClientID.ConcatWith(".getLayout()") : control.ClientID);
                        }
                        else if (control is Observable || control is UserControl)
                        {
                            script = script.Replace(match.Value, control.ClientID);
                        }
                        else
                        {
                            script = script.Replace(match.Value, "Ext.get(\"" + control.ClientID + "\")");
                        }
                    }
                }
                else
                {
                    script = script.Replace(match.Value, "Ext.get(\"" + parts[0] + "\")");
                }
            }

            return script;
        }

Usage Example

Exemplo n.º 1
0
        public static string ParseTokens(string script, Control seed)
        {
            if (script == null)
            {
                return(null);
            }

            if (script.ToString().StartsWith("<!token>"))
            {
                return(script.ToString().Substring(8));
            }

            if (seed == null)
            {
                seed = TokenUtils.Page;
            }

            bool isRaw = (
                TokenUtils.IsAlertToken(script) ||
                TokenUtils.IsRawToken(script) ||
                TokenUtils.IsSelectToken(script));

            script = TokenUtils.ReplaceIDTokens(script, seed);
            script = TokenUtils.ReplaceSelectTokens(script);

            script = TokenUtils.ReplaceAlertToken(script);
            script = TokenUtils.ReplaceRawToken(script);
            script = TokenUtils.ReplaceFunctionToken(script);

            return((isRaw || TokenUtils.IsFunction(script)) ? "<raw>".ConcatWith(script) : script);
        }
All Usage Examples Of Ext.Net.TokenUtils::ReplaceIDTokens