private DataContextInfo GetTypedTemplateDataContext(DocumentCompositeNode documentNode, RawDataSourceInfoBase localSource)
        {
            if (!PlatformTypes.DataTemplate.IsAssignableFrom((ITypeId)documentNode.Type))
            {
                return((DataContextInfo)null);
            }
            IProperty dataContextProperty = documentNode.TypeResolver.ResolveProperty(DataTemplateElement.DataTypeProperty);

            if (dataContextProperty == null)
            {
                return((DataContextInfo)null);
            }
            if (DocumentPrimitiveNode.GetValueAsType(documentNode.Properties[(IPropertyId)dataContextProperty]) == null)
            {
                return((DataContextInfo)null);
            }
            DataContextInfo dataContextInfo = new DataContextInfo();

            dataContextInfo.RawDataSource = new RawDataSourceInfo((DocumentNode)documentNode, (string)null).CombineWith(localSource);
            dataContextInfo.SetDataContextOwner(documentNode, dataContextProperty);
            return(dataContextInfo);
        }
        public DataContextInfo Evaluate(IDataContextAncestorWalker walker, bool isForSettingValue)
        {
            this.visitedLocations.Reset();
            DataContextInfo       dataContextInfo1    = new DataContextInfo();
            RawDataSourceInfoBase dataSourceInfoBase1 = (RawDataSourceInfoBase)null;
            bool flag = isForSettingValue;

            this.evaluatingInfo = dataContextInfo1;
            DataContextInfo dataContextInfo2 = (DataContextInfo)null;

            try
            {
                while (walker.MoveNext())
                {
                    if (flag)
                    {
                        flag = DataContextMetadata.GetDataContextAttribute <DualDataContextAttribute>(walker.CurrentProperty) != null;
                    }
                    RawDataSourceInfoBase dataSourceInfoBase2 = !flag?this.NavigateSpecialDataContextInternal(walker, dataSourceInfoBase1, true) : dataSourceInfoBase1;

                    flag = false;
                    if (dataSourceInfoBase2 != dataSourceInfoBase1)
                    {
                        dataSourceInfoBase1 = dataSourceInfoBase2;
                        this.MoveUpIfDataContextLocation(walker);
                    }
                    if (dataSourceInfoBase1 != null)
                    {
                        if (!dataSourceInfoBase1.IsValid)
                        {
                            break;
                        }
                    }
                    RawDataSourceInfoBase rawDataContextInfo = this.GetRawDataContextInfo(walker);
                    if (rawDataContextInfo != null)
                    {
                        if (rawDataContextInfo.IsValid)
                        {
                            dataSourceInfoBase1 = rawDataContextInfo.CombineWith(dataSourceInfoBase1);
                        }
                        else if (dataSourceInfoBase1 != null)
                        {
                            dataSourceInfoBase1.SetInvalid();
                        }
                        else
                        {
                            dataSourceInfoBase1 = rawDataContextInfo;
                        }
                    }
                    if (dataSourceInfoBase1 != null)
                    {
                        if (dataSourceInfoBase1.IsValid)
                        {
                            if (dataSourceInfoBase1.HasSource)
                            {
                                break;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                    if (dataContextInfo2 == null)
                    {
                        dataContextInfo2 = this.GetTypedTemplateDataContext(walker.CurrentNode, dataSourceInfoBase1);
                    }
                }
            }
            finally
            {
                this.evaluatingInfo = (DataContextInfo)null;
            }
            if (dataContextInfo2 != null && dataContextInfo2.DataSource.IsValidWithSource && (dataSourceInfoBase1 == null || !dataSourceInfoBase1.IsValid || !dataSourceInfoBase1.HasSource))
            {
                dataContextInfo1 = dataContextInfo2;
            }
            else
            {
                dataContextInfo1.RawDataSource = dataSourceInfoBase1;
            }
            return(dataContextInfo1);
        }