protected TApiElement EnsureApiElementType <TApiElement> (ApiElement apiElement) where TApiElement : ApiElement { if (apiElement == null) { throw new ArgumentNullException(nameof(apiElement)); } TApiElement ret = apiElement as TApiElement; if (ret == null) { throw new InvalidOperationException($"Expected API element of type '{typeof (TApiElement).FullName}' but got '{apiElement.GetType ().FullName}' instead"); } return(ret); }