Beispiel #1
0
        private EntityInfo EntityParse(string entityFilePath, ProjectInfo projectInfo)
        {
            string sourceText = File.ReadAllText(entityFilePath);

            SyntaxTree tree = CSharpSyntaxTree.ParseText(sourceText);

            CompilationUnitSyntax root = tree.GetCompilationUnitRoot();
            string @namespace          = root.DescendantNodes().OfType <NamespaceDeclarationSyntax>().Single().Name.ToString();//不满足项目命名空间
            ClassDeclarationSyntax classDeclarationSyntax = root.DescendantNodes().OfType <ClassDeclarationSyntax>().Single();
            string            className         = classDeclarationSyntax.Identifier.ToString();
            BaseListSyntax    baseList          = classDeclarationSyntax.BaseList;
            GenericNameSyntax genericNameSyntax = baseList.DescendantNodes().OfType <SimpleBaseTypeSyntax>()
                                                  .First(node => !node.ToFullString().StartsWith("I")) // Not interface
                                                  .DescendantNodes().OfType <GenericNameSyntax>()
                                                  .FirstOrDefault();

            string baseType;
            string primaryKey;

            if (genericNameSyntax == null)
            {
                // No generic parameter -> Entity with Composite Keys
                baseType   = baseList.DescendantNodes().OfType <SimpleBaseTypeSyntax>().Single().Type.ToString();
                primaryKey = "long";
            }
            else
            {
                // Normal entity
                baseType   = genericNameSyntax.Identifier.ToString();
                primaryKey = genericNameSyntax.DescendantNodes().OfType <TypeArgumentListSyntax>().Single().Arguments[0].ToString();
            }
            List <PropertyInfo> properties = root.DescendantNodes().OfType <PropertyDeclarationSyntax>()
                                             .Select(prop =>

                                                     new PropertyInfo(prop.Type.ToString(), prop.Identifier.Value.ToString())
                                                     )
                                             .ToList();

            string xmlPath      = _settingOptions.BaseDirectory + projectInfo.FullName + ".Core.xml";
            string entityRemark = Util.GetEntityRemarkBySummary(xmlPath, properties, @namespace + "." + className);


            if (_settingOptions.Areas != null)
            {
                @namespace = projectInfo.FullName + "." + _settingOptions.Areas + "." + className.Pluralize();
            }
            else
            {
                @namespace = projectInfo.FullName + "." + className.Pluralize();
            }
            string relativeDirectory = @namespace.RemovePreFix(projectInfo.FullName + ".").Replace('.', '/');

            EntityInfo entityInfo = new EntityInfo(@namespace, className, baseType, primaryKey, relativeDirectory);

            entityInfo.Properties.AddRange(properties);
            entityInfo.EntityRemark = entityRemark;

            return(entityInfo);
        }
Beispiel #2
0
        private void ProcessBaseType(BaseListSyntax baseList)
        {
            var baseType   = baseList.DescendantNodes().First().ToString();
            var references = baseList.DescendantNodes().OfType <IdentifierNameSyntax>().ToList();

            var matchingInputs =
                references
                .Select(x =>
                        TryMatchInput(x, out var input)
                    ? input : null
                        )
                .Where(x => x != null);

            foreach (var matchingInput in matchingInputs)
            {
                AddDependency(matchingInput, DependencyKind.BaseClass);
            }
        }