private TypeEntry RegisterCilType(TypeDefinition type, TypeEnvironment typeEnvironment) { var typeFullName = type.GetCompatibleFullName(); if (typeEnvironment.ContainsType(typeFullName)) { return(typeEnvironment[typeFullName]); } // Gets all the classes from which the input class inherits. var baseClasses = type.Interfaces.Select(i => i.InterfaceType).Append(type.BaseType); var baseInstanceFields = new List <FieldIdentifier>(); var baseStaticFields = new List <FieldIdentifier>(); var baseSupers = new List <string>(); var baseTypes = new List <string>(); // Aggregates the instance and static fields, the super foreach (var baseClass in baseClasses) { if (baseClass != null) { try { var resolvedBaseClass = baseClass.Resolve(); if (resolvedBaseClass != null) { var baseTypeEntry = RegisterCilType(resolvedBaseClass, typeEnvironment); baseInstanceFields.AddRange(baseTypeEntry.TypeStruct.InstanceFields); baseStaticFields.AddRange(baseTypeEntry.TypeStruct.StaticFields); baseSupers.AddRange(baseTypeEntry.TypeStruct.Supers.Select(s => s.Name)); baseTypes.Add(baseClass.GetCompatibleFullName()); } } catch { continue; } } } var allFields = type.Fields.Select( f => (f.IsStatic, Field: new FieldIdentifier(f.GetCompatibleFullName(), Typ.FromTypeReference(f.FieldType)))); var instanceFields = allFields .Where(f => !f.IsStatic) .Select(f => f.Field) .Concat(baseInstanceFields); var staticFields = allFields .Where(f => f.IsStatic) .Select(f => f.Field) .Concat(baseStaticFields); var procNames = type.Methods.Select(m => new ProcedureName(m)); var typeStruct = new Struct(instanceFields, staticFields, baseSupers.Concat(baseTypes), procNames); var typeEntry = new TypeEntry { TypeName = TypeName.FromTypeReference(type), TypeStruct = typeStruct, }; typeEnvironment[typeFullName] = typeEntry; return(typeEntry); }