コード例 #1
0
        private static T TryGetActual <T>(ICanAddMatcher <T> matcher)
        {
            if (matcher == null)
            {
                throw new InvalidOperationException(
                          $"Can't get an Actual value from a NULL matcher"
                          );
            }

            var prop = matcher?.GetType()
                       .GetProperties()
                       .FirstOrDefault(pi => pi.Name.ToLower() == "actual");

            if (prop == null)
            {
                throw new InvalidOperationException(
                          $"Failed to GetActual on type {typeof(T)}. GetActual only works on IHasActual<T> or objects with an 'Actual' property");
            }

            try
            {
                return((T)prop.GetValue(matcher));
            }
            catch
            {
                throw new InvalidOperationException(
                          @$ "Unable to get Actual value matching type {
                            typeof(T)
                        } from {
                            matcher.Stringify()
                        }"