Updated Chapter 12 with C# 8.0 related constraints.
ADD
src/Chapter12/Listing12.24.UsingDelegateConstraint.cs
+using System;
+
+namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_31
+{
+ public class Publisher
+ {
+ static public object? InvokeAll<TDelegate>(
+ object?[]? args, params TDelegate[] delegates)
+ // Constraint of type Action/Func not allowed
+ where TDelegate : System.MulticastDelegate
+ {
+ switch (Delegate.Combine(delegates))
+ {
+ case Action action:
+ action();
+ return null;
+ case TDelegate result:
+ return result.DynamicInvoke(args);
+ default:
+ return null;
+ };
+ }
+
+ static public void InvokeAll(params Action?[] actions)
+ {
+ Action? result = (Action?)Delegate.Combine(actions);
+ result?.Invoke();
+ }
+ }
+}

RENAME
src/Chapter12/Listing12.24.SpecifyingTheTypeParameterAsAValueType.cs
src/Chapter12/Listing12.25.SpecifyingTheTypeParameterAsAValueType.cs
RENAME
src/Chapter12/Listing12.25.SpecifyingMultipleConstraints.cs
src/Chapter12/Listing12.26.SpecifyingMultipleConstraints.cs
DELETE
src/Chapter12/Listing12.27.InheritedConstraintsSpecifiedExplicitly.cs
-namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_27
-{
- using System;
-
- class EntityBase<T> where T : IComparable<T>
- {
- // ...
- }
-
- // ERROR:
- // The type 'T' must be convertible to 'System.IComparable<T>'
- // to use it as parameter 'T' in the generic type or
- // method
- // class Entity<T> : EntityBase<T>
- // {
- // ...
- // }
-}

RENAME
src/Chapter12/Listing12.26.RequiringADefaultConstructorConstraint.cs
src/Chapter12/Listing12.27.RequiringADefaultConstructorConstraint.cs
MODIFY
src/Chapter12/Listing12.28.InheritedConstraintsSpecifiedExplicitly.cs
src/Chapter12/Listing12.28.InheritedConstraintsSpecifiedExplicitly.cs
-namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_28
+namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_27
{
using System;
- class EntityBase
- {
- public virtual void Method<T>(T t)
- where T : IComparable<T>
+ class EntityBase<T> where T : IComparable<T>
{
// ...
}
- }
- class Order : EntityBase
- {
- public override void Method<T>(T t)
- // Constraints may not be repeated on overriding
- // members
- // where T : IComparable<T>
- {
+ // ERROR:
+ // The type 'T' must be convertible to 'System.IComparable<T>'
+ // to use it as parameter 'T' in the generic type or
+ // method
+ // class Entity<T> : EntityBase<T>
+ // {
// ...
- }
- }
+ // }
}

ADD
src/Chapter12/Listing12.29.InheritedConstraintsSpecifiedExplicitly.cs
+namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_28
+{
+ using System;
+
+ class EntityBase
+ {
+ public virtual void Method<T>(T t)
+ where T : IComparable<T>
+ {
+ // ...
+ }
+ }
+
+ class Order : EntityBase
+ {
+ public override void Method<T>(T t)
+ // Constraints may not be repeated on overriding
+ // members
+ // where T : IComparable<T>
+ {
+ // ...
+ }
+ }
+}

RENAME
src/Chapter12/Listing12.29.ConstraintExpressionsCannotRequireOperators.cs
src/Chapter12/Listing12.30.ConstraintExpressionsCannotRequireOperators.cs
RENAME
src/Chapter12/Listing12.30.CombiningConstraintsUsingOrRelationshipNotAllowed.cs
src/Chapter12/Listing12.31.CombiningConstraintsUsingOrRelationshipNotAllowed.cs
DELETE
src/Chapter12/Listing12.31.InheritanceConstraintsCannotBeDelegates.cs
-namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_31
-{
- // Error: Constraint cannot be special class 'System.Delegate'
- //public class Publisher<T>
- // where T : System.Delegate
- //{
- // public event T Event;
- // public void Publish()
- // {
- // if(Event != null)
- // {
- // Event(this, new EventArgs());
- // }
- // }
- //}
-}

Updated Chapter 12 with C# 8.0 related constraints.