当前位置: 首页>>代码示例>>C#>>正文


C# ICompilation.GetAllTypeDefinitions方法代码示例

本文整理汇总了C#中ICompilation.GetAllTypeDefinitions方法的典型用法代码示例。如果您正苦于以下问题:C# ICompilation.GetAllTypeDefinitions方法的具体用法?C# ICompilation.GetAllTypeDefinitions怎么用?C# ICompilation.GetAllTypeDefinitions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ICompilation的用法示例。


在下文中一共展示了ICompilation.GetAllTypeDefinitions方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateEmulator

		protected OOPEmulator CreateEmulator(ICompilation compilation, IErrorReporter errorReporter = null) {
			var n = new Namer();
			errorReporter = errorReporter ?? new MockErrorReporter();
			var md = new MetadataImporter(errorReporter, compilation, new CompilerOptions());
			md.Prepare(compilation.GetAllTypeDefinitions());
			var rtl = new RuntimeLibrary(md, errorReporter, compilation, n);
			return new OOPEmulator(compilation, md, rtl, n, new MockLinker(), errorReporter);
		}
开发者ID:chenxustu1,项目名称:SaltarelleCompiler,代码行数:8,代码来源:OOPEmulatorTestBase.cs

示例2: RunAutomaticMetadataAttributeAppliers

		private void RunAutomaticMetadataAttributeAppliers(IAttributeStore store, ICompilation compilation) {
			var processors = new IAutomaticMetadataAttributeApplier[] { new MakeMembersWithScriptableAttributesReflectable(store) };
			foreach (var p in processors) {
				foreach (var asm in compilation.Assemblies)
					p.Process(asm);
				foreach (var t in compilation.GetAllTypeDefinitions())
					p.Process(t);
			}
		}
开发者ID:ShuntaoChen,项目名称:SaltarelleCompiler,代码行数:9,代码来源:MetadataImporterTestBase.cs

示例3: Compile

        public IEnumerable<JsType> Compile(PreparedCompilation compilation)
        {
            _compilation = compilation.Compilation;

            _metadataImporter.Prepare(_compilation.GetAllTypeDefinitions(), _compilation.MainAssembly, _errorReporter);

            _types = new Dictionary<ITypeDefinition, JsClass>();
            _constructorDeclarations = new HashSet<Tuple<ConstructorDeclaration, CSharpAstResolver>>();
            _instanceInitStatements = new Dictionary<JsClass, List<JsStatement>>();

            var unsupportedConstructsScanner = new UnsupportedConstructsScanner(_errorReporter, compilation.Compilation.ReferencedAssemblies.Count == 0);
            bool hasUnsupported = false;

            foreach (var f in compilation.SourceFiles) {
                try {
                    if (!AllowUnsupportedConstructs) {
                        if (!unsupportedConstructsScanner.ProcessAndReturnTrueIfEverythingIsSupported(f.SyntaxTree)) {
                            hasUnsupported = true;
                            continue;
                        }
                    }
                    _definedSymbols = f.DefinedSymbols;

                    _resolver = new CSharpAstResolver(_compilation, f.SyntaxTree, f.ParsedFile);
                    _resolver.ApplyNavigator(new ResolveAllNavigator());
                    f.SyntaxTree.AcceptVisitor(this);
                }
                catch (Exception ex) {
                    _errorReporter.Region = _currentNode.GetRegion();
                    _errorReporter.InternalError(ex);
                }
            }

            if (hasUnsupported)
                return new JsType[0];	// Just to be safe

            // Handle constructors. We must do this after we have visited all the compilation units because field initializer (which change the InstanceInitStatements and StaticInitStatements) might appear anywhere.
            foreach (var n in _constructorDeclarations) {
                try {
                    _resolver = n.Item2;
                    HandleConstructorDeclaration(n.Item1);
                }
                catch (Exception ex) {
                    _errorReporter.Region = n.Item1.GetRegion();
                    _errorReporter.InternalError(ex);
                }
            }

            // Add default constructors where needed.
            foreach (var toAdd in _types.Where(t => t.Value != null).SelectMany(kvp => kvp.Key.GetConstructors().Where(c => c.IsSynthetic).Select(c => new { jsClass = kvp.Value, c }))) {
                try {
                    MaybeAddDefaultConstructorToType(toAdd.jsClass, toAdd.c);
                }
                catch (Exception ex) {
                    _errorReporter.Region = toAdd.c.Region;
                    _errorReporter.InternalError(ex, "Error adding default constructor to type");
                }
            }

            _types.Values.Where(t => t != null).ForEach(t => t.Freeze());

            var enums = new List<JsType>();
            foreach (var e in _compilation.MainAssembly.TopLevelTypeDefinitions.SelectMany(SelfAndNested).Where(t => t.Kind == TypeKind.Enum)) {
                try {
                    enums.Add(ConvertEnum(e.GetDefinition()));
                }
                catch (Exception ex) {
                    _errorReporter.Region = e.GetDefinition().Region;
                    _errorReporter.InternalError(ex);
                }
            }

            return _types.Values.Concat(enums).Where(t => t != null);
        }
