本文整理汇总了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);
}
示例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);
}
}
示例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);
}
示例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);
//.........这里部分代码省略.........
示例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();
}
示例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);
}