示例#1
0
        protected TypeData(IDataEngine engine, TypeDeclarationSyntax declarationsyntax)
        {
            Engine                       = engine;
            NAME                         = declarationsyntax.Identifier.ToString();
            GenericsParameters           = declarationsyntax.TypeParameterList.GetGenerics();
            WIDENAME                     = declarationsyntax.WideName();
            Engine.AllTypeData[WIDENAME] = this;
            Declarations.Add(declarationsyntax);

            NAMESPACE = declarationsyntax.FirstAncestorOrSelf <NamespaceDeclarationSyntax>().Name.ToString();
            Usings    = declarationsyntax.FirstAncestorOrSelf <CompilationUnitSyntax>().Usings
                        .Select(u => u.Name.ToString()).ToArray();
            SemanticModel = Engine.SemanticModel(declarationsyntax.SyntaxTree);
            Symbol        = SemanticModel.GetDeclaredSymbol(declarationsyntax);
            Declarations.AddRange(Symbol.DeclaringSyntaxReferences.Select(r => r.GetSyntax())
                                  .OfType <TypeDeclarationSyntax>().Where(d => d != declarationsyntax));
            Modifier      = Declarations.SelectMany(d => d.Modifiers).Select(m => m.Text).Distinct().ToArray();
            Inheritance   = Declarations.SelectMany(d => d.ChildNodes()).OfType <BaseListSyntax>().SelectMany(b => b.Types.Select(t => t.Type.ToString())).Distinct().ToArray();
            Properties    = new Dictionary <string, IPropertyData>();
            Methods       = new Dictionary <string, IMethodData>();
            Events        = new Dictionary <string, IEventData>();
            PropertiesAll = new Dictionary <string, IPropertyData>();
            MethodsAll    = new Dictionary <string, IMethodData>();
            EventsAll     = new Dictionary <string, IEventData>();

            var attls = declarationsyntax.AttributeLists;
            var att   = new List <IAttrData>();
            var lst   = new List <string>();

            foreach (var lista in attls)
            {
                lst.Add(lista.ToString());
                foreach (var a in lista.Attributes)
                {
                    att.Add(new AttrData(a));
                }
            }

            AttributesData  = att.ToArray();
            AttributesLists = lst.ToArray();



            foreach (var child in Declarations.SelectMany(d => d.ChildNodes()))
            {
                switch (child)
                {
                case PropertyDeclarationSyntax p:
                    if (!Properties.ContainsKey(p.Identifier.ToString()))
                    {
                        Properties.Add(p.Identifier.ToString(), new PropertyData(p));
                    }
                    break;

                case EventDeclarationSyntax ev:
                    if (!Events.ContainsKey(ev.Identifier.ToString()))
                    {
                        Events.Add(ev.Identifier.ToString(), new EventData(ev));
                    }
                    break;

                case MethodDeclarationSyntax m:
                    if (!Methods.ContainsKey(m.Identifier.ToString()))
                    {
                        Methods.Add(m.Identifier.ToString(), new MethodData(m));
                    }
                    break;
                }
            }
            var ctype          = Symbol;
            var inheritanceall = new HashSet <INamedTypeSymbol>();

            while (ctype != null && ctype.Name != "Object")
            {
                if (ctype != Symbol)
                {
                    inheritanceall.Add(ctype);
                }
                foreach (var s in ctype.Interfaces)
                {
                    inheritanceall.Add(s);
                    foreach (var si in s.AllInterfaces)
                    {
                        inheritanceall.Add(si);
                    }
                }
                ctype = ctype.BaseType;
            }

            InheritanceAll = inheritanceall.ToArray();



            void LoadIfNotKey <V>(Dictionary <string, V> dic, KeyValuePair <string, V> p)
            {
                if (!dic.ContainsKey(p.Key))
                {
                    dic[p.Key] = p.Value;
                }
            }

            foreach (var p in Properties)
            {
                LoadIfNotKey(PropertiesAll, p);
            }
            foreach (var e in Events)
            {
                LoadIfNotKey(EventsAll, e);
            }
            foreach (var m in Methods)
            {
                LoadIfNotKey(MethodsAll, m);
            }
            foreach (var sub in InheritanceAll)
            {
                var subvalue = Engine.GetRecordForSymbol(sub.Name);
                if (subvalue == null)
                {
                    continue;
                }
                foreach (var p in subvalue.Properties)
                {
                    LoadIfNotKey(PropertiesAll, p);
                }
                foreach (var e in subvalue.Events)
                {
                    LoadIfNotKey(EventsAll, e);
                }
                foreach (var m in subvalue.Methods)
                {
                    LoadIfNotKey(MethodsAll, m);
                }
            }
            InheritanceLoaded = true;
        }
示例#2
0
 public Compilation(IEnumerable <Declaration> declarations, RoutineDeclaration anonymous)
 {
     Declarations.AddRange(declarations);
     Anonymous = anonymous;
 }