/// <summary> /// Imports a namespace from another compilation. /// </summary> /// <remarks> /// This method may return null if the namespace does not exist in the target compilation. /// </remarks> public static INamespace Import(this ICompilation compilation, INamespace ns) { if (compilation == null) { throw new ArgumentNullException("compilation"); } if (ns == null) { return(null); } if (ns.ParentNamespace == null) { // root namespace return(compilation.GetNamespaceForExternAlias(ns.ExternAlias)); } else { INamespace parent = Import(compilation, ns.ParentNamespace); if (parent != null) { return(parent.GetChildNamespace(ns.Name)); } else { return(null); } } }
protected override void GetElementCompletions(CompletionDataList list) { base.GetElementCompletions(list); var database = GetDb(); if (database == null) { return; } IType type = database.LookupType("System.Windows", "DependencyObject"); if (type == null) { return; } foreach (string namespc in namespaces) { INamespace ns = database.RootNamespace; foreach (var sn in namespc.Split('.')) { ns = ns.GetChildNamespace(sn); } foreach (IType t in ListControlClasses(database, ns)) { list.Add(t.Name, Gtk.Stock.GoForward, t.GetDefinition().Documentation); } } }
public static INamespace FindDescendantNamespace(this INamespace ns, string nsName) { var xs = nsName.Split('.'); foreach (var x in xs) { ns = ns?.GetChildNamespace(x); } return(ns); }
public ISymbol Resolve(ITypeResolveContext context) { string[] parts = fullName.Split('.'); INamespace parent = context.Compilation.GetNamespaceForExternAlias(externAlias); int i = 0; while (i < parts.Length && parent != null) { parent = parent.GetChildNamespace(parts[i]); i++; } return(parent); }
public ISymbol Resolve(ITypeResolveContext context) { IAssembly assembly = assemblyReference.Resolve(context); INamespace parent = assembly.RootNamespace; string[] parts = fullName.Split('.'); int i = 0; while (i < parts.Length && parent != null) { parent = parent.GetChildNamespace(parts[i]); i++; } return(parent); }
Expression LookInUsingScopeNamespace(ResolveContext rc, ResolvedUsingScope usingScope, INamespace n, string identifier, IList <IType> typeArguments, bool parameterizeResultType) { if (n == null) { return(null); } // first look for a namespace int k = typeArguments.Count; if (k == 0) { INamespace childNamespace = n.GetChildNamespace(identifier); if (childNamespace != null) { if (usingScope != null && usingScope.HasAlias(identifier)) { rc.Report.Error(7, loc, "The name `{0}' is ambigious", name); return(new TypeExpression((IType) new UnknownTypeSpec(null, identifier), Location)); // ambigious } return(new AliasNamespace(childNamespace, Location)); } } // then look for a type ITypeDefinition def = n.GetTypeDefinition(identifier, k); if (def != null) { IType result = def; if (parameterizeResultType && k > 0) { result = new ParameterizedTypeSpec(def, typeArguments); } if (usingScope != null && usingScope.HasAlias(identifier)) { rc.Report.Error(7, loc, "The name `{0}' is ambigious", name); return(new TypeExpression((IType) new UnknownTypeSpec(null, identifier), Location)); // ambigious } else { return(new TypeExpression(result, Location)); } } return(null); }
ResolveResult LookInUsingScopeNamespace(ResolvedUsingScope usingScope, INamespace n, string identifier, IList<IType> typeArguments, bool parameterizeResultType) { if (n == null) return null; // first look for a namespace int k = typeArguments.Count; if (k == 0) { INamespace childNamespace = n.GetChildNamespace(identifier); if (childNamespace != null) { if (usingScope != null && usingScope.HasAlias(identifier)) return new AmbiguousTypeResolveResult(new UnknownType(null, identifier)); return new NamespaceResolveResult(childNamespace); } } // then look for a type ITypeDefinition def = n.GetTypeDefinition(identifier, k); if (def != null) { IType result = def; if (parameterizeResultType && k > 0) { result = new ParameterizedType(def, typeArguments); } if (usingScope != null && usingScope.HasAlias(identifier)) return new AmbiguousTypeResolveResult(result); else return new TypeResolveResult(result); } return null; }
/// <summary> /// Imports a symbol from another compilation. /// </summary> public static ISymbol Import(this ICompilation compilation, ISymbol symbol) { if (compilation == null) { throw new ArgumentNullException("compilation"); } if (symbol == null) { return(null); } switch (symbol.SymbolKind) { case SymbolKind.TypeParameter: return((ITypeParameter)Import(compilation, (IType)symbol)); case SymbolKind.Variable: IVariable v = (IVariable)symbol; return(new DefaultVariable( Import(compilation, v.Type), v.Name, v.Region, v.IsConst, v.ConstantValue )); case SymbolKind.Parameter: IParameter p = (IParameter)symbol; if (p.Owner != null) { int index = p.Owner.Parameters.IndexOf(p); var owner = (IParameterizedMember)Import(compilation, p.Owner); if (owner == null || index < 0 || index >= owner.Parameters.Count) { return(null); } return(owner.Parameters[index]); } else { return(new DefaultParameter( Import(compilation, p.Type), p.Name, null, p.Region, null, p.IsRef, p.IsOut, p.IsParams )); } case SymbolKind.Namespace: INamespace ns = (INamespace)symbol; if (ns.ParentNamespace == null) { return(compilation.RootNamespace); } else { INamespace importedParent = Import(compilation, ns.ParentNamespace); if (importedParent != null) { return(importedParent.GetChildNamespace(ns.Name)); } else { return(null); } } default: if (symbol is IEntity) { return(Import(compilation, (IEntity)symbol)); } throw new NotSupportedException("Unsupported symbol kind: " + symbol.SymbolKind); } }