コード例 #1
0
        private IList <object> GetClientIdFragments()
        {
            var rawId = GetValue(IDProperty);

            // can't generate ID from nothing
            if (rawId == null)
            {
                return(null);
            }

            if (ClientIDMode == ClientIDMode.Static)
            {
                // just rewrite Static mode ID
                return(new[] { ID });
            }

            var fragments = new List <object> {
                rawId
            };
            DotvvmControl childContainer        = null;
            bool          searchingForIdElement = false;

            foreach (DotvvmControl ancestor in GetAllAncestors())
            {
                if (IsNamingContainer(ancestor))
                {
                    if (searchingForIdElement)
                    {
                        fragments.Add(childContainer.GetDotvvmUniqueId());
                    }
                    searchingForIdElement = false;

                    var clientIdExpression = ancestor.GetValueRaw(Internal.ClientIDFragmentProperty);
                    if (clientIdExpression is IValueBinding)
                    {
                        fragments.Add(clientIdExpression);
                    }
                    else if (!string.IsNullOrEmpty(ancestor.ID))
                    {
                        // add the ID fragment
                        fragments.Add(ancestor.ID);
                    }
                    else
                    {
                        searchingForIdElement = true;
                        childContainer        = ancestor;
                    }
                }

                if (searchingForIdElement && ancestor.IsPropertySet(ClientIDProperty))
                {
                    fragments.Add(ancestor.GetValueRaw(ClientIDProperty));
                    searchingForIdElement = false;
                }

                if (ancestor.ClientIDMode == ClientIDMode.Static)
                {
                    break;
                }
            }
            if (searchingForIdElement)
            {
                fragments.Add(childContainer.GetDotvvmUniqueId());
            }
            fragments.Reverse();
            return(fragments);
        }
コード例 #2
0
ファイル: DotvvmControl.cs プロジェクト: samdubey/dotvvm
        private IList <ClientIDFragment> GetClientIdFragments()
        {
            var rawId = GetValue(IDProperty);

            // can't generate ID from nothing
            if (rawId == null)
            {
                return(null);
            }

            if (ClientIDMode == ClientIDMode.Static)
            {
                // just rewrite Static mode ID
                return(new[] { new ClientIDFragment(ID) });
            }

            var fragments = new List <ClientIDFragment> {
                ClientIDFragment.FromProperty(rawId)
            };
            var           dataContextChanges    = HasBinding(DataContextProperty) ? 1 : 0;
            DotvvmControl childContainer        = null;
            bool          searchingForIdElement = false;

            foreach (var ancestor in GetAllAncestors())
            {
                if (ancestor.HasBinding(DataContextProperty))
                {
                    dataContextChanges++;
                }

                if (IsNamingContainer(ancestor))
                {
                    if (searchingForIdElement)
                    {
                        fragments.Add(ClientIDFragment.FromProperty(childContainer.GetDotvvmUniqueId()));
                    }
                    searchingForIdElement = false;

                    var clientIdExpression = (string)ancestor.GetValue(Internal.ClientIDFragmentProperty);
                    if (clientIdExpression != null)
                    {
                        // generate the expression
                        var expression = new StringBuilder();
                        for (int i = 0; i < dataContextChanges; i++)
                        {
                            throw new NotImplementedException(); // TODO:
                        }
                        expression.Append(clientIdExpression);
                        fragments.Add(new ClientIDFragment(expression.ToString(), isExpression: true));
                    }
                    else if (!string.IsNullOrEmpty(ancestor.ID))
                    {
                        // add the ID fragment
                        fragments.Add(new ClientIDFragment(ancestor.ID));
                    }
                    else
                    {
                        searchingForIdElement = true;
                        childContainer        = ancestor;
                    }
                }

                if (searchingForIdElement && ancestor.IsPropertySet(ClientIDProperty))
                {
                    fragments.Add(ClientIDFragment.FromProperty(ancestor.GetValueRaw(ClientIDProperty)));
                    searchingForIdElement = false;
                }

                if (ancestor.ClientIDMode == ClientIDMode.Static)
                {
                    break;
                }
            }
            if (searchingForIdElement)
            {
                fragments.Add(ClientIDFragment.FromProperty(childContainer.GetDotvvmUniqueId()));
            }
            return(fragments);
        }