コード例 #1
0
ファイル: DelegateFactory.cs プロジェクト: JosefPihrt/Orang
        public static bool TryCreateFromSourceText <TDelegate>(
            string sourceText,
            Type returnType,
            Type parameterType,
            [NotNullWhen(true)] out TDelegate?result) where TDelegate : Delegate
        {
            Assembly?assembly = AssemblyFactory.FromSourceText(sourceText);

            if (assembly == null)
            {
                result = null;
                return(false);
            }

            result = CreateDelegateAndCatchIfThrows <TDelegate>(assembly, returnType, new Type[] { parameterType });
            return(result != null);
        }
コード例 #2
0
ファイル: DelegateFactory.cs プロジェクト: JosefPihrt/Orang
        public static bool TryCreateFromCodeFile <TDelegate>(
            string filePath,
            Type returnType,
            Type parameterType,
            [NotNullWhen(true)] out TDelegate?result) where TDelegate : Delegate
        {
            if (!FileSystemHelpers.TryReadAllText(filePath, out string?content, f => WriteError(f)))
            {
                result = null;
                return(false);
            }

            Assembly?assembly = AssemblyFactory.FromSourceText(content);

            if (assembly == null)
            {
                result = null;
                return(false);
            }

            result = CreateDelegateAndCatchIfThrows <TDelegate>(assembly, returnType, new Type[] { parameterType });
            return(result != null);
        }