Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Diagnostics;

using System.Runtime.CompilerServices;
using MS.Internal.KnownBoxes;
using MS.Internal.WindowsBase; // for FriendAccessAllowed

namespace System.Windows
Expand Down Expand Up @@ -54,12 +53,24 @@ public void SetValue(DependencyObject instance, T value)
// Set the value if it's not the default, otherwise remove the value.
if (!EqualityComparer<T>.Default.Equals(value, _defaultValue))
{
instance.SetEffectiveValue(entryIndex, null /* dp */, _globalIndex, null /* metadata */, value, BaseValueSourceInternal.Local);
object valueObject;

if (typeof(T) == typeof(bool))
{
// Use shared boxed instances rather than creating new objects for each SetValue call.
valueObject = BooleanBoxes.Box(Unsafe.As<T, bool>(ref value));
}
else
{
valueObject = value;
}

instance.SetEffectiveValue(entryIndex, dp: null, _globalIndex, metadata: null, valueObject, BaseValueSourceInternal.Local);
_hasBeenSet = true;
}
else
{
instance.UnsetEffectiveValue(entryIndex, null /* dp */, null /* metadata */);
instance.UnsetEffectiveValue(entryIndex, dp: null, metadata: null);
}
}
else
Expand Down