Last active
August 29, 2015 14:07
-
-
Save DexterHaslem/b5d7bf4332b4d400167c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* paste these in top so LINQPad eats and adds to usings | |
| using System; | |
| using System.ComponentModel; | |
| using System.Collections.Generic; | |
| using System.CodeDom.Compiler; | |
| using Microsoft.CSharp; | |
| */ | |
| public class Program | |
| { | |
| private static string src = | |
| @" | |
| using System; | |
| using System.ComponentModel; | |
| namespace LoadMe | |
| { | |
| [TypeConverter(typeof(FooConverter))] | |
| public class Foo | |
| { | |
| public string Property1 { get; set; } | |
| public string Property2 { get; set; } | |
| } | |
| public class FooConverter : TypeConverter | |
| { | |
| // stuff | |
| } | |
| } | |
| "; | |
| public static void Main() | |
| { | |
| var codeProvider = new CSharpCodeProvider(new Dictionary<string, string>{{ "CompilerVersion", "v4.0" }}); | |
| var compileParameters = new CompilerParameters(new[] { "System.dll" }); | |
| compileParameters.GenerateInMemory = true; | |
| var compilerResults = codeProvider.CompileAssemblyFromSource(compileParameters, src); | |
| if (compilerResults.Errors.Count == 0) | |
| { | |
| var fooType = compilerResults.CompiledAssembly.GetType("LoadMe.Foo"); | |
| Console.WriteLine(fooType.FullName + "::" + fooType.Assembly.FullName); | |
| Console.WriteLine("Type converter type = '" + TypeDescriptor.GetConverter(fooType).GetType().FullName + "'"); | |
| } | |
| else | |
| { | |
| foreach (var err in compilerResults.Errors) | |
| Console.WriteLine(err); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment