コード例 #1
0
        internal static KeyBinding CreateFrozenKeyBinding(ICommand command, ModifierKeys modifiers, Key key)
        {
            KeyBinding kb = new KeyBinding(command, key, modifiers);
            // Mark KeyBindings as frozen because they're shared between multiple editor instances.
            // KeyBinding derives from Freezable only in .NET 4, so we have to use this little trick:
            Freezable f = ((object)kb) as Freezable;

            if (f != null)
            {
                f.Freeze();
            }
            return(kb);
        }
コード例 #2
0
        /// <summary>
        /// Implementation of <see cref="System.Windows.Freezable.FreezeCore">Freezable.FreezeCore</see>.
        /// </summary>
        protected override bool FreezeCore(bool isChecking)
        {
            bool canFreeze = base.FreezeCore(isChecking);

            int count = _collection.Count;

            for (int i = 0; i < count && canFreeze; i++)
            {
                canFreeze &= Freezable.Freeze(_collection[i], isChecking);
            }

            return(canFreeze);
        }
コード例 #3
0
        public void Frozen_object_should_not_throw_when_trying_to_get_property()
        {
            var pet = Freezable.MakeFreezable <Pet>();

            pet.Age = 3;

            Freezable.Freeze(pet);

            var age      = pet.Age;
            var name     = pet.Name;
            var deceased = pet.Deceased;
            var str      = pet.ToString();
        }
コード例 #4
0
        /// <summary>
        /// Implementation of <see cref="System.Windows.Freezable.FreezeCore">Freezable.FreezeCore</see>.
        /// </summary>
        protected override bool FreezeCore(bool isChecking)
        {
            bool canFreeze = base.FreezeCore(isChecking);

            canFreeze &= Freezable.Freeze(_keyFrames, isChecking);

            if (canFreeze & !_areKeyTimesValid)
            {
                ResolveKeyTimes();
            }

            return(canFreeze);
        }
