コード例 #1
0
 public static T TypeAssert <T>(this go.main_package.I target)
 {
     try
     {
         go.main_package.I <T> test = (go.main_package.I <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}");
     }
 }
コード例 #2
0
        public static object TypeAssert(this go.main_package.I target, Type type)
        {
            try
            {
                MethodInfo conversionOperator = s_conversionOperators.GetOrAdd(type, _ => typeof(go.main_package.I <>).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}");
            }
        }
コード例 #3
0
ファイル: methprom_IInterface.cs プロジェクト: zjmit/go2cs
 public static T _ <T>(this go.main_package.I target)
 {
     try
     {
         return(((go.main_package.I <T>)target).Target);
     }
     catch (NotImplementedException ex)
     {
         throw new PanicException($"interface conversion: {GetGoTypeName(target.GetType())} is not {GetGoTypeName(typeof(T))}: missing method {ex.InnerException?.Message}");
     }
 }