public object Create(IDictionary <Type, object> dictionary) { var lines = dictionary.Select(x => BuildProperty(x.Key)).ToArray(); var propertySource = string.Join("\r\n", lines); var source = "public class DebugContext { \r\n" + propertySource + "\r\n}"; var assembly = _compiler.CompileInMemory(source, GetReferencedAssemblies(dictionary).Select(a => a.Location)); var context = Activator.CreateInstance(assembly.GetTypes().First()); foreach (var type in dictionary.Keys) { context.ReflectionSet(type.Name, dictionary[type]); } return(context); }
public Assembly GenerateAssemblyInMemory(AssemblyGenerationSpec spec) { var sourceCode = _handlerGenerator.GetSourceCode(spec); return(_compiler.CompileInMemory(sourceCode, spec.Assemblies)); }