public static void ResolvedUnresolvedMembers(Solution solution) { foreach (var project in solution.Projects) { var compilation = project.Compilation; var assemblyContext = new SimpleTypeResolveContext(compilation.MainAssembly); foreach (var typeDef in compilation.MainAssembly.GetAllTypeDefinitions()) { foreach (var part in typeDef.Parts) { if (!typeDef.Equals(part.Resolve(assemblyContext))) throw new InvalidOperationException(); } foreach (var member in IncludeAccessors(typeDef.Members)) { var resolvedMember = member.UnresolvedMember.Resolve(assemblyContext); if (!member.Equals(resolvedMember)) throw new InvalidOperationException(); } // ToMemberReference() requires an appropriate generic context if the member // contains open generics; otherwise the main context of the compilation is sufficient. ITypeResolveContext context; if (typeDef.TypeParameterCount > 0) context = new SimpleTypeResolveContext(typeDef); else context = compilation.TypeResolveContext; // Include (potentially specialized) inherited members when testing ToMemberReference() foreach (var member in IncludeAccessors(typeDef.GetMembers())) { var resolvedMember = member.ToReference().Resolve(context); if (!member.Equals(resolvedMember)) throw new InvalidOperationException(); } } } }
string GetString (Ambience amb, IUnresolvedEntity x) { var ctx = new SimpleTypeResolveContext (Document.Compilation.MainAssembly); IEntity rx = null; if (x is IUnresolvedMember) rx = ((IUnresolvedMember)x).CreateResolved (ctx); if (tag is IUnresolvedFile) return amb.GetString (rx, OutputFlags.IncludeGenerics | OutputFlags.IncludeParameters | OutputFlags.UseFullInnerTypeName | OutputFlags.ReformatDelegates); return amb.GetString (rx, OutputFlags.IncludeGenerics | OutputFlags.IncludeParameters | OutputFlags.ReformatDelegates); }
public AnonymousType(ICompilation compilation, IList <IUnresolvedProperty> properties) { if (properties == null) { throw new ArgumentNullException("properties"); } this.compilation = compilation ?? throw new ArgumentNullException("compilation"); this.unresolvedProperties = properties.ToArray(); var context = new SimpleTypeResolveContext(compilation.MainAssembly); this.resolvedProperties = new ProjectedList <ITypeResolveContext, IUnresolvedProperty, IProperty>(context, unresolvedProperties, (c, p) => new AnonymousTypeProperty(p, c, this)); }
public void ParseReflectionName() { var context = new SimpleTypeResolveContext(compilation.MainAssembly); Assert.AreEqual("System.Int32", ReflectionHelper.ParseReflectionName("System.Int32").Resolve(context).ReflectionName); Assert.AreEqual("System.Int32&", ReflectionHelper.ParseReflectionName("System.Int32&").Resolve(context).ReflectionName); Assert.AreEqual("System.Int32*&", ReflectionHelper.ParseReflectionName("System.Int32*&").Resolve(context).ReflectionName); Assert.AreEqual("System.Int32", ReflectionHelper.ParseReflectionName(typeof(int).AssemblyQualifiedName).Resolve(context).ReflectionName); Assert.AreEqual("System.Action`1[[System.String]]", ReflectionHelper.ParseReflectionName("System.Action`1[[System.String]]").Resolve(context).ReflectionName); Assert.AreEqual("System.Action`1[[System.String]]", ReflectionHelper.ParseReflectionName("System.Action`1[[System.String, mscorlib]]").Resolve(context).ReflectionName); Assert.AreEqual("System.Int32[,,][,]", ReflectionHelper.ParseReflectionName(typeof(int[,][,,]).AssemblyQualifiedName).Resolve(context).ReflectionName); Assert.AreEqual("System.Environment+SpecialFolder", ReflectionHelper.ParseReflectionName("System.Environment+SpecialFolder").Resolve(context).ReflectionName); }
public FileCodeModel2(CodeModelContext context) { if (context == null || context.FilteredFileName == null) throw new ArgumentException("context must be restricted to a file"); this.context = context; var compilation = SD.ParserService.GetCompilation(context.CurrentProject); var projectContent = compilation.MainAssembly.UnresolvedAssembly as IProjectContent; if (projectContent != null) { IUnresolvedFile file = projectContent.GetFile(context.FilteredFileName); if (file != null) { var csharpFile = file as CSharpUnresolvedFile; if (csharpFile != null) AddUsings(codeElements, csharpFile.RootUsingScope, compilation); var resolveContext = new SimpleTypeResolveContext(compilation.MainAssembly); AddTypes(file.TopLevelTypeDefinitions .Select(td => td.Resolve(resolveContext) as ITypeDefinition) .Where(td => td != null).Distinct()); } } }
public void ArrayOfTypeParameter() { var context = new SimpleTypeResolveContext(compilation.MainAssembly); Assert.AreEqual("`0[,]", ReflectionHelper.ParseReflectionName("`0[,]").Resolve(context).ReflectionName); }
public IEnumerable<ILLocalVariable> GetLocalVariables(IMethod method) { string id = IdStringProvider.GetIdString(method.MemberDefinition); var file = GetSymbols(method); if (file == null || !file.DebugSymbols.ContainsKey(id)) return null; var symbols = file.DebugSymbols[id]; var context = new SimpleTypeResolveContext(method); var loader = new CecilLoader(); return symbols.LocalVariables.Where(v => v.OriginalVariable != null).Select( v => new Debugger.ILLocalVariable() { Index = v.OriginalVariable.Index, Type = loader.ReadTypeReference(v.Type).Resolve(context), Name = v.Name, IsCompilerGenerated = false, ILRanges = new [] { new ILRange(0, int.MaxValue) } }); }
void AddCodeElements() { ICompilation compilation = project.GetCompilationUnit(); var projectContent = compilation.MainAssembly.UnresolvedAssembly as IProjectContent; if (projectContent != null) { IUnresolvedFile file = projectContent.GetFile(context.FilteredFileName); if (file != null) { var csharpFile = file as CSharpUnresolvedFile; if (csharpFile != null) { AddUsings(csharpFile.RootUsingScope, compilation); } var resolveContext = new SimpleTypeResolveContext(compilation.MainAssembly); AddTypes( file.TopLevelTypeDefinitions .Select(td => td.Resolve(resolveContext) as ITypeDefinition) .Where(td => td != null) .Distinct()); } } }