本文整理汇总了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
//.........这里部分代码省略.........