コード例 #1
0
        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);
        }
コード例 #2
0
        public Assembly GenerateAssemblyInMemory(AssemblyGenerationSpec spec)
        {
            var sourceCode = _handlerGenerator.GetSourceCode(spec);

            return(_compiler.CompileInMemory(sourceCode, spec.Assemblies));
        }