Skip to content

Instantly share code, notes, and snippets.

@nesteruk
Created December 15, 2019 21:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nesteruk/f04914f3ed3a9c59d08749d2dde9f177 to your computer and use it in GitHub Desktop.
Save nesteruk/f04914f3ed3a9c59d08749d2dde9f177 to your computer and use it in GitHub Desktop.
using System;
using System.Linq;
namespace DotNetDesignPatternDemos.Structural.Proxy.Composite
{
// todo: publish
public class MasonrySettings
{
//public bool? All
//{
// get
// {
// if (Pillars == Walls &&
// Walls == Floors)
// return Pillars;
// return null;
// }
// set
// {
// if (!value.HasValue) return;
// Pillars = value.Value;
// Walls = value.Value;
// Floors = value.Value;
// } // error-prone!
//}
public bool? All
{
get
{
if (flags.Skip(1).All(f => f == flags[0]))
return flags[0];
return null;
}
set
{
if (!value.HasValue) return;
for (int i = 0; i < flags.Length; ++i)
flags[i] = value.Value;
}
}
//public bool Pillars;
//public bool Walls;
//public bool Floors;
private bool[] flags = new bool[3];
public bool Pillars
{
get => flags[0];
set => flags[0] = value;
}
public bool Walls
{
get => flags[1];
set => flags[1] = value;
}
public bool Floors
{
get => flags[2];
set => flags[2] = value;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment