Wraps the results of a programmatically-accessed compilation of a Type with the warnings generated by the compiler.
예제 #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TypeResults"/> class.
 /// </summary>
 /// <param name="methodReference">
 /// The reflected information on the final method produced by the compiler.
 /// </param>
 /// <param name="compiledType">
 /// The results of the programmatically-accessed compilation of the containing type.
 /// </param>
 protected internal MethodResults(MethodInfo methodReference, TypeResults compiledType)
 {
     typeResults = compiledType;
     method = methodReference;
     Instance = typeResults.Instantiate();
     FastInvoke = Hack.GetMethodInvoker(method);
 }
예제 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TypeResults"/> class.
 /// </summary>
 /// <param name="methodReference">
 /// The reflected information on the final method produced by the compiler.
 /// </param>
 /// <param name="compiledType">
 /// The results of the programmatically-accessed compilation of the containing type.
 /// </param>
 protected internal MethodResults(MethodInfo methodReference, TypeResults compiledType)
 {
     typeResults = compiledType;
     method      = methodReference;
     Instance    = typeResults.Instantiate();
     FastInvoke  = Hack.GetMethodInvoker(method);
 }
예제 #3
0
        /// <summary>
        /// Compiles a method from the provided source with the parameters specified.
        /// </summary>
        /// <param name="compiler">
        /// The compiler to use for compiling the source to MSIL.
        /// </param>
        /// <param name="methodSource">
        /// The actual source of the method.
        /// </param>
        /// <param name="methodName">
        /// The name of the method.
        /// </param>
        /// <param name="options">
        /// The parameters to be set for the compiler.
        /// </param>
        /// <param name="language">
        /// A specification of the syntax of the language of the code
        /// </param>
        /// <returns>
        /// The resulting method and any warnings produced by the compiler, wrapped in a MethodResults object.
        /// </returns>
        /// <exception cref="CompilationException"/>
        public static MethodResults CreateMethod(ICodeCompiler compiler, string methodSource, string methodName, CompilerParameters options, Language language)
        {
            string containerName = String.Format("{0}Container", methodName);

            StringBuilder sourceBuilder = new StringBuilder();

            sourceBuilder.Append(language.beginType(containerName));
            sourceBuilder.Append(methodSource);
            sourceBuilder.Append(language.endType(containerName));

            TypeResults compiledType = CreateType(compiler, sourceBuilder.ToString(), containerName, options, language);

            return(compiledType.GetMethod(methodName));
        }