public static T TypeAssert <T>(this go.main_package.Abser target) { try { go.main_package.Abser <T> test = (go.main_package.Abser <T>)target; return((T)target); } catch (InvalidCastException) { throw new PanicException($"panic: interface conversion: {target.GetType().FullName} is not {typeof(T).FullName}"); } catch (NotImplementedException ex) { throw new PanicException($"panic: interface conversion: {target.GetType().FullName} is not {typeof(T).FullName}: missing method {ex.InnerException?.Message}"); } }
public static object TypeAssert(this go.main_package.Abser target, Type type) { try { MethodInfo conversionOperator = s_conversionOperators.GetOrAdd(type, _ => typeof(go.main_package.Abser <>).GetExplicitGenericConversionOperator(type)); if ((object)conversionOperator == null) { throw new PanicException($"panic: interface conversion: {target.GetType().FullName} is not {type.FullName}"); } return(conversionOperator.Invoke(null, new object[] { target })); } catch (NotImplementedException ex) { throw new PanicException($"panic: interface conversion: {target.GetType().FullName} is not {type.FullName}: missing method {ex.InnerException?.Message}"); } }