/// <summary> /// Creates a new TypeSystemConvertVisitor. /// </summary> /// <param name="fileName">The file name (used for DomRegions).</param> public TypeSystemConvertVisitor(string fileName) { if (fileName == null) throw new ArgumentNullException("fileName"); this.parsedFile = new CSharpParsedFile(fileName); this.usingScope = parsedFile.RootUsingScope; }
public ResolvedUsingScope(CSharpTypeResolveContext context, UsingScope usingScope) { if (context == null) { throw new ArgumentNullException("context"); } if (usingScope == null) { throw new ArgumentNullException("usingScope"); } this.parentContext = context; this.usingScope = usingScope; if (usingScope.Parent != null) { if (context.CurrentUsingScope == null) { throw new InvalidOperationException(); } } else { if (context.CurrentUsingScope != null) { throw new InvalidOperationException(); } } }
public static void AddUsings(CodeElementsList<CodeElement> codeElements, UsingScope usingScope, ICompilation compilation) { var resolvedUsingScope = usingScope.Resolve(compilation); foreach (var ns in resolvedUsingScope.Usings) { codeElements.Add(new CodeImport(ns.FullName)); } }
/// <summary> /// Creates a new TypeSystemConvertVisitor and initializes it with a given context. /// </summary> /// <param name="parsedFile">The parsed file to which members should be added.</param> /// <param name="currentUsingScope">The current using scope.</param> /// <param name="currentTypeDefinition">The current type definition.</param> public TypeSystemConvertVisitor(CSharpParsedFile parsedFile, UsingScope currentUsingScope = null, CSharpUnresolvedTypeDefinition currentTypeDefinition = null) { if (parsedFile == null) throw new ArgumentNullException("parsedFile"); this.parsedFile = parsedFile; this.usingScope = currentUsingScope ?? parsedFile.RootUsingScope; this.currentTypeDefinition = currentTypeDefinition; }
public CSharpUnresolvedFile(string fileName) { if (fileName == null) { throw new ArgumentNullException("fileName"); } this.fileName = fileName; this.rootUsingScope = new UsingScope(); }
/// <summary> /// Creates a new nested using scope. /// </summary> /// <param name="parent">The parent using scope.</param> /// <param name="shortName">The short namespace name.</param> public UsingScope(UsingScope parent, string shortName) { if (parent == null) throw new ArgumentNullException("parent"); if (shortName == null) throw new ArgumentNullException("shortName"); this.parent = parent; this.shortName = shortName; }
public void AddUsings(UsingScope usingScope, ICompilation compilation) { foreach (KeyValuePair<string, TypeOrNamespaceReference> alias in usingScope.UsingAliases) { AddCodeImport(alias.Value.ToString()); } foreach (TypeOrNamespaceReference typeOrNamespace in usingScope.Usings) { AddCodeImport(typeOrNamespace.ToString()); } }
public CSharpParsedFile(string fileName, UsingScope rootUsingScope) { if (fileName == null) { throw new ArgumentNullException("fileName"); } if (rootUsingScope == null) { throw new ArgumentNullException("rootUsingScope"); } this.fileName = fileName; this.rootUsingScope = rootUsingScope; }
/// <summary> /// Creates a new nested using scope. /// </summary> /// <param name="parent">The parent using scope.</param> /// <param name="shortName">The short namespace name.</param> public UsingScope(UsingScope parent, string shortName) { if (parent == null) { throw new ArgumentNullException("parent"); } if (shortName == null) { throw new ArgumentNullException("shortName"); } this.parent = parent; this.shortName = shortName; }
public override IUnresolvedEntity VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration, object data) { DomRegion region = MakeRegion(namespaceDeclaration); UsingScope previousUsingScope = usingScope; foreach (Identifier ident in namespaceDeclaration.Identifiers) { usingScope = new UsingScope(usingScope, ident.Name); usingScope.Region = region; } base.VisitNamespaceDeclaration(namespaceDeclaration, data); parsedFile.UsingScopes.Add(usingScope); // add after visiting children so that nested scopes come first usingScope = previousUsingScope; return null; }
public CSharpUnresolvedTypeDefinition(CSharpUnresolvedTypeDefinition declaringTypeDefinition, string name) : base(declaringTypeDefinition, name) { this.usingScope = declaringTypeDefinition.usingScope; this.AddDefaultConstructorIfRequired = true; }
public CSharpUnresolvedTypeDefinition(UsingScope usingScope, string name) : base(usingScope.NamespaceName, name) { this.usingScope = usingScope; this.AddDefaultConstructorIfRequired = true; }
internal static IConstantValue ConvertConstantValue( ITypeReference targetType, AstNode expression, IUnresolvedTypeDefinition parentTypeDefinition, IUnresolvedMethod parentMethodDefinition, UsingScope parentUsingScope) { ConstantValueBuilder b = new ConstantValueBuilder(false); ConstantExpression c = expression.AcceptVisitor(b, null); if (c == null) return new ErrorConstantValue(targetType); PrimitiveConstantExpression pc = c as PrimitiveConstantExpression; if (pc != null && pc.Type == targetType) { // Save memory by directly using a SimpleConstantValue. return new SimpleConstantValue(targetType, pc.Value); } // cast to the desired type return new ConstantCast(targetType, c); }