private MemberSymbol CreateGenericMember(MemberSymbol templateMember, IList <TypeSymbol> typeArguments) { TypeSymbol parentType = (TypeSymbol)templateMember.Parent; TypeSymbol instanceAssociatedType; if (templateMember.AssociatedType.Type == SymbolType.GenericParameter) { GenericParameterSymbol genericParameter = (GenericParameterSymbol)templateMember.AssociatedType; instanceAssociatedType = typeArguments[genericParameter.Index]; } else { instanceAssociatedType = typeArguments[0]; } if (templateMember.Type == SymbolType.Indexer) { IndexerSymbol templateIndexer = (IndexerSymbol)templateMember; IndexerSymbol instanceIndexer = new IndexerSymbol(parentType, instanceAssociatedType); if (templateIndexer.UseScriptIndexer) { instanceIndexer.SetScriptIndexer(); } instanceIndexer.SetVisibility(templateIndexer.Visibility); return(instanceIndexer); } if (templateMember.Type == SymbolType.Property) { PropertySymbol templateProperty = (PropertySymbol)templateMember; PropertySymbol instanceProperty = new PropertySymbol(templateProperty.Name, parentType, instanceAssociatedType); if (templateProperty.IsTransformed) { instanceProperty.SetTransformedName(templateProperty.GeneratedName); } instanceProperty.SetNameCasing(templateProperty.IsCasePreserved); instanceProperty.SetVisibility(templateProperty.Visibility); return(instanceProperty); } if (templateMember.Type == SymbolType.Field) { FieldSymbol templateField = (FieldSymbol)templateMember; FieldSymbol instanceField = new FieldSymbol(templateField.Name, parentType, instanceAssociatedType); if (templateField.IsTransformed) { instanceField.SetTransformName(templateField.GeneratedName); } instanceField.SetNameCasing(templateField.IsCasePreserved); instanceField.SetVisibility(templateField.Visibility); return(instanceField); } if (templateMember.Type == SymbolType.Method) { MethodSymbol templateMethod = (MethodSymbol)templateMember; MethodSymbol instanceMethod = new MethodSymbol(templateMethod.Name, parentType, instanceAssociatedType); if (templateMethod.IsAliased) { instanceMethod.SetTransformedName(templateMethod.TransformName); } else if (templateMethod.IsTransformed) { instanceMethod.SetTransformedName(templateMethod.GeneratedName); } if (templateMethod.SkipGeneration) { instanceMethod.SetSkipGeneration(); } if (templateMethod.InterfaceMember != null) { instanceMethod.SetInterfaceMember(templateMethod.InterfaceMember); } instanceMethod.SetNameCasing(templateMethod.IsCasePreserved); instanceMethod.SetVisibility(templateMethod.Visibility); return(instanceMethod); } Debug.Fail("Unexpected generic member '" + templateMember.Name + " on type '" + ((TypeSymbol)templateMember.Parent).FullName + "'."); return(null); }
public Symbol FindSymbol(string name, Symbol context, SymbolFilter filter) { if ((filter & SymbolFilter.Types) == 0) { return(null); } Symbol symbol = null; if (name.IndexOf('.') > 0) { symbol = FindSymbolFromNamespace(name, context); } else { Debug.Assert(context != null); if (context is MethodSymbol methodContext) { GenericParameterSymbol genericType = FindGenericType(name, methodContext); if (genericType != null) { return(genericType); } } TypeSymbol typeSymbol = context as TypeSymbol; if (typeSymbol == null) { Symbol parentSymbol = context.Parent; while (parentSymbol != null) { typeSymbol = parentSymbol as TypeSymbol; if (typeSymbol != null) { break; } parentSymbol = parentSymbol.Parent; } } Debug.Assert(typeSymbol != null); if (typeSymbol == null) { return(null); } if (typeSymbol.IsGeneric) { var resolved = typeSymbol.GenericParameters.FirstOrDefault(param => param.Name == name); if (resolved != null) { return(resolved); } } bool systemNamespaceChecked = false; NamespaceSymbol containerNamespace = (NamespaceSymbol)typeSymbol.Parent; Debug.Assert(containerNamespace != null); symbol = ((ISymbolTable)containerNamespace).FindSymbol(name, /* context */ typeSymbol, SymbolFilter.Types); if (containerNamespace == SystemNamespace) { systemNamespaceChecked = true; } if (symbol == null) { if (typeSymbol.Aliases != null && typeSymbol.Aliases.ContainsKey(name)) { string typeReference = typeSymbol.Aliases[name]; symbol = ((ISymbolTable)this).FindSymbol(typeReference, /* context */ null, SymbolFilter.Types); } else if (typeSymbol.Imports != null) { foreach (string importedNamespaceReference in typeSymbol.Imports) { if (namespaceMap.ContainsKey(importedNamespaceReference) == false) { // Since we included all parent namespaces of the current type's // namespace, we might run into a namespace that doesn't contain // any defined types, i.e. doesn't exist. continue; } NamespaceSymbol importedNamespace = namespaceMap[importedNamespaceReference]; if (importedNamespace == containerNamespace) { continue; } symbol = ((ISymbolTable)importedNamespace).FindSymbol(name, /* context */ null, SymbolFilter.Types); if (importedNamespace == SystemNamespace) { systemNamespaceChecked = true; } if (symbol != null) { break; } } } } if (symbol == null && systemNamespaceChecked == false) { symbol = ((ISymbolTable)SystemNamespace).FindSymbol(name, /* context */ null, SymbolFilter.Types); } if (symbol == null) { symbol = ((ISymbolTable)GlobalNamespace).FindSymbol(name, /* context */ null, SymbolFilter.Types); } } return(symbol); }