当前位置: 首页>>代码示例>>C#>>正文


C# ClassDeclarationSyntax.BaseTypeExist方法代码示例

本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Syntax.ClassDeclarationSyntax.BaseTypeExist方法的典型用法代码示例。如果您正苦于以下问题:C# ClassDeclarationSyntax.BaseTypeExist方法的具体用法?C# ClassDeclarationSyntax.BaseTypeExist怎么用?C# ClassDeclarationSyntax.BaseTypeExist使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.CodeAnalysis.CSharp.Syntax.ClassDeclarationSyntax的用法示例。


在下文中一共展示了ClassDeclarationSyntax.BaseTypeExist方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetRepository

        /// <summary>
        ///     Get general info about candidate for repository
        /// </summary>
        /// <param name="doClass">Class syntax</param>
        private BaseCodeClassGeneratorRepository GetRepository(ClassDeclarationSyntax doClass)
        {
            var className = doClass.Identifier.Text;

            // Get DataAccess attribute from repository model
            var dataAccessAttr = SyntaxAnalysisHelper.GetAttributesAndPropepertiesCollection(doClass).FirstOrDefault(x => x.Name.ToString().Contains(_config.RepositoryAttributeName));

            // common repository info
            var repositoryInfo = new RepositoryInfo()
            {
                RepositorySuffix = _config.RepositorySuffix,
                ClassName = className,
                ClassFullName = _solutionSyntaxWalker.GetFullRepositoryModelName(doClass),
            };

            repositoryInfo.IsTenantRelated = !doClass.BaseTypeExist("ITenantUnrelated");

            // Base class name
            if (doClass.BaseList != null && doClass.BaseList.Types.Any())
            {
                var baseClass = doClass.BaseList.Types.FirstOrDefault(t => _solutionSyntaxWalker.IsBaseClass(t));

                if (baseClass != null)
                {
                    repositoryInfo.BaseClassName = baseClass.ToString();
                }
            }

            #region Repository interface

            // Get implemented interfaces for custom repository (for example - IMenuItemRepository : IRepository<MenuItem>)
            var repositoryInterfaces = _solutionSyntaxWalker.GetInheritedInterfaces(repositoryInfo.GenericRepositoryInterfaceName).ToList();

            var repoInterface = repositoryInterfaces.FirstOrDefault();

            if (repoInterface == null)
            {
                var ret = CreateWithAnalysisError(className, _config.RepositorySuffix, string.Format("Repository interface {0} not found.", repositoryInfo.GenericRepositoryInterfaceName));
                return ret;
            }

            // Repository interface info
            repositoryInfo.RepositoryInterfaceName = _solutionSyntaxWalker.GetTypeNamespace(repoInterface) + "." + repoInterface.Identifier.Text;

            #endregion

            #region Repository model attributes

            #region DataAccess

            var dataAccess = (DataAccessAttribute)dataAccessAttr;

            var tableName = dataAccess.TableName ?? doClass.Identifier.ToString() + 's';
            repositoryInfo.TableName = tableName;

            // Get filters
            var filterKeys = (new[] { dataAccess.FilterKey1, dataAccess.FilterKey2, dataAccess.FilterKey3 })
                .Where(fk => fk != null)
                .Select(fk =>
                {
                    // Filter data may be combined (ItemId, GroupId)
                    var filters = fk.Split(',').Select(f =>
                    {
                        var name = f.Trim();
                        var parameter = doClass.Members.OfType<PropertyDeclarationSyntax>().FirstOrDefault(cp => cp.GetterExist() && cp.SetterExist() && cp.Identifier.Text == name);
                        var fullTypeName = _solutionSyntaxWalker.GetFullPropertyTypeName(parameter);
                        return new ParameterInfo(name, parameter != null ? fullTypeName : null);
                    }).ToList();
                    return new FilterInfo(string.Join("And", fk.Split(',').Select(f => f.Trim())), filters, FilterType.FilterKey);
                });

            repositoryInfo.FilterInfos.AddRange(filterKeys);

            // Common filter - isDeleted, modified
            repositoryInfo.SpecialOptionsIsDeleted = new FilterInfo("IsDeleted", new List<ParameterInfo> {new ParameterInfo("IsDeleted", "bool", Convert.ToString(dataAccess.IsDeleted).FirstSymbolToLower())}, FilterType.FilterKey);
            repositoryInfo.SpecialOptionsModified = new FilterInfo("Modified", new List<ParameterInfo> {new ParameterInfo("Modified", "DateTimeOffset")}, FilterType.FilterKey);

            repositoryInfo.VersionTableName = dataAccess.TableVersion;
            var isVersioning = dataAccess.TableVersion != null;
            repositoryInfo.IsVersioning = isVersioning;

            #endregion

            #endregion

            #region Property attributes

            var properties = doClass.Members.OfType<PropertyDeclarationSyntax>().Where(cp => cp.GetterExist() && cp.SetterExist()).ToList();

            // Add sql column name - skip members marked [DbIgnoreAttribute]
            var elements = properties
                .Where(p => !p.AttributeExist(RepositoryDataModelHelper.DbIgnoreAttributeName))
                .Select(p => p.Identifier.Text);
            repositoryInfo.Elements.AddRange(elements);

            // Primary keys info
//.........这里部分代码省略.........
开发者ID:yumapos,项目名称:Yumapos-WCF-Generator,代码行数:101,代码来源:RepositoryService.cs


注:本文中的Microsoft.CodeAnalysis.CSharp.Syntax.ClassDeclarationSyntax.BaseTypeExist方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。