.NET 4.x Сравнение нескольких объектов - C#
Формулировка задачи:
Что скажете про такую лабуду?
жду замечаний и летящих помидоров
string month = "July";
if (month == "June".Or("July").Or("August"))
Console.WriteLine("Summer ;)");
if (1 == 1.Xor(1))
Console.WriteLine("NO(");
DateTime a = DateTime.Now, b = a, c = b;
if(a == b.And(c))
Console.WriteLine("Unexpectedly!");
Console.ReadKey();public static class Extention
{
public class Items<T> : IEquatable<T>
where T : IEquatable<T>
{
public delegate bool Method(bool b1, bool b2);
Method method;
IEquatable<T> el1, el2;
public Items(IEquatable<T> el1, IEquatable<T> el2, Method method)
{
this.el1 = el1;
this.el2 = el2;
this.method = method;
}
public bool Equals(T item)
{
return method(el2.Equals(item), el1.Equals(item));
}
public static bool operator ==(T element, Items<T> items)
{
return items.Equals(element);
}
public static bool operator !=(T element, Items<T> items)
{
return !items.Equals(element);
}
}
public static Items<TEl> Or<TEl>(this IEquatable<TEl> t1, TEl t2)
where TEl : IEquatable<TEl>
{
return new Items<TEl>(t1, t2, (a, b) => a || b);
}
public static Items<TEl> And<TEl>(this IEquatable<TEl> t1, TEl t2)
where TEl : IEquatable<TEl>
{
return new Items<TEl>(t1, t2, (a, b) => a && b);
}
public static Items<TEl> Xor<TEl>(this IEquatable<TEl> t1, TEl t2)
where TEl : IEquatable<TEl>
{
return new Items<TEl>(t1, t2, (a, b) => a ^ b);
}
}Решение задачи: «.NET 4.x Сравнение нескольких объектов»
textual
Листинг программы
string monthnull = null; Console.WriteLine((monthnull == null) || (monthnull == monthnull.ToString())); Console.WriteLine(monthnull.Or(null).Or(monthnull.ToString()));