/// <summary> /// Compiles a type (or class) 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="typeSource"> /// The actual source of the type. /// </param> /// <param name="typeName"> /// The name of the type. /// </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 type and any warnings produced by the compiler, wrapped in a TypeResults object. /// </returns> /// <exception cref="CompilationException"/> public static TypeResults CreateType(ICodeCompiler compiler, string typeSource, string typeName, CompilerParameters options, Language language) { string namespaceName = options.OutputAssembly; if (namespaceName == null) { namespaceName = "Evaluated"; } StringBuilder sourceBuilder = new StringBuilder(); foreach (string referenced in options.ReferencedAssemblies) { sourceBuilder.Append(language.useStatement(referenced.Replace(".dll", ""))); } sourceBuilder.Append(language.beginNamespace(namespaceName)); sourceBuilder.Append(typeSource); sourceBuilder.Append(language.endNamespace(namespaceName)); AssemblyResults compiled = CreateAssembly(compiler, sourceBuilder.ToString(), options, language); return(compiled.GetType(namespaceName + "." + typeName, true)); }
/// <summary> /// Initializes a new instance of the <see cref="TypeResults"/> class. /// </summary> /// <param name="typeReference"> /// The final <see cref="Type"/> produced by the compiler. /// </param> /// <param name="compiledAssembly"> /// The results of the programmatically-accessed compilation of the containing assembly. /// </param> protected internal TypeResults(Type typeReference, AssemblyResults compiledAssembly) { type = typeReference; assemblyResults = compiledAssembly; }