private void InitRecursively(INamedTypeSymbol typeSym) { string key = ClassInfo.GetFullName(typeSym); if (!m_ClassSymbols.ContainsKey(key)) { ClassSymbolInfo csi = new ClassSymbolInfo(); m_ClassSymbols.Add(key, csi); csi.Init(typeSym, m_Compilation, this); } foreach (var newSym in typeSym.GetTypeMembers()) { InitRecursively(newSym); } }
internal void Init(INamedTypeSymbol typeSym, CSharpCompilation compilation, SymbolTable symTable) { if (typeSym.TypeKind == TypeKind.Error) { Logger.Instance.ReportIllegalType(typeSym); return; } IsInterface = typeSym.TypeKind == TypeKind.Interface; foreach (var intf in typeSym.AllInterfaces) { string key = ClassInfo.GetFullName(intf); ClassSymbolInfo isi; if (!symTable.ClassSymbols.TryGetValue(key, out isi)) { isi = new ClassSymbolInfo(); symTable.ClassSymbols.Add(key, isi); isi.Init(intf, compilation, symTable); } } ClassKey = ClassInfo.GetFullName(typeSym); BaseClassKey = ClassInfo.GetFullName(typeSym.BaseType); if (BaseClassKey == "System.Object" || BaseClassKey == "System.ValueType") { BaseClassKey = string.Empty; } ExistConstructor = false; ExistStaticConstructor = false; if (typeSym.GetAttributes().Length > 0) { ExistAttributes = true; } Dictionary <string, int> memberCounts = new Dictionary <string, int>(); SymbolTable.Instance.CalcMemberCount(ClassKey, memberCounts); bool fieldUseExplicitTypeParams = false; bool staticUseExplicitTypeParams = false; TypeSymbol = typeSym; var members = typeSym.GetMembers(); foreach (var sym in members) { var fsym = sym as IFieldSymbol; if (null != fsym) { FieldSymbols.Add(fsym); if (fsym.GetAttributes().Length > 0) { ExistAttributes = true; } CheckFieldUseExplicitTypeParam(fsym, compilation, ref fieldUseExplicitTypeParams, ref staticUseExplicitTypeParams); } } foreach (var sym in members) { var msym = sym as IMethodSymbol; if (null != msym) { if (msym.MethodKind == MethodKind.Constructor && !msym.IsImplicitlyDeclared) { ExistConstructor = true; } else if (msym.MethodKind == MethodKind.StaticConstructor && !msym.IsImplicitlyDeclared) { ExistStaticConstructor = true; } MethodSymbols.Add(msym); if (msym.GetAttributes().Length > 0) { ExistAttributes = true; } string name = msym.Name; if (name[0] == '.') { name = name.Substring(1); } bool isOverloaded; int count; if (msym.MethodKind == MethodKind.Constructor && msym.ContainingType.IsValueType) { //值类型构造都按重载处理,总是会生成一个默认构造 isOverloaded = true; } else if (memberCounts.TryGetValue(name, out count)) { isOverloaded = count > 1; } else { isOverloaded = false; } if (!SymbolOverloadFlags.ContainsKey(name)) { SymbolOverloadFlags.Add(name, isOverloaded); } else { SymbolOverloadFlags[name] = isOverloaded; } continue; } var psym = sym as IPropertySymbol; if (null != psym && !psym.IsIndexer) { PropertySymbols.Add(psym); if (psym.GetAttributes().Length > 0) { ExistAttributes = true; } continue; } var esym = sym as IEventSymbol; if (null != esym) { EventSymbols.Add(esym); if (esym.GetAttributes().Length > 0) { ExistAttributes = true; } continue; } } BuildInterfaceInfo(typeSym, compilation, symTable); }