コード例 #5
0
        /// <summary>
        /// Try to freeze object
        /// </summary>
        /// <param name="freezable">Freezable object</param>
        /// <returns></returns>
        public static Boolean TryFreeze(Freezable freezable)
        {
            Debug.Assert(freezable != null);

            if (freezable.CanFreeze)
            {
                freezable.Freeze();
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #6
0
ファイル: WpfGraphicsUtil.cs プロジェクト: yesbb12/NetMap
        FreezeIfFreezable
        (
            Freezable freezable
        )
        {
            Debug.Assert(freezable != null);

            if (freezable.CanFreeze)
            {
                freezable.Freeze();

                return(true);
            }

            return(false);
        }
コード例 #7
0
ファイル: FreezingBullet.cs プロジェクト: Lawlets/GamJamTUT
    private void OnTriggerStay2D(Collider2D collision)
    {
        if (collision.gameObject.tag == m_owner)
        {
            return;
        }

        if (collision.gameObject.tag == "Enemy")
        {
            if (collision.gameObject.GetComponent <Freezable>())
            {
                Freezable freezable = collision.gameObject.GetComponent <Freezable>();
                freezable.Freeze(m_freezePower);
            }
        }
    }
コード例 #8
0
 // Token: 0x060021FF RID: 8703 RVA: 0x000A9E00 File Offset: 0x000A8000
 internal bool TryCacheFreezable(string value, Freezable freezable)
 {
     if (this.FreezeFreezables && freezable.CanFreeze)
     {
         if (!freezable.IsFrozen)
         {
             freezable.Freeze();
         }
         if (this._freezeCache == null)
         {
             this._freezeCache = new Dictionary <string, Freezable>();
         }
         this._freezeCache.Add(value, freezable);
         return(true);
     }
     return(false);
 }
コード例 #9
0
ファイル: FreezeBehavior.cs プロジェクト: radtek/Shopdrawing
 public static void FreezeResources(ResourceDictionary resources)
 {
     object[] objArray = new object[resources.Keys.Count];
     resources.Keys.CopyTo(objArray, 0);
     object[] objArray1 = objArray;
     for (int i = 0; i < (int)objArray1.Length; i++)
     {
         Freezable item = resources[objArray1[i]] as Freezable;
         if (item != null && item.CanFreeze)
         {
             item.Freeze();
         }
     }
     foreach (ResourceDictionary mergedDictionary in resources.MergedDictionaries)
     {
         FreezeBehavior.FreezeResources(mergedDictionary);
     }
 }
コード例 #10
0
        public void FreezableOfStringWillRemainFrozenAfterFreezeCalled()
        {
            // Arrange
            Freezable <string> freezable;
            string             expected = "Hello World";
            string             actual;

            // Act
            freezable = new Freezable <string>(expected);
            freezable.Freeze();

            freezable.Value = "Goodbye World";
            actual          = freezable.Value;

            // Assert
            Assert.True(freezable.IsFrozen);
            Assert.Equal(expected, actual);
        }
コード例 #11
0
        public void FreezableOfInt32WillRemainFrozenAfterFreezeCalled()
        {
            // Arrange
            Freezable <int> freezable;
            int             expected = 123;
            int             actual;

            // Act
            freezable = new Freezable <int>(expected);
            freezable.Freeze();

            freezable.Value = 456;
            actual          = freezable.Value;

            // Assert
            Assert.True(freezable.IsFrozen);
            Assert.Equal(expected, actual);
        }
コード例 #12
0
    public override void Effect()
    {
        List <Actor> actors = GetAllHitActors();

        foreach (Actor actor in actors)
        {
            float distanceMultiplicator = GetDistanceMultiplier(actor);
            actor.TakeDamage(distanceMultiplicator * damage);

            Freezable f = actor.GetComponent <Freezable>();
            if (f != null)
            {
                f.Freeze(distanceMultiplicator * maxFreezeTime);
            }
        }

        Debug.Log("Freeze stuff");
    }
コード例 #13
0
        private static void TryFreeze(Freezable freezable)
        {
            var bindingProperty = GetBindingProperty(freezable);

            if (bindingProperty != null)
            {
                var bindingExpression = BindingOperations.GetBindingExpression(freezable, bindingProperty);
                if (bindingExpression == null)
                {
                    freezable.Changed += OnFreezableChanged;
                    return;
                }

                bindingExpression.UpdateTarget();
                freezable.SetValue(bindingProperty, freezable.GetValue(bindingProperty));
                BindingOperations.ClearAllBindings(freezable);
                freezable.Freeze();
            }
        }
コード例 #14
0
        public void Freezable_should_work_normally()
        {
            var rex = Freezable.MakeFreezable <Pet>();

            rex.Name = "Rex";
            rex.Age += 50;
            Assert.AreEqual(50, rex.Age);
            rex.Deceased = true;

            Freezable.Freeze(rex);

            Assert.IsTrue(Freezable.IsFrozen(rex));

            try {
                rex.Age++;
                Assert.Fail("rex is frozen!!!");
            }
            catch (ObjectFreezenException) {
                Console.WriteLine("Oops. it's frozen. Can't change that anymore.");
            }
        }
コード例 #15
0
        private void AddFreezableEntries(ResourceDictionary dictionary)
        {
            if (Items == null)
            {
                return;
            }

            for (int i = 0; i < Items.Count; i++)
            {
                //Freeze Freezable item.
                Freezable item = Items[i];
                if (item.CanFreeze)
                {
                    item.Freeze();
                }
                else
                {
                    item = null;
                }

                AddEntry(dictionary, item);
            }
        }
コード例 #16
0
ファイル: IceSpray.cs プロジェクト: ElliotHume/LabyrinthianVR
 void OnTriggerEnter(Collider other)
 {
     //Debug.Log("Ice Spray hit "+other.gameObject);
     if (other.tag == "Spell_Interactable")
     {
         SpellInteractable si = other.GetComponent <SpellInteractable>();
         Freezable         b  = other.GetComponent <Freezable>();
         if (si != null)
         {
             si.Trigger("icespray");
         }
         if (b != null)
         {
             b.Freeze();
         }
         Debug.Log("Freeze: " + other.gameObject);
     }
     else if (other.tag == "Enemy")
     {
         EnemyAI  enemy  = other.GetComponent <EnemyAI>();
         CasterAI caster = other.GetComponent <CasterAI>();
         if (enemy != null)
         {
             enemy.Slow(15f);
             enemy.TakeDamage("ice", damagePerTick);
         }
         if (caster != null)
         {
             caster.TakeDamage("ice", damagePerTick);
         }
     }
     else if (other.tag == "Missile")
     {
         Destroy(other.gameObject);
     }
 }
コード例 #17
0
        // Token: 0x0600226B RID: 8811 RVA: 0x000AAF38 File Offset: 0x000A9138
        internal static void TransformNodes(XamlReader xamlReader, XamlObjectWriter xamlWriter, bool onlyLoadOneNode, bool skipJournaledProperties, bool shouldPassLineNumberInfo, IXamlLineInfo xamlLineInfo, IXamlLineInfoConsumer xamlLineInfoConsumer, XamlContextStack <WpfXamlFrame> stack, IStyleConnector styleConnector)
        {
            while (xamlReader.Read())
            {
                if (shouldPassLineNumberInfo && xamlLineInfo.LineNumber != 0)
                {
                    xamlLineInfoConsumer.SetLineInfo(xamlLineInfo.LineNumber, xamlLineInfo.LinePosition);
                }
                switch (xamlReader.NodeType)
                {
                case XamlNodeType.StartObject:
                    WpfXamlLoader.WriteStartObject(xamlReader, xamlWriter, stack);
                    break;

                case XamlNodeType.GetObject:
                    xamlWriter.WriteNode(xamlReader);
                    if (stack.CurrentFrame.Type != null)
                    {
                        stack.PushScope();
                    }
                    stack.CurrentFrame.Type = stack.PreviousFrame.Property.Type;
                    break;

                case XamlNodeType.EndObject:
                {
                    xamlWriter.WriteNode(xamlReader);
                    if (stack.CurrentFrame.FreezeFreezable)
                    {
                        Freezable freezable = xamlWriter.Result as Freezable;
                        if (freezable != null && freezable.CanFreeze)
                        {
                            freezable.Freeze();
                        }
                    }
                    DependencyObject dependencyObject = xamlWriter.Result as DependencyObject;
                    if (dependencyObject != null && stack.CurrentFrame.XmlSpace != null)
                    {
                        XmlAttributeProperties.SetXmlSpace(dependencyObject, stack.CurrentFrame.XmlSpace.Value ? "default" : "preserve");
                    }
                    stack.PopScope();
                    break;
                }

                case XamlNodeType.StartMember:
                    if ((!xamlReader.Member.IsDirective || !(xamlReader.Member == XamlReaderHelper.Freeze)) && xamlReader.Member != WpfXamlLoader.XmlSpace.Value && xamlReader.Member != XamlLanguage.Space)
                    {
                        xamlWriter.WriteNode(xamlReader);
                    }
                    stack.CurrentFrame.Property = xamlReader.Member;
                    if (skipJournaledProperties && !stack.CurrentFrame.Property.IsDirective)
                    {
                        WpfXamlMember wpfXamlMember = stack.CurrentFrame.Property as WpfXamlMember;
                        if (wpfXamlMember != null)
                        {
                            DependencyProperty dependencyProperty = wpfXamlMember.DependencyProperty;
                            if (dependencyProperty != null)
                            {
                                FrameworkPropertyMetadata frameworkPropertyMetadata = dependencyProperty.GetMetadata(stack.CurrentFrame.Type.UnderlyingType) as FrameworkPropertyMetadata;
                                if (frameworkPropertyMetadata != null && frameworkPropertyMetadata.Journal)
                                {
                                    int num = 1;
                                    while (xamlReader.Read())
                                    {
                                        switch (xamlReader.NodeType)
                                        {
                                        case XamlNodeType.StartObject:
                                        {
                                            XamlType type      = xamlReader.Type;
                                            XamlType xamlType  = type.SchemaContext.GetXamlType(typeof(BindingBase));
                                            XamlType xamlType2 = type.SchemaContext.GetXamlType(typeof(DynamicResourceExtension));
                                            if (num == 1 && (type.CanAssignTo(xamlType) || type.CanAssignTo(xamlType2)))
                                            {
                                                num = 0;
                                                WpfXamlLoader.WriteStartObject(xamlReader, xamlWriter, stack);
                                            }
                                            break;
                                        }

                                        case XamlNodeType.StartMember:
                                            num++;
                                            break;

                                        case XamlNodeType.EndMember:
                                            num--;
                                            if (num == 0)
                                            {
                                                xamlWriter.WriteNode(xamlReader);
                                                stack.CurrentFrame.Property = null;
                                            }
                                            break;

                                        case XamlNodeType.Value:
                                        {
                                            DynamicResourceExtension dynamicResourceExtension = xamlReader.Value as DynamicResourceExtension;
                                            if (dynamicResourceExtension != null)
                                            {
                                                WpfXamlLoader.WriteValue(xamlReader, xamlWriter, stack, styleConnector);
                                            }
                                            break;
                                        }
                                        }
                                        if (num == 0)
                                        {
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    break;

                case XamlNodeType.EndMember:
                {
                    WpfXamlFrame currentFrame = stack.CurrentFrame;
                    XamlMember   property     = currentFrame.Property;
                    if ((!property.IsDirective || !(property == XamlReaderHelper.Freeze)) && property != WpfXamlLoader.XmlSpace.Value && property != XamlLanguage.Space)
                    {
                        xamlWriter.WriteNode(xamlReader);
                    }
                    currentFrame.Property = null;
                    break;
                }

                case XamlNodeType.Value:
                    WpfXamlLoader.WriteValue(xamlReader, xamlWriter, stack, styleConnector);
                    break;

                case XamlNodeType.NamespaceDeclaration:
                    xamlWriter.WriteNode(xamlReader);
                    if (stack.Depth == 0 || stack.CurrentFrame.Type != null)
                    {
                        stack.PushScope();
                        for (WpfXamlFrame wpfXamlFrame = stack.CurrentFrame; wpfXamlFrame != null; wpfXamlFrame = (WpfXamlFrame)wpfXamlFrame.Previous)
                        {
                            if (wpfXamlFrame.XmlnsDictionary != null)
                            {
                                stack.CurrentFrame.XmlnsDictionary = new XmlnsDictionary(wpfXamlFrame.XmlnsDictionary);
                                break;
                            }
                        }
                        if (stack.CurrentFrame.XmlnsDictionary == null)
                        {
                            stack.CurrentFrame.XmlnsDictionary = new XmlnsDictionary();
                        }
                    }
                    stack.CurrentFrame.XmlnsDictionary.Add(xamlReader.Namespace.Prefix, xamlReader.Namespace.Namespace);
                    break;

                default:
                    xamlWriter.WriteNode(xamlReader);
                    break;
                }
                if (onlyLoadOneNode)
                {
                    return;
                }
            }
        }
コード例 #18
0
        internal static void TransformNodes(System.Xaml.XamlReader xamlReader, System.Xaml.XamlObjectWriter xamlWriter,
                                            bool onlyLoadOneNode,
                                            bool skipJournaledProperties,
                                            bool shouldPassLineNumberInfo, IXamlLineInfo xamlLineInfo, IXamlLineInfoConsumer xamlLineInfoConsumer,
                                            XamlContextStack <WpfXamlFrame> stack,
                                            IStyleConnector styleConnector)
        {
            while (xamlReader.Read())
            {
                if (shouldPassLineNumberInfo)
                {
                    if (xamlLineInfo.LineNumber != 0)
                    {
                        xamlLineInfoConsumer.SetLineInfo(xamlLineInfo.LineNumber, xamlLineInfo.LinePosition);
                    }
                }

                switch (xamlReader.NodeType)
                {
                case System.Xaml.XamlNodeType.NamespaceDeclaration:
                    xamlWriter.WriteNode(xamlReader);
                    if (stack.Depth == 0 || stack.CurrentFrame.Type != null)
                    {
                        stack.PushScope();
                        // Need to create an XmlnsDictionary.
                        // Look up stack to see if we have one earlier
                        //  If so, use that.  Otherwise new a xmlnsDictionary
                        WpfXamlFrame iteratorFrame = stack.CurrentFrame;
                        while (iteratorFrame != null)
                        {
                            if (iteratorFrame.XmlnsDictionary != null)
                            {
                                stack.CurrentFrame.XmlnsDictionary =
                                    new XmlnsDictionary(iteratorFrame.XmlnsDictionary);
                                break;
                            }
                            iteratorFrame = (WpfXamlFrame)iteratorFrame.Previous;
                        }
                        if (stack.CurrentFrame.XmlnsDictionary == null)
                        {
                            stack.CurrentFrame.XmlnsDictionary =
                                new XmlnsDictionary();
                        }
                    }
                    stack.CurrentFrame.XmlnsDictionary.Add(xamlReader.Namespace.Prefix, xamlReader.Namespace.Namespace);
                    break;

                case System.Xaml.XamlNodeType.StartObject:
                    WriteStartObject(xamlReader, xamlWriter, stack);
                    break;

                case System.Xaml.XamlNodeType.GetObject:
                    xamlWriter.WriteNode(xamlReader);
                    // If there wasn't a namespace node before this get object, need to pushScope.
                    if (stack.CurrentFrame.Type != null)
                    {
                        stack.PushScope();
                    }
                    stack.CurrentFrame.Type = stack.PreviousFrame.Property.Type;
                    break;

                case System.Xaml.XamlNodeType.EndObject:
                    xamlWriter.WriteNode(xamlReader);
                    // Freeze if required
                    if (stack.CurrentFrame.FreezeFreezable)
                    {
                        Freezable freezable = xamlWriter.Result as Freezable;
                        if (freezable != null && freezable.CanFreeze)
                        {
                            freezable.Freeze();
                        }
                    }
                    DependencyObject dependencyObject = xamlWriter.Result as DependencyObject;
                    if (dependencyObject != null && stack.CurrentFrame.XmlSpace.HasValue)
                    {
                        XmlAttributeProperties.SetXmlSpace(dependencyObject, stack.CurrentFrame.XmlSpace.Value ? "default" : "preserve");
                    }
                    stack.PopScope();
                    break;

                case System.Xaml.XamlNodeType.StartMember:
                    // ObjectWriter should NOT process PresentationOptions:Freeze directive since it is Unknown
                    // The space directive node stream should not be written because it induces object instantiation,
                    // and the Baml2006Reader can produce space directives prematurely.
                    if (!(xamlReader.Member.IsDirective && xamlReader.Member == XamlReaderHelper.Freeze) &&
                        xamlReader.Member != XmlSpace.Value &&
                        xamlReader.Member != XamlLanguage.Space)
                    {
                        xamlWriter.WriteNode(xamlReader);
                    }

                    stack.CurrentFrame.Property = xamlReader.Member;
                    if (skipJournaledProperties)
                    {
                        if (!stack.CurrentFrame.Property.IsDirective)
                        {
                            System.Windows.Baml2006.WpfXamlMember wpfMember = stack.CurrentFrame.Property as System.Windows.Baml2006.WpfXamlMember;
                            if (wpfMember != null)
                            {
                                DependencyProperty prop = wpfMember.DependencyProperty;

                                if (prop != null)
                                {
                                    FrameworkPropertyMetadata metadata = prop.GetMetadata(stack.CurrentFrame.Type.UnderlyingType) as FrameworkPropertyMetadata;
                                    if (metadata != null && metadata.Journal == true)
                                    {
                                        // Ignore the BAML for this member, unless it declares a value that wasn't journaled - namely a binding or a dynamic resource
                                        int count = 1;
                                        while (xamlReader.Read())
                                        {
                                            switch (xamlReader.NodeType)
                                            {
                                            case System.Xaml.XamlNodeType.StartMember:
                                                count++;
                                                break;

                                            case System.Xaml.XamlNodeType.StartObject:
                                                XamlType xamlType            = xamlReader.Type;
                                                XamlType bindingBaseType     = xamlType.SchemaContext.GetXamlType(typeof(BindingBase));
                                                XamlType dynamicResourceType = xamlType.SchemaContext.GetXamlType(typeof(DynamicResourceExtension));
                                                if (count == 1 && (xamlType.CanAssignTo(bindingBaseType) || xamlType.CanAssignTo(dynamicResourceType)))
                                                {
                                                    count = 0;
                                                    WriteStartObject(xamlReader, xamlWriter, stack);
                                                }
                                                break;

                                            case System.Xaml.XamlNodeType.EndMember:
                                                count--;
                                                if (count == 0)
                                                {
                                                    xamlWriter.WriteNode(xamlReader);
                                                    stack.CurrentFrame.Property = null;
                                                }
                                                break;

                                            case System.Xaml.XamlNodeType.Value:
                                                DynamicResourceExtension value = xamlReader.Value as DynamicResourceExtension;
                                                if (value != null)
                                                {
                                                    WriteValue(xamlReader, xamlWriter, stack, styleConnector);
                                                }
                                                break;
                                            }
                                            if (count == 0)
                                            {
                                                break;
                                            }
                                        }

                                        System.Diagnostics.Debug.Assert(count == 0, "Mismatch StartMember/EndMember");
                                    }
                                }
                            }
                        }
                    }
                    break;

                case System.Xaml.XamlNodeType.EndMember:
                    WpfXamlFrame currentFrame    = stack.CurrentFrame;
                    XamlMember   currentProperty = currentFrame.Property;
                    // ObjectWriter should not process PresentationOptions:Freeze directive nodes since it is unknown
                    // The space directive node stream should not be written because it induces object instantiation,
                    // and the Baml2006Reader can produce space directives prematurely.
                    if (!(currentProperty.IsDirective && currentProperty == XamlReaderHelper.Freeze) &&
                        currentProperty != XmlSpace.Value &&
                        currentProperty != XamlLanguage.Space)
                    {
                        xamlWriter.WriteNode(xamlReader);
                    }
                    currentFrame.Property = null;
                    break;

                case System.Xaml.XamlNodeType.Value:
                    WriteValue(xamlReader, xamlWriter, stack, styleConnector);
                    break;

                default:
                    xamlWriter.WriteNode(xamlReader);
                    break;
                }

                //Only do this loop for one node if loadAsync
                if (onlyLoadOneNode)
                {
                    return;
                }
            }
        }
コード例 #19
0
        public void Freeze_nonFreezable_object_should_throw_InvalidOperationException()
        {
            var rex = new Pet();

            Assert.Throws <InvalidOperationException>(() => Freezable.Freeze(rex));
        }
コード例 #20
0
ファイル: Program.cs プロジェクト: Kamil-Zakiev/CSharp
        public void Freeze_nonFreezable_object_should_throw_NotFreezableObjectException()
        {
            var rex = new Pet();

            Assert.Throws <NotFreezableObjectException>(() => Freezable.Freeze(rex));
        }
コード例 #21
0
 static void \u206B​‪‬​‏​‭‎‏‍‏‫​‎‎‮‪‎‏‭‫‬‮([In] Freezable obj0)
 {
     obj0.Freeze();
 }
コード例 #22
0
ファイル: Baml2006Reader.cs プロジェクト: sjyanxin/WPFSource
        bool IFreezeFreezables.TryFreeze(string value, Freezable freezable)
        {
            // We don't check FreezeFreezables since this is used only by the BrushBinary deserializer inter----ly
            // It will check FreezeFreezables. 
            if (freezable.CanFreeze)
            { 
                if (!freezable.IsFrozen) 
                {
                    freezable.Freeze(); 
                }
                if (_freezeCache == null)
                {
                    _freezeCache = new Dictionary<string, Freezable>(); 
                }
                _freezeCache.Add(value, freezable); 
                return true; 
            }
 
            return false;
        }
コード例 #23
0
ファイル: WpfXamlLoader.cs プロジェクト: ash2005/z
        internal static void TransformNodes(System.Xaml.XamlReader xamlReader, System.Xaml.XamlObjectWriter xamlWriter,
                                            bool onlyLoadOneNode,
                                            bool skipJournaledProperties,
                                            bool shouldPassLineNumberInfo, IXamlLineInfo xamlLineInfo, IXamlLineInfoConsumer xamlLineInfoConsumer,
                                            XamlContextStack <WpfXamlFrame> stack,
                                            IStyleConnector styleConnector)
        {
            while (xamlReader.Read())
            {
                if (shouldPassLineNumberInfo)
                {
                    if (xamlLineInfo.LineNumber != 0)
                    {
                        xamlLineInfoConsumer.SetLineInfo(xamlLineInfo.LineNumber, xamlLineInfo.LinePosition);
                    }
                }

                switch (xamlReader.NodeType)
                {
                case System.Xaml.XamlNodeType.NamespaceDeclaration:
                    xamlWriter.WriteNode(xamlReader);
                    if (stack.Depth == 0 || stack.CurrentFrame.Type != null)
                    {
                        stack.PushScope();
                        // Need to create an XmlnsDictionary.
                        // Look up stack to see if we have one earlier
                        //  If so, use that.  Otherwise new a xmlnsDictionary
                        WpfXamlFrame iteratorFrame = stack.CurrentFrame;
                        while (iteratorFrame != null)
                        {
                            if (iteratorFrame.XmlnsDictionary != null)
                            {
                                stack.CurrentFrame.XmlnsDictionary =
                                    new XmlnsDictionary(iteratorFrame.XmlnsDictionary);
                                break;
                            }
                            iteratorFrame = (WpfXamlFrame)iteratorFrame.Previous;
                        }
                        if (stack.CurrentFrame.XmlnsDictionary == null)
                        {
                            stack.CurrentFrame.XmlnsDictionary =
                                new XmlnsDictionary();
                        }
                    }
                    stack.CurrentFrame.XmlnsDictionary.Add(xamlReader.Namespace.Prefix, xamlReader.Namespace.Namespace);
                    break;

                case System.Xaml.XamlNodeType.StartObject:
                    xamlWriter.WriteNode(xamlReader);
                    // If there's a frame but no Type, that means there
                    // was a namespace. Just set the Type
                    if (stack.Depth != 0 && stack.CurrentFrame.Type == null)
                    {
                        stack.CurrentFrame.Type = xamlReader.Type;
                    }
                    else
                    {
                        // Propagate the FreezeFreezable property from the current stack frame
                        stack.PushScope();
                        stack.CurrentFrame.Type = xamlReader.Type;
                        if (stack.PreviousFrame.FreezeFreezable)
                        {
                            stack.CurrentFrame.FreezeFreezable = true;
                        }
                    }
                    break;

                case System.Xaml.XamlNodeType.GetObject:
                    xamlWriter.WriteNode(xamlReader);
                    // If there wasn't a namespace node before this get object, need to pushScope.
                    if (stack.CurrentFrame.Type != null)
                    {
                        stack.PushScope();
                    }
                    stack.CurrentFrame.Type = stack.PreviousFrame.Property.Type;
                    break;

                case System.Xaml.XamlNodeType.EndObject:
                    xamlWriter.WriteNode(xamlReader);
                    // Freeze if required
                    if (stack.CurrentFrame.FreezeFreezable)
                    {
                        Freezable freezable = xamlWriter.Result as Freezable;
                        if (freezable != null && freezable.CanFreeze)
                        {
                            freezable.Freeze();
                        }
                    }
                    DependencyObject dependencyObject = xamlWriter.Result as DependencyObject;
                    if (dependencyObject != null && stack.CurrentFrame.XmlSpace.HasValue)
                    {
                        XmlAttributeProperties.SetXmlSpace(dependencyObject, stack.CurrentFrame.XmlSpace.Value ? "default" : "preserve");
                    }
                    stack.PopScope();
                    break;

                case System.Xaml.XamlNodeType.StartMember:
                    // ObjectWriter should NOT process PresentationOptions:Freeze directive since it is Unknown
                    // The space directive node stream should not be written because it induces object instantiation,
                    // and the Baml2006Reader can produce space directives prematurely.
                    if (!(xamlReader.Member.IsDirective && xamlReader.Member == XamlReaderHelper.Freeze) &&
                        xamlReader.Member != XmlSpace.Value &&
                        xamlReader.Member != XamlLanguage.Space)
                    {
                        xamlWriter.WriteNode(xamlReader);
                    }

                    stack.CurrentFrame.Property = xamlReader.Member;
                    if (skipJournaledProperties)
                    {
                        if (!stack.CurrentFrame.Property.IsDirective)
                        {
                            System.Windows.Baml2006.WpfXamlMember wpfMember = stack.CurrentFrame.Property as System.Windows.Baml2006.WpfXamlMember;
                            if (wpfMember != null)
                            {
                                DependencyProperty prop = wpfMember.DependencyProperty;

                                if (prop != null)
                                {
                                    FrameworkPropertyMetadata metadata = prop.GetMetadata(stack.CurrentFrame.Type.UnderlyingType) as FrameworkPropertyMetadata;
                                    if (metadata != null && metadata.Journal == true)
                                    {
                                        //
                                        int count = 1;
                                        while (xamlReader.Read())
                                        {
                                            switch (xamlReader.NodeType)
                                            {
                                            case System.Xaml.XamlNodeType.StartMember:
                                                count++;
                                                break;

                                            case System.Xaml.XamlNodeType.EndMember:
                                                count--;
                                                if (count == 0)
                                                {
                                                    xamlWriter.WriteNode(xamlReader);
                                                }
                                                break;
                                            }
                                            if (count == 0)
                                            {
                                                break;
                                            }
                                        }
                                        // shouldn't this have been a XamlReader.Skip()?
                                        System.Diagnostics.Debug.Assert(count == 0, "Mismatch StartMember/EndMember");
                                    }
                                }
                            }
                        }
                    }
                    break;

                case System.Xaml.XamlNodeType.EndMember:
                    WpfXamlFrame currentFrame    = stack.CurrentFrame;
                    XamlMember   currentProperty = currentFrame.Property;
                    // ObjectWriter should not process PresentationOptions:Freeze directive nodes since it is unknown
                    // The space directive node stream should not be written because it induces object instantiation,
                    // and the Baml2006Reader can produce space directives prematurely.
                    if (!(currentProperty.IsDirective && currentProperty == XamlReaderHelper.Freeze) &&
                        currentProperty != XmlSpace.Value &&
                        currentProperty != XamlLanguage.Space)
                    {
                        xamlWriter.WriteNode(xamlReader);
                    }
                    currentFrame.Property = null;
                    break;

                case System.Xaml.XamlNodeType.Value:
                    if (stack.CurrentFrame.Property.IsDirective && stack.CurrentFrame.Property == XamlLanguage.Shared)
                    {
                        bool isShared;
                        if (bool.TryParse(xamlReader.Value as string, out isShared))
                        {
                            if (!isShared)
                            {
                                if (!(xamlReader is Baml2006Reader))
                                {
                                    throw new XamlParseException(SR.Get(SRID.SharedAttributeInLooseXaml));
                                }
                            }
                        }
                    }
                    // ObjectWriter should not process PresentationOptions:Freeze directive nodes since it is unknown
                    if (stack.CurrentFrame.Property.IsDirective && stack.CurrentFrame.Property == XamlReaderHelper.Freeze)
                    {
                        bool freeze = Convert.ToBoolean(xamlReader.Value, TypeConverterHelper.InvariantEnglishUS);
                        stack.CurrentFrame.FreezeFreezable = freeze;
                        var bamlReader = xamlReader as System.Windows.Baml2006.Baml2006Reader;
                        if (bamlReader != null)
                        {
                            bamlReader.FreezeFreezables = freeze;
                        }
                    }
                    // The space directive node stream should not be written because it induces object instantiation,
                    // and the Baml2006Reader can produce space directives prematurely.
                    else if (stack.CurrentFrame.Property == XmlSpace.Value || stack.CurrentFrame.Property == XamlLanguage.Space)
                    {
                        if (typeof(DependencyObject).IsAssignableFrom(stack.CurrentFrame.Type.UnderlyingType))
                        {
                            System.Diagnostics.Debug.Assert(xamlReader.Value is string, "XmlAttributeProperties.XmlSpaceProperty has the type string.");
                            stack.CurrentFrame.XmlSpace = (string)xamlReader.Value == "default";
                        }
                    }
                    else
                    {
                        // Ideally we should check if we're inside FrameworkTemplate's Content and not register those.
                        // However, checking if the instance is null accomplishes the same with a much smaller perf impact.
                        if (styleConnector != null &&
                            stack.CurrentFrame.Instance != null &&
                            stack.CurrentFrame.Property == XamlLanguage.ConnectionId &&
                            typeof(Style).IsAssignableFrom(stack.CurrentFrame.Type.UnderlyingType))
                        {
                            styleConnector.Connect((int)xamlReader.Value, stack.CurrentFrame.Instance);
                        }

                        xamlWriter.WriteNode(xamlReader);
                    }
                    break;

                default:
                    xamlWriter.WriteNode(xamlReader);
                    break;
                }

                //Only do this loop for one node if loadAsync
                if (onlyLoadOneNode)
                {
                    return;
                }
            }
        }
コード例 #24
0
        internal bool TryCacheFreezable(string value, Freezable freezable)
        {
            if (FreezeFreezables)
            {
                if (freezable.CanFreeze)
                {
                    if (!freezable.IsFrozen)
                    {
                        freezable.Freeze();
                    }
                    if (_freezeCache == null)
                    {
                        _freezeCache = new Dictionary<string, Freezable>();
                    }
                    _freezeCache.Add(value, freezable);
                    return true;
                }
            }

            return false;
        }