Skip to content

Commit 72dbf7e

Browse files
committed
C# - Added support for child ColorSet objects.
1 parent 69280a1 commit 72dbf7e

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

ColorSetKit-Test/Test.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,31 @@ public void TestColor()
127127
}
128128
}
129129

130+
[TestMethod]
131+
public void TestChild()
132+
{
133+
ColorSet set = new ColorSet();
134+
ColorSet child = new ColorSet();
135+
SolidColorBrush clear = new SolidColorBrush( System.Windows.Media.Color.FromArgb( 0, 0, 0, 0 ) );
136+
SolidColorBrush red = new SolidColorBrush( System.Windows.Media.Color.FromArgb( 255, 255, 0, 0 ) );
137+
138+
Assert.IsNull( set[ "foo" ] );
139+
140+
set.Add( child );
141+
142+
Assert.IsNull( set[ "foo" ] );
143+
144+
child.Add( red, "foo" );
145+
146+
Assert.IsNotNull( set[ "foo" ] );
147+
Assert.IsTrue( ReferenceEquals( set[ "foo" ].Color, red ) );
148+
149+
set.Add( clear, "foo" );
150+
151+
Assert.IsNotNull( set[ "foo" ] );
152+
Assert.IsTrue( ReferenceEquals( set[ "foo" ].Color, clear ) );
153+
}
154+
130155
[TestMethod]
131156
public void TestCreate()
132157
{

ColorSetKit/ColorSet.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ private Dictionary< string, ColorPair > Colors
6161
set;
6262
}
6363
= new Dictionary< string, ColorPair >();
64+
65+
private List< ColorSet > Children
66+
{
67+
get;
68+
set;
69+
}
70+
= new List< ColorSet >();
6471

6572
private object Lock
6673
{
@@ -148,10 +155,32 @@ public ColorPair ColorNamed( string name )
148155
return this.Colors[ name ];
149156
}
150157

158+
foreach( ColorSet child in this.Children )
159+
{
160+
if( child[ name ] is ColorPair color )
161+
{
162+
return color;
163+
}
164+
}
165+
151166
return null;
152167
}
153168
}
154169

170+
public void Add( ColorSet child )
171+
{
172+
if( ReferenceEquals( this, child ) )
173+
{
174+
return;
175+
}
176+
177+
lock( this.Lock )
178+
{
179+
180+
this.Children.Add( child );
181+
}
182+
}
183+
155184
public void Add( SolidColorBrush color, string name )
156185
{
157186
this.Add( color, null, name );

0 commit comments

Comments
 (0)