Exemple #1
0
        public static bool TryCreateFromCodeFile <TDelegate>(
            string filePath,
            Type returnType,
            Type parameterType,
            out TDelegate result) where TDelegate : Delegate
        {
            if (!ParseHelpers.TryReadAllText(filePath, out string content, f => Logger.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);
        }