コード例 #1
0
 public void OnMetadataReferenceRemoved(ProjectId projectId, PortableExecutableReference metadataReference) { }
コード例 #2
0
        // invoked by the PureLiveModelsFactory when it detects it needs to rebuild models
        // the factory should have notified all "pure live models" view engines that it is
        // rebuilding models, and engines should have suspended compilation, so it is safe
        // to have zero lock in this method
        public static Assembly CompileAndRegisterModels(string code)
        {
            // zero everything and increment generation
            _modelsReference = null;
            _modelsAssembly = null;
            _modelsVersionString = null;
            _modelsGeneration++;

            // we don't really need the _gen in the name since it's in the version already
            // but that helps when debugging because the name itself indicates the _gen
            var assemblyName = "__dynamic__" + _modelsGeneration + "__";
            var assemblyVersion = "0.0.0." + _modelsGeneration;

            code = code.Replace("//ASSATTR", @"[assembly:System.Reflection.AssemblyTitle(""" + assemblyName + @""")]
[assembly:System.Reflection.AssemblyVersion(""" + assemblyVersion + @""")]");

            // create the compilation
            SyntaxTree[] trees;
            var compilation = GetCompilation(assemblyName, new Dictionary<string, string> { { "code", code } }, out trees);

            // check diagnostics for errors (not warnings)
            foreach (var diag in compilation.GetDiagnostics().Where(x => x.Severity == DiagnosticSeverity.Error))
                throw new Exception(string.Format("Compilation {0}: {1}", diag.Severity, diag.GetMessage()));

            // emit
            var stream = new MemoryStream();
            compilation.Emit(stream); // should we check the result?
            var bytes = stream.GetBuffer();

            _modelsAssembly = Assembly.Load(bytes);
            _modelsVersionString = assemblyName + ", Version=" + assemblyVersion + ", Culture=neutral, PublicKeyToken=null";
            _modelsReference = MetadataReference.CreateFromImage(bytes);

            return _modelsAssembly;
        }
コード例 #3
0
ファイル: PEAssemblySymbol.cs プロジェクト: iolevel/peachpie
        internal static PEAssemblySymbol Create(PortableExecutableReference reference)
        {
            var data = (AssemblyMetadata)reference.GetMetadata();
            //var data = AssemblyMetadata.CreateFromFile(reference.FilePath);
            var ass = data.GetAssembly();

            return new PEAssemblySymbol(
                ass, DocumentationProvider.Default, true,
                IsPchpCor(ass) ? MetadataImportOptions.Internal : MetadataImportOptions.Public);
        }