开发者ID:jack128,项目名称:SaltarelleCompiler,代码行数:74,代码来源:Compiler.cs

示例4: Analyze

		public ReadOnlyCollection<AssemblyNode> Analyze()
		{
			IUnresolvedAssembly[] loadedAssemblies = LoadAssemblies().ToArray();
			compilation = new SimpleCompilation(loadedAssemblies.First(), loadedAssemblies.Skip(1));
			
			assemblyMappings = new Dictionary<IAssembly, AssemblyNode>();
			namespaceMappings = new Dictionary<string, NamespaceNode>();
			typeMappings = new Dictionary<ITypeDefinition, TypeNode>();
			fieldMappings = new Dictionary<IField, FieldNode>();
			methodMappings = new Dictionary<IMethod, MethodNode>();
			propertyMappings = new Dictionary<IProperty, PropertyNode>();
			eventMappings = new Dictionary<IEvent, EventNode>();
			cecilMappings = new Dictionary<MemberReference, IEntity>();
			
			// first we have to read all types so every method, field or property has a container
			foreach (var type in compilation.GetAllTypeDefinitions()) {
				var tn = ReadType(type);
				
				foreach (var field in type.Fields) {
					var node = new FieldNode(field);
					fieldMappings.Add(field, node);
					var cecilObj = loader.GetCecilObject((IUnresolvedField)field.UnresolvedMember);
					if (cecilObj != null)
						cecilMappings[cecilObj] = field;
					tn.AddChild(node);
				}
				
				foreach (var method in type.Methods) {
					var node = new MethodNode(method);
					methodMappings.Add(method, node);
					var cecilObj = loader.GetCecilObject((IUnresolvedMethod)method.UnresolvedMember);
					if (cecilObj != null)
						cecilMappings[cecilObj] = method;
					tn.AddChild(node);
				}
				
				foreach (var property in type.Properties) {
					var node = new PropertyNode(property);
					propertyMappings.Add(property, node);
					var cecilPropObj = loader.GetCecilObject((IUnresolvedProperty)property.UnresolvedMember);
					if (cecilPropObj != null)
						cecilMappings[cecilPropObj] = property;
					if (property.CanGet) {
						var cecilMethodObj = loader.GetCecilObject((IUnresolvedMethod)property.Getter.UnresolvedMember);
						if (cecilMethodObj != null)
							cecilMappings[cecilMethodObj] = property;
					}
					if (property.CanSet) {
						var cecilMethodObj = loader.GetCecilObject((IUnresolvedMethod)property.Setter.UnresolvedMember);
						if (cecilMethodObj != null)
							cecilMappings[cecilMethodObj] = property;
					}
					tn.AddChild(node);
				}
				
				foreach (var @event in type.Events) {
					var node = new EventNode(@event);
					eventMappings.Add(@event, node);
					var cecilObj = loader.GetCecilObject((IUnresolvedEvent)@event.UnresolvedMember);
					if (cecilObj != null)
						cecilMappings[cecilObj] = @event;
					if (@event.CanAdd) {
						var cecilMethodObj = loader.GetCecilObject((IUnresolvedMethod)@event.AddAccessor.UnresolvedMember);
						if (cecilMethodObj != null)
							cecilMappings[cecilMethodObj] = @event;
					}
					if (@event.CanInvoke) {
						var cecilMethodObj = loader.GetCecilObject((IUnresolvedMethod)@event.InvokeAccessor.UnresolvedMember);
						if (cecilMethodObj != null)
							cecilMappings[cecilMethodObj] = @event;
					}
					if (@event.CanRemove) {
						var cecilMethodObj = loader.GetCecilObject((IUnresolvedMethod)@event.RemoveAccessor.UnresolvedMember);
						if (cecilMethodObj != null)
							cecilMappings[cecilMethodObj] = @event;
					}
					tn.AddChild(node);
				}
			}
			
			ILAnalyzer analyzer = new ILAnalyzer(loadedAssemblies.Select(asm => loader.GetCecilObject(asm)).ToArray(), this);
			int count = typeMappings.Count + methodMappings.Count + fieldMappings.Count + propertyMappings.Count;
			int i  = 0;
			
			foreach (var element in typeMappings) {
				ReportProgress(++i / (double)count);
				AddRelationshipsForTypes(element.Key.DirectBaseTypes, element.Value);
				AddRelationshipsForAttributes(element.Key.Attributes, element.Value);
				CreateEdges(element.Value);
			}
			
			foreach (var element in methodMappings) {
				ReportProgress(++i / (double)count);
				var cecilObj = loader.GetCecilObject((IUnresolvedMethod)element.Key.UnresolvedMember);
				if (cecilObj != null)
					analyzer.Analyze(cecilObj.Body, element.Value);
				var node = element.Value;
				var method = element.Key;
				AddRelationshipsForType(node, method.ReturnType);
				AddRelationshipsForAttributes(method.Attributes, node);
//.........这里部分代码省略.........
开发者ID:nylen,项目名称:SharpDevelop,代码行数:101,代码来源:AssemblyAnalyzer.cs

示例5: InitializeAttributeStore

		private void InitializeAttributeStore(AttributeStore attributeStore, WindsorContainer container, ICompilation compilation) {
			var assemblies = compilation.Assemblies;
			var types = compilation.GetAllTypeDefinitions().ToList();
			foreach (var applier in container.ResolveAll<IAutomaticMetadataAttributeApplier>()) {
				foreach (var a in assemblies)
					applier.Process(a);
				foreach (var t in types)
					applier.Process(t);
			}
			attributeStore.RunAttributeCode();
		}
开发者ID:ShuntaoChen,项目名称:SaltarelleCompiler,代码行数:11,代码来源:CompilerDriver.cs

示例6: Prepare

        private void Prepare(string source, IRuntimeLibrary runtimeLibrary = null, bool expectErrors = false, bool MinimizeNames = false)
        {
            IProjectContent project = new CSharpProjectContent();
            var parser = new CSharpParser();

            using (var rdr = new StringReader(source)) {
                var pf = new CSharpUnresolvedFile() { FileName = "File.cs" };
                var syntaxTree = parser.Parse(rdr, pf.FileName);
                syntaxTree.AcceptVisitor(new TypeSystemConvertVisitor(pf));
                project = project.AddOrUpdateFiles(pf);
            }
            project = project.AddAssemblyReferences(new[] { Files.Mscorlib, Files.Web, Files.Knockout });

            _compilation = project.CreateCompilation();

            var options = new CompilerOptions { MinimizeScript = MinimizeNames };
            _errorReporter = new MockErrorReporter(!expectErrors);
            var s = new AttributeStore(_compilation, _errorReporter);
            s.RunAttributeCode();
            _metadata = new MetadataImporter(_errorReporter, _compilation, s, options);

            _metadata.Prepare(_compilation.GetAllTypeDefinitions());

            _allErrors = _errorReporter.AllMessages.ToList().AsReadOnly();
            if (expectErrors) {
                Assert.That(_allErrors, Is.Not.Empty, "Compile should have generated errors");
            }
            else {
                Assert.That(_allErrors, Is.Empty, "Compile should not generate errors");
            }

            var rtl = new RuntimeLibrary(_metadata, _errorReporter, _compilation, new Namer(), s);
        }
开发者ID:Saltarelle,项目名称:SaltarelleKnockout,代码行数:33,代码来源:AttributeTests.cs


注:本文中的ICompilation.GetAllTypeDefinitions方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。