/// <summary> /// CbXXX型の Func<> 型を作成します。 /// </summary> /// <param name="original">Func型の正式な型</param> /// <param name="ret">オリジナルの返し値の型</param> /// <returns>型</returns> public static Type GetFuncType(Type original, Type ret) { return(typeof(CbFunc <,>).MakeGenericType( original, CbST.ConvertCbType(ret) )); }
/// <summary> /// Func<object, type> 型の CbFunc<type> 型の変数を返します。 /// </summary> /// <param name="type">オリジナルの元々の型</param> /// <param name="retType">オリジナルの返し値の型</param> /// <param name="name">変数名</param> /// <returns>CbFunc<type> 型の変数</returns> public static ICbValue FuncValue(Type type, Type retType, string name) { if (type is null) { return(null); } string typeName = type.FullName; if (type.IsByRef) { // リファレンス(スクリプト変数接続) typeName = typeName.Replace("&", ""); type = CbST.GetTypeEx(typeName); } foreach (var arg in type.GenericTypeArguments) { Type cbType = CbST.ConvertCbType(arg); if (cbType is null) { return(null); } } return(CbFunc.CreateFuncFromOriginalType(type, retType, name)); }
/// <summary> /// CbXXX型の Func<> 型の変数を作成します。 /// </summary> /// <param name="arg">Func型の第一引数のオリジナルの型</param> /// <param name="ret">オリジナルの返し値の型</param> /// <returns>CbFunc<original, CbXXX型のret型>の変数</returns> public static ICbValue CreateFunc(Type arg, Type ret, string name = "") { Type cbFuncType = typeof(CbFunc <,>).MakeGenericType( typeof(Func <,>).MakeGenericType(arg, ret), CbST.ConvertCbType(ret) ); object result = cbFuncType.InvokeMember( nameof(CbFunc <int, CbInt> .GetCbFunc), BindingFlags.InvokeMethod, null, null, new object[] { name }) as ICbValue; return(result as ICbValue); }