├── .editorconfig ├── .github └── ISSUE_REPLY_TEMPLATE.md ├── .gitignore ├── CodeArts.Caching.md ├── CodeArts.Casting.md ├── CodeArts.Configuration.md ├── CodeArts.Db.EntityFramework.md ├── CodeArts.Db.Linq2Sql.md ├── CodeArts.Db.Lts.md ├── CodeArts.Db.md ├── CodeArts.Json.md ├── CodeArts.Middleware.md ├── CodeArts.Mvc.md ├── CodeArts.Net.md ├── CodeArts.sln ├── LICENSE.txt ├── ORM_UML.svg ├── README.md ├── Tests ├── CodeArts.Db.Dapper.Tests │ ├── CodeArts.Db.Dapper.Tests.csproj │ ├── Domain │ │ └── Entities │ │ │ ├── FeiUserdetails.cs │ │ │ └── FeiUsers.cs │ ├── Serialize │ │ └── SqlServerConnectionAttribute.cs │ ├── SkyDbContext.cs │ ├── SqlServerConsts.cs │ └── UnitTest1.cs ├── CodeArts.Db.EntityFramework.Tests │ ├── CodeArts.Db.EntityFramework.Tests.csproj │ ├── DbTestContext.cs │ ├── Domain │ │ ├── Entities │ │ │ ├── FeiUserWeChat.cs │ │ │ ├── FeiUserdetails.cs │ │ │ └── FeiUsers.cs │ │ ├── UserDetailsRepository.cs │ │ ├── UserRepository.cs │ │ └── UserWeChatRepository.cs │ ├── Dtos │ │ ├── TaxCodeTreeSimDto.cs │ │ ├── UserInDto.cs │ │ └── UserSimDto.cs │ ├── Enums │ │ ├── AuthShipEnum.cs │ │ ├── AuthTreeEnum.cs │ │ ├── CommonStatusEnum.cs │ │ ├── OrgTreeEnum.cs │ │ ├── UserRole.cs │ │ └── UserSex.cs │ ├── Serialize │ │ ├── DefaultDbConfigAttribute.cs │ │ └── SqlServerConnectionAttribute.cs │ ├── Sql │ │ ├── mssql.sql │ │ └── mysql.sql │ ├── SqlServerConsts.cs │ ├── SqlServerTest.cs │ └── UnitTest1.cs ├── CodeArts.Db.Lts.Tests │ ├── CodeArts.Db.Lts.Tests.csproj │ ├── Domain │ │ ├── AuthShipRepository.cs │ │ ├── AuthTreeRepository.cs │ │ ├── Entities │ │ │ ├── AuthShip.cs │ │ │ ├── AuthTree.cs │ │ │ ├── FeiUserWeChat.cs │ │ │ ├── FeiUserdetails.cs │ │ │ ├── FeiUsers.cs │ │ │ ├── OrgTree.cs │ │ │ ├── OrmTest.cs │ │ │ ├── OssBuckets.cs │ │ │ ├── TaxCode.cs │ │ │ └── User.cs │ │ ├── MySqlUserRespository.cs │ │ ├── OrgTreeRepository.cs │ │ ├── OrmTestRepository.cs │ │ ├── TaxCodeRepository.cs │ │ ├── UserDetailsRepository.cs │ │ ├── UserRepository.cs │ │ └── UserWeChatRepository.cs │ ├── Dtos │ │ ├── TaxCodeTreeSimDto.cs │ │ ├── UserInDto.cs │ │ └── UserSimDto.cs │ ├── Enums │ │ ├── AuthShipEnum.cs │ │ ├── AuthTreeEnum.cs │ │ ├── CommonStatusEnum.cs │ │ ├── OrgTreeEnum.cs │ │ ├── OssAclEnum.cs │ │ ├── OssAlgorithmEnum.cs │ │ ├── OssKmsEncryptionAlgorithmEnum.cs │ │ ├── OssStorageEnum.cs │ │ ├── UserRole.cs │ │ └── UserSex.cs │ ├── MySqlConsts.cs │ ├── MySqlTest.cs │ ├── SQLTest.cs │ ├── Serialize │ │ ├── DateTimeTokenAttribute.cs │ │ ├── DefaultDbConfigAttribute.cs │ │ └── SqlServerConnectionAttribute.cs │ ├── Sql │ │ ├── mssql.sql │ │ └── mysql.sql │ ├── SqlServerConsts.cs │ ├── SqlServerTest.cs │ ├── ThreadSecurityTest.cs │ └── UnitTest1.cs ├── CodeArts.Emit.Tests │ ├── Class1.cs │ ├── CodeArts.Emit.Tests.csproj │ └── UnitTest1.cs ├── CodeArts.Tests │ ├── CodeArts.Tests.csproj │ ├── CryptoExtentions.cs │ ├── DesignModeTest.cs │ ├── EnumExtensions.cs │ ├── Enums │ │ └── RoleEnum.cs │ ├── ExpressionTest.cs │ ├── KeyGenTest.cs │ ├── NormalTests.cs │ ├── ObjectExtentions.cs │ ├── StringExtentions.cs │ ├── TestAttributes.cs │ ├── UriExtentions.cs │ └── packages.config ├── ConsoleEmit │ ├── App.config │ ├── ConsoleEmit.csproj │ ├── MyTest.cs │ ├── Program.cs │ └── Properties │ │ └── AssemblyInfo.cs ├── GrpcClient │ ├── GrpcClient.csproj │ ├── Program.cs │ ├── Protos │ │ └── push.proto │ ├── appsettings.Development.json │ └── appsettings.json ├── MVC461 │ ├── App_Start │ │ └── WebApiConfig.cs │ ├── Controllers │ │ └── ValuesController.cs │ ├── Domain │ │ ├── Entities │ │ │ └── User.cs │ │ └── UserRepository.cs │ ├── MVC461.csproj │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Startup.cs │ ├── Web.Debug.config │ ├── Web.Release.config │ ├── Web.config │ └── packages.config ├── Mvc.Core │ ├── Controllers │ │ ├── ValuesController.cs │ │ └── WeatherForecastController.cs │ ├── Domain │ │ ├── EfContext.cs │ │ ├── Entities │ │ │ ├── FeiUsers.cs │ │ │ └── User.cs │ │ └── UserRepository.cs │ ├── Dtos │ │ └── UserDto.cs │ ├── Mvc.Core.csproj │ ├── Program.cs │ ├── Protos │ │ └── push.proto │ ├── Services │ │ └── PushService.cs │ ├── Startup.cs │ ├── WeatherForecast.cs │ ├── appsettings.Development.json │ ├── appsettings.json │ └── log4net.config ├── Mvc.Core2_1 │ ├── Controllers │ │ └── ValuesController.cs │ ├── Domain │ │ ├── Entities │ │ │ └── User.cs │ │ └── UserRepository.cs │ ├── Mvc.Core2_1.csproj │ ├── Program.cs │ ├── Startup.cs │ ├── appsettings.Development.json │ ├── appsettings.json │ └── log4net.config ├── Mvc4 │ ├── Controllers │ │ └── ValuesController.cs │ ├── Mvc4.csproj │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Startup.cs │ ├── Views │ │ └── TestView.cs │ ├── Web.Debug.config │ ├── Web.Release.config │ ├── Web.config │ └── packages.config └── Mvc45 │ ├── Controllers │ └── ValuesController.cs │ ├── Mvc45.csproj │ ├── Properties │ └── AssemblyInfo.cs │ ├── Startup.cs │ ├── Web.Debug.config │ ├── Web.Release.config │ ├── packages.config │ └── web.config ├── appveyor.yml ├── build.ps1 ├── codearts.png ├── project.json └── src ├── CodeArts.Caching ├── BaseCaching.cs ├── CachingManager.cs ├── CodeArts.Caching.csproj ├── ICaching.cs ├── ICachingProvider.cs ├── Level.cs └── MultiCaching.cs ├── CodeArts.Casting ├── CastingMapper.cs ├── CastingStartup.cs ├── CodeArts.Casting.csproj ├── Expressions │ ├── AutomaticMap.cs │ ├── ConstructorMap.cs │ ├── ConversionOperatorMap.cs │ ├── ConvertMap.cs │ ├── EnumToEnumMap.cs │ ├── EnumerableMap.cs │ ├── FromKvStringMap.cs │ ├── KeyValueMap.cs │ ├── ParseStringMap.cs │ ├── StringToEnumMap.cs │ ├── ToKvStringMap.cs │ └── UnderlyingTypeEnumMap.cs ├── IMapConfiguration.cs ├── IMapExpression.cs ├── IProfile.cs ├── IProfileConfiguration.cs ├── IProfileExpression.cs ├── IProfileMap.cs ├── MapExpression.cs ├── Mapper.cs ├── ProfileConfiguration.cs ├── ProfileExpression.cs └── SimpleExpression.cs ├── CodeArts.Configuration ├── CodeArts.Configuration.csproj ├── ConfigurationStartup.cs └── DefaultConfigHelper.cs ├── CodeArts.Db.Dapper ├── CodeArts.Db.Dapper.csproj ├── DapperConnectionManager.cs └── DbContext.cs ├── CodeArts.Db.EntityFramework.SqlServer ├── CodeArts.Db.EntityFramework.SqlServer.csproj └── SqlServerLinqAdapter.cs ├── CodeArts.Db.EntityFramework.Sqlite ├── CodeArts.Db.EntityFramework.Sqlite.csproj └── SqliteLinqAdapter.cs ├── CodeArts.Db.EntityFramework ├── CodeArts.Db.EntityFramework.csproj ├── DbContext.cs ├── DbTransaction.cs ├── DbTransactionProvider.cs ├── EntityFrameworkServiceCollectionExtentions.cs ├── IDbConnectionLinqAdapter.cs ├── IDbTransaction.cs ├── IDbTransactionProvider.cs ├── ILinqRepository.cs ├── LinqConnectionManager.cs ├── LinqRepository.cs └── QueryableExtentions.cs ├── CodeArts.Db.Linq2Sql ├── CodeArts.Db.Linq2Sql.csproj ├── CommandBehavior.cs ├── CustomVisitorList.cs ├── ExpressionExtensions.cs ├── Expressions │ ├── AllVisitor.cs │ ├── AnyVisitor.cs │ ├── AverageVisitor.cs │ ├── BaseVisitor.cs │ ├── CombinationVisitor.cs │ ├── CoreVisitor.cs │ ├── DeleteVisitor.cs │ ├── ExecuteVisitor.cs │ ├── GroupByLinqVisitor.cs │ ├── GroupByVisitor.cs │ ├── GroupJoinVisitor.cs │ ├── HavingVisitor.cs │ ├── InsertVisitor.cs │ ├── JoinSelectVisitor.cs │ ├── JoinVisitor.cs │ ├── LinqAnyVisitor.cs │ ├── LinqContainsVisitor.cs │ ├── MaxVisitor.cs │ ├── MinVisitor.cs │ ├── NestedAllVisitor.cs │ ├── NestedAnyVisitor.cs │ ├── NestedContainsVisitor.cs │ ├── QueryVisitor.cs │ ├── SelectVisitor.cs │ ├── SetContainsVisitor.cs │ ├── SetExistsVisitor.cs │ ├── SumVisitor.cs │ ├── UpdateVisitor.cs │ └── WhereVisitor.cs ├── Extentions │ └── RepositoryExtentions.cs ├── ICustomVisitor.cs ├── ICustomVisitorList.cs ├── IExecuteVisitor.cs ├── IQueryVisitor.cs ├── IStartupVisitor.cs ├── IVisitor.cs ├── IWriterMap.cs ├── MethodCall.cs ├── QueryableMethods.cs ├── TypeExtensions.cs ├── Types.cs ├── Writer.cs └── WriterMap.cs ├── CodeArts.Db.Lts.MySql ├── CodeArts.Db.Lts.MySql.csproj ├── MySqlLtsAdapter.cs └── Visiters │ └── ConvertVisitter.cs ├── CodeArts.Db.Lts.SqlServer ├── CodeArts.Db.Lts.SqlServer.csproj ├── SqlServer2012LtsAdapter.cs ├── SqlServerLtsAdapter.cs └── Visiters │ └── ConvertVisitter.cs ├── CodeArts.Db.Lts ├── CodeArts.Db.Lts.csproj ├── DRepository.cs ├── DapperFor.cs ├── DatabaseFactory.cs ├── DatabaseFor.cs ├── DbConnectionAdapter.cs ├── DbConnectionManager.cs ├── DbRepository.cs ├── Extentions │ ├── QueryableAsyncExtentions.cs │ └── RepositoryExtentions.cs ├── IAsyncQueryProvider.cs ├── IDRepository.cs ├── IDatabase.Async.cs ├── IDatabase.cs ├── IDatabaseFor.cs ├── IDbConnectionLtsAdapter.cs ├── IDbRepository.cs ├── IRepository.cs ├── QueryableAsync.cs ├── Repository.cs └── Types.cs ├── CodeArts.Db.MySql ├── CodeArts.Db.MySql.csproj ├── MySqlAdapter.cs ├── MySqlCorrectSettings.cs └── MySqlFactory.cs ├── CodeArts.Db.SqlServer ├── CodeArts.Db.SqlServer.csproj ├── Formatters │ ├── CreateIfFormatter.cs │ └── DropIfFormatter.cs ├── SqlServer2012Adapter.cs ├── SqlServer2012CorrectSettings.cs ├── SqlServerAdapter.cs ├── SqlServerCorrectSettings.cs └── SqlServerFactory.cs ├── CodeArts.Db.Sqlite ├── CodeArts.Db.Sqlite.csproj ├── SqliteAdapter.cs ├── SqliteCorrectSettings.cs └── SqliteFactory.cs ├── CodeArts.Db ├── AdapterFormatter.cs ├── BaseEntity.cs ├── CodeArts.Db.csproj ├── CommandSql.cs ├── CommandTypes.cs ├── CommonSettings.cs ├── ConnectionConfig.cs ├── DatabaseEngine.cs ├── DbConfigAttribute.cs ├── DbConnectionFactory.cs ├── DbReadConfigAttribute.cs ├── DbServiceRouter.cs ├── DbServiceSet.cs ├── DbValidator.cs ├── DbWriteConfigAttribute.cs ├── DefaultSqlAdpter.cs ├── DispatchConnections.cs ├── Exceptions │ ├── DException.cs │ ├── DRequiredException.cs │ ├── DSyntaxErrorException.cs │ ├── NonAuthorizedException.cs │ ├── NotImplementedKeyException.cs │ └── TypeAccessInvalidException.cs ├── ExpressionCombine.cs ├── Extentions │ └── QueryableExtentions.cs ├── IDbConnectionAdapter.cs ├── IDbConnectionFactory.cs ├── IDbRouter.cs ├── IDispatchConnections.cs ├── IEntiy.cs ├── IFormatter.cs ├── IReadOnlyConnectionConfig.cs ├── ISQLCorrectSettings.cs ├── ISqlAdpter.cs ├── ITableInfo.cs ├── LookupDb.cs ├── ParameterToken.cs ├── ParameterValue.cs ├── Routes │ ├── IDeleteable.cs │ ├── IInsertable.cs │ └── IUpdateable.cs ├── SQL.cs ├── TableRegions.cs ├── TableToken.cs ├── TokenAttribute.cs ├── TransactionConnections.cs └── Types.cs ├── CodeArts.DependencyInjection.Abstractions ├── CodeArts.DependencyInjection.Abstractions.csproj ├── Extensions │ └── ServiceCollectionDescriptorExtensions.cs ├── IServiceCollection.cs ├── IServiceProviderFactory.cs ├── IServiceScope.cs ├── IServiceScopeFactory.cs ├── ISupportRequiredService.cs ├── ServiceCollectionServiceExtensions.cs ├── ServiceDescriptor.cs ├── ServiceLifetime.cs └── ServiceProviderServiceExtensions.cs ├── CodeArts.DependencyInjection ├── CodeArts.DependencyInjection.csproj ├── DefaultServiceProviderFactory.cs ├── ServiceCollection.cs ├── ServiceCollectionContainerBuilderExtensions.cs ├── ServiceLookup │ ├── CallSiteChain.cs │ ├── CallSiteExpressionBuilderContext.cs │ ├── CallSiteFactory.cs │ ├── CallSiteKind.cs │ ├── CallSiteResultCacheLocation.cs │ ├── CallSiteRuntimeResolver.cs │ ├── CallSiteValidator.cs │ ├── CallSiteVisitor.cs │ ├── CompiledServiceProviderEngine.cs │ ├── ConstantCallSite.cs │ ├── ConstructorCallSite.cs │ ├── CreateInstanceCallSite.cs │ ├── DynamicServiceProviderEngine.cs │ ├── Expressions │ │ ├── ExpressionResolverBuilder.cs │ │ └── ExpressionsServiceProviderEngine.cs │ ├── FactoryCallSite.cs │ ├── IEnumerableCallSite.cs │ ├── ILEmit │ │ ├── ILEmitCallSiteAnalysisResult.cs │ │ ├── ILEmitCallSiteAnalyzer.cs │ │ ├── ILEmitResolverBuilder.cs │ │ ├── ILEmitResolverBuilderContext.cs │ │ └── ILEmitServiceProviderEngine.cs │ ├── IServiceProviderEngine.cs │ ├── IServiceProviderEngineCallback.cs │ ├── ResultCache.cs │ ├── RuntimeServiceProviderEngine.cs │ ├── ServiceCacheKey.cs │ ├── ServiceCallSite.cs │ ├── ServiceProviderCallSite.cs │ ├── ServiceProviderEngine.cs │ ├── ServiceProviderEngineScope.cs │ ├── ServiceScopeFactoryCallSite.cs │ ├── SingletonCallSite.cs │ ├── StackGuard.cs │ └── ThrowHelper.cs ├── ServiceProvider.cs ├── ServiceProviderMode.cs └── ServiceProviderOptions.cs ├── CodeArts.Emit ├── AbstractTypeEmitter.cs ├── AstException.cs ├── AstExpression.cs ├── BinaryExpressionType.cs ├── CodeArts.Emit.csproj ├── ConstructorEmitter.cs ├── DynamicMethod.cs ├── EmitUtils.cs ├── Emitters │ ├── ClassEmitter.cs │ ├── FieldEmitter.cs │ ├── MethodEmitter.cs │ ├── NestedClassEmitter.cs │ ├── ParameterEmitter.cs │ └── PropertyEmitter.cs ├── Expressions │ ├── ArrayAst.cs │ ├── ArrayIndexAst.cs │ ├── ArrayLengthAst.cs │ ├── BinaryAst.cs │ ├── BlockAst.cs │ ├── CoalesceAst.cs │ ├── ConditionAst.cs │ ├── ConstantAst.cs │ ├── ConvertAst.cs │ ├── DefaultAst.cs │ ├── FieldAst.cs │ ├── IfThenAst.cs │ ├── IfThenElseAst.cs │ ├── InvocationAst.cs │ ├── MemberAst.cs │ ├── MethodCallAst.cs │ ├── NewArrayAst.cs │ ├── NewInstanceAst.cs │ ├── ParameterAst.cs │ ├── PropertyAst.cs │ ├── ReturnAst.cs │ ├── SwitchAst.cs │ ├── ThrowAst.cs │ ├── TryAst.cs │ ├── TypeAsAst.cs │ ├── TypeIsAst.cs │ ├── UnaryAst.cs │ └── VariableAst.cs ├── INamingScope.cs ├── Intercept.cs ├── InterceptAsync.cs ├── InterceptAttribute.cs ├── InterceptContext.cs ├── ModuleEmitter.cs ├── NamingScope.cs ├── NoninterceptAttribute.cs ├── TypeExtensions.cs └── UnaryExpressionType.cs ├── CodeArts.Json ├── CodeArts.Json.csproj ├── JsonStartup.cs └── Serialize │ └── Json │ └── DefaultJsonHelper.cs ├── CodeArts.Logging ├── CodeArts.Logging.csproj ├── LoggerExtentions.cs └── LoggerManager.cs ├── CodeArts.MemoryCaching ├── CodeArts.MemoryCaching.csproj ├── MemoryCaching.cs ├── MemoryCachingProvider.cs ├── MemoryCachingStartup.cs └── MemoryManager.cs ├── CodeArts.Middleware ├── CodeArts.Middleware.csproj ├── IProxyByPattern.cs ├── InterceptCore.cs ├── MethodInfoEqualityComparer.cs ├── MiddlewareIntercept.cs ├── MiddlewareInterceptAsync.cs ├── Proxies │ ├── ProxyByFactory.cs │ ├── ProxyByImplementationType.cs │ ├── ProxyByInstance.cs │ └── ProxyByServiceType.cs ├── ServicesExtensions.cs └── TypeExtensions.cs ├── CodeArts.Mvc ├── Algorithms │ └── HMACSHA256AlgorithmGen.cs ├── Authentication │ ├── JwtBearerApplicationBuilderExtensions.cs │ ├── JwtBearerEvents.cs │ └── ResultContext.cs ├── BaseController.cs ├── Builder │ ├── ApplicationBuilderExtensions.cs │ └── IApplicationBuilder.cs ├── CodeArts.Mvc.csproj ├── Converters │ └── MyJsonConverter.cs ├── DExceptionFilter.cs ├── DStartup.cs ├── DependencyInjectionOptions.cs ├── DependencyInjectionServiceCollectionExtentions.cs ├── DictionaryExtentions.cs ├── ExceptionAdapter.cs ├── ExceptionHandler.cs ├── Filters │ └── ValidateModelAttribute.cs ├── Hosting │ └── ApplicationStart.cs ├── HttpContextExtensions.cs ├── HttpVerbs.cs ├── IJwtAlgorithmGen.cs ├── JwtAlgorithmGen.cs ├── JwtStartup.cs ├── JwtToken.cs ├── JwtTokenGen.cs ├── LoggerManagerExtentions.cs ├── MapExtensions.cs ├── ModelValidator.cs ├── PathString.cs ├── Providers │ ├── CachedDataAnnotationsModelMetadata.cs │ ├── DataAnnotationsModelMetadataProvider.cs │ └── DataAnnotationsModelValidator.cs ├── ResponseExtensions.cs └── Validators │ └── DataAnnotations │ ├── DataAnnotationsModelValidator.cs │ └── DataAnnotationsModelValidatorProvider.cs ├── CodeArts.Net ├── CodeArts.Net.csproj ├── Extentions │ ├── EncodingExtentions.cs │ └── UriExtentions.cs ├── IRequestable.cs └── WebCoreClient.cs ├── CodeArts.RedisCaching ├── CodeArts.RedisCaching.csproj ├── RedisCaching.cs ├── RedisCachingProvider.cs ├── RedisCachingStartup.cs └── RedisManager.cs └── CodeArts ├── AssemblyFinder.cs ├── CodeArts.csproj ├── Collections └── Generic │ ├── IAsyncEnumerable.cs │ ├── IAsyncEnumerator.cs │ ├── IReadOnlyCollection.cs │ ├── IReadOnlyDictionary.cs │ └── IReadOnlyList.cs ├── Config ├── ConfigHelper.cs └── IConfigHelper.cs ├── Consts.cs ├── Converter.cs ├── DResult.cs ├── DefaultSettings.cs ├── DevelopAttribute.cs ├── Emptyable.cs ├── Exceptions ├── BusiException.cs ├── CodeException.cs ├── ServException.cs └── SyntaxException.cs ├── Extentions ├── CryptoExtentions.cs ├── EnumExtensions.cs ├── IEnumerableAsyncExtentions.cs ├── IEnumerableExtentions.cs ├── QueryableExtentions.cs ├── ReadOnlyCollectionExtentions.cs ├── StringExtentions.cs └── TypeExtensions.cs ├── IConfigable.cs ├── IKeyGen.cs ├── IKeyGenFactory.cs ├── IMapper.cs ├── IResult.cs ├── IStartup.cs ├── IgnoreAttribute.cs ├── JsonSettings.cs ├── Key.cs ├── KeyGen.cs ├── KeyGenFactory.cs ├── LazyLoading.cs ├── Mapper.cs ├── NamingAttribute.cs ├── NamingType.cs ├── PagedList.cs ├── PatternKind.cs ├── Runtime ├── ConstructorItem.cs ├── FieldItem.cs ├── MethodItem.cs ├── ParameterItem.cs ├── PropertyItem.cs ├── StoreItem.cs └── TypeItem.cs ├── RuntimeServPools.cs ├── Serialize ├── Json │ ├── IJsonHelper.cs │ └── JsonHelper.cs └── Xml │ └── XmlHelper.cs ├── ServResult.cs ├── Singleton.cs ├── SnowflakeFactory.cs ├── SnowflakeKeyGen.cs ├── StatusCodes.cs ├── StatusCodesExtentions.cs ├── Threading ├── AsyncLocal.cs ├── AsyncLocalValueChangedArgs.cs └── CallContext.cs ├── UppercaseString.cs └── XStartup.cs /.editorconfig: -------------------------------------------------------------------------------- 1 | [*.cs] 2 | 3 | # IDE0066: 将 switch 语句转换为表达式 4 | dotnet_diagnostic.IDE0066.severity = none 5 | 6 | # IDE0063: 使用简单的 "using" 语句 7 | dotnet_diagnostic.IDE0063.severity = none 8 | -------------------------------------------------------------------------------- /.github/ISSUE_REPLY_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug. 3 | about: The framework is abnormal. 4 | --- 5 | 6 | ## ISSUE TEMPLATE 7 | 8 | #### 实例: 9 | 10 | ```c 11 | // 异常代码。 12 | ``` 13 | 14 | #### 说明: 15 | 16 | * 异常描述。 -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Tiny Lit 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /Tests/CodeArts.Db.Dapper.Tests/CodeArts.Db.Dapper.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp2.1;net461; 5 | 6 | false 7 | 8 | 9 | 10 | NETSTANDARD2_1; 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Tests/CodeArts.Db.Dapper.Tests/Serialize/SqlServerConnectionAttribute.cs: -------------------------------------------------------------------------------- 1 | using CodeArts.Db; 2 | using CodeArts.Db.Tests; 3 | using System; 4 | 5 | namespace UnitTest.Serialize 6 | { 7 | /// 8 | /// 数据库供应器。 9 | /// 10 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface)] 11 | public class SqlServerConnectionAttribute : DbConfigAttribute 12 | { 13 | public override ConnectionConfig GetConfig() 14 | { 15 | return new ConnectionConfig 16 | { 17 | Name = "de", 18 | ProviderName = "SqlServer", 19 | ConnectionString = string.Format(@"Data Source={0};User ID={2}; Password={3};Initial Catalog={1};Pooling=true", 20 | SqlServerConsts.Domain, 21 | SqlServerConsts.Database, 22 | SqlServerConsts.User, 23 | SqlServerConsts.Password)//? 数据库链接 24 | }; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Tests/CodeArts.Db.Dapper.Tests/SkyDbContext.cs: -------------------------------------------------------------------------------- 1 | using CodeArts.Db.Dapper.Tests.Domain.Entities; 2 | using UnitTest.Serialize; 3 | 4 | namespace CodeArts.Db.Dapper.Tests 5 | { 6 | [SqlServerConnection] 7 | public class SkyDbContext : DbContext 8 | { 9 | public DbServiceSet Users { get; set; } 10 | 11 | public DbServiceSet Userdetails { get; set; } 12 | } 13 | } -------------------------------------------------------------------------------- /Tests/CodeArts.Db.Dapper.Tests/SqlServerConsts.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace CodeArts.Db.Tests 6 | { 7 | public class SqlServerConsts 8 | { 9 | internal static readonly string Domain = Environment.GetEnvironmentVariable("DEV-DATABASE-SQLSEVER-DOMAIN") ?? "sqlsever.server.com"; 10 | internal static readonly string Database = Environment.GetEnvironmentVariable("DEV-DATABASE-SQLSEVER-DATABASE") ?? "yep_sky_orm"; 11 | internal static readonly string User = Environment.GetEnvironmentVariable("DEV-DATABASE-SQLSEVER-USER") ?? "sa"; 12 | internal static readonly string Password = Environment.GetEnvironmentVariable("DEV-DATABASE-SQLSEVER-PASSWORD") ?? "Password@12"; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Tests/CodeArts.Db.EntityFramework.Tests/DbTestContext.cs: -------------------------------------------------------------------------------- 1 | #if NET461 2 | using System.Data.Entity; 3 | #else 4 | using Microsoft.EntityFrameworkCore; 5 | #endif 6 | using UnitTest.Domain.Entities; 7 | using UnitTest.Serialize; 8 | 9 | namespace CodeArts.Db.EntityFramework.Tests 10 | { 11 | [SqlServerConnection] 12 | public class DbTestContext : DbContext 13 | { 14 | public DbSet FeiUserdetails { get; set; } 15 | 16 | public DbSet FeiUsers { get; set; } 17 | 18 | public DbSet FeiUserWeChat { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Tests/CodeArts.Db.EntityFramework.Tests/Domain/UserDetailsRepository.cs: -------------------------------------------------------------------------------- 1 | using CodeArts.Db.EntityFramework; 2 | using UnitTest.Domain.Entities; 3 | using UnitTest.Serialize; 4 | #if NET461 5 | using System.Data.Entity; 6 | #else 7 | using Microsoft.EntityFrameworkCore; 8 | #endif 9 | 10 | namespace CodeArts.Db.Domain 11 | { 12 | [SqlServerConnection] 13 | public class UserDetailsRepository : LinqRepository 14 | { 15 | public UserDetailsRepository(DbContext context) : base(context) 16 | { 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Tests/CodeArts.Db.EntityFramework.Tests/Domain/UserRepository.cs: -------------------------------------------------------------------------------- 1 | using CodeArts.Db.EntityFramework; 2 | #if NET461 3 | using System.Data.Entity; 4 | #else 5 | using Microsoft.EntityFrameworkCore; 6 | #endif 7 | using UnitTest.Domain.Entities; 8 | using UnitTest.Serialize; 9 | 10 | namespace CodeArts.Db.Domain 11 | { 12 | [SqlServerConnection] 13 | public class UserRepository : LinqRepository 14 | { 15 | public UserRepository(DbContext context) : base(context) 16 | { 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Tests/CodeArts.Db.EntityFramework.Tests/Domain/UserWeChatRepository.cs: -------------------------------------------------------------------------------- 1 | using CodeArts.Db.EntityFramework; 2 | using UnitTest.Domain.Entities; 3 | using UnitTest.Serialize; 4 | #if NET461 5 | using System.Data.Entity; 6 | #else 7 | using Microsoft.EntityFrameworkCore; 8 | #endif 9 | 10 | namespace CodeArts.Db.Domain 11 | { 12 | [SqlServerConnection] 13 | public class UserWeChatRepository : LinqRepository 14 | { 15 | public UserWeChatRepository(DbContext context) : base(context) 16 | { 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Tests/CodeArts.Db.EntityFramework.Tests/Dtos/TaxCodeTreeSimDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace UnitTest.Dtos 6 | { 7 | /// 8 | /// 税务编码树结构出参。 9 | /// 10 | public class TaxCodeTreeSimDto 11 | { 12 | /// 13 | /// ID。 14 | /// 15 | public string Id { get; set; } 16 | 17 | /// 18 | /// 名称。 19 | /// 20 | public string Name { get; set; } 21 | 22 | /// 23 | /// 简称。 24 | /// 25 | public string ShortName { get; set; } 26 | 27 | /// 28 | /// 是否包含孩子节点。 29 | /// 30 | public bool HasChild { get; set; } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Tests/CodeArts.Db.EntityFramework.Tests/Dtos/UserSimDto.cs: -------------------------------------------------------------------------------- 1 | namespace UnitTest.Dtos 2 | { 3 | /// 4 | /// 用户简表。 5 | /// 6 | public class UserSimDto 7 | { 8 | /// 9 | /// ID。 10 | /// 11 | public int Id { get; set; } 12 | /// 13 | /// 用户名称。 14 | /// 15 | public string Username { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Tests/CodeArts.Db.EntityFramework.Tests/Enums/AuthShipEnum.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | 3 | namespace UnitTest.Enums 4 | { 5 | /// 6 | /// 权限关系类型。 7 | /// 8 | public enum AuthShipEnum 9 | { 10 | /// 11 | /// 人员权限。 12 | /// 13 | [Description("人员权限")] 14 | User = 1 << 0, 15 | /// 16 | /// 机构权限。 17 | /// 18 | [Description("机构权限")] 19 | Tree = 1 << 1, 20 | /// 21 | /// 付费权限。 22 | /// 23 | [Description("付费权限")] 24 | Vip = 1 << 2 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Tests/CodeArts.Db.EntityFramework.Tests/Enums/AuthTreeEnum.cs: -------------------------------------------------------------------------------- 1 | namespace UnitTest.Enums 2 | { 3 | /// 4 | /// 权限类型。 5 | /// 6 | public enum AuthTreeEnum 7 | { 8 | /// 9 | /// 项目。 10 | /// 11 | Project = 1 << 0, 12 | /// 13 | /// 导航。 14 | /// 15 | Nav = 1 << 1, 16 | /// 17 | /// 菜单。 18 | /// 19 | Menu = 1 << 2, 20 | /// 21 | /// 页面。 22 | /// 23 | Page = 1 << 3, 24 | /// 25 | /// 功能。 26 | /// 27 | Function = 1 << 4, 28 | /// 29 | /// 面板。 30 | /// 31 | Panel = 1 << 5, 32 | /// 33 | /// 提示。 34 | /// 35 | Alert = 1 << 6, 36 | /// 37 | /// 标记。 38 | /// 39 | Label = 1 << 7 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Tests/CodeArts.Db.EntityFramework.Tests/Enums/CommonStatusEnum.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | 3 | namespace UnitTest.Enums 4 | { 5 | /// 6 | /// 公共状态枚举。 7 | /// 8 | public enum CommonStatusEnum 9 | { 10 | /// 11 | /// 删除。 12 | /// 13 | [Description("已删除")] 14 | Deleted = -1, 15 | /// 16 | /// 未激活。 17 | /// 18 | [Description("未激活")] 19 | NonActivated = 0, 20 | /// 21 | /// 启用。 22 | /// 23 | [Description("启用")] 24 | Enabled = 1, 25 | /// 26 | /// 禁用。 27 | /// 28 | [Description("禁用")] 29 | Disabled = 2 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Tests/CodeArts.Db.EntityFramework.Tests/Enums/OrgTreeEnum.cs: -------------------------------------------------------------------------------- 1 | namespace UnitTest.Enums 2 | { 3 | /// 4 | /// 机构类型。 5 | /// 6 | public enum OrgTreeEnum 7 | { 8 | /// 9 | /// 集团。 10 | /// 11 | G = 1 << 0, 12 | /// 13 | /// 单位。 14 | /// 15 | N = 1 << 1, 16 | /// 17 | /// 部门。 18 | /// 19 | M = 1 << 2, 20 | /// 21 | /// 商铺。 22 | /// 23 | S = 1 << 3, 24 | /// 25 | /// 虚拟节点。 26 | /// 27 | V = 1 << 4 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Tests/CodeArts.Db.EntityFramework.Tests/Enums/UserRole.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | 3 | namespace UnitTest.Enums 4 | { 5 | /// 6 | /// 用户角色。 7 | /// 8 | public enum UserRole 9 | { 10 | #region 客户 11 | /// 12 | /// 用户。 13 | /// 14 | [Description("用户")] 15 | Normal = 1 << 0, 16 | /// 17 | /// 管理员。 18 | /// 19 | [Description("管理员")] 20 | Administrator = 1 << 1, 21 | #endregion 22 | 23 | #region 系统 24 | /// 25 | /// 销售人员。 26 | /// 27 | [Description("销售人")] 28 | Saler = 1 << 2, 29 | /// 30 | /// 开发者。 31 | /// 32 | [Description("开发者")] 33 | Developer = 1 << 3, 34 | /// 35 | /// 维护人。 36 | /// 37 | [Description("维护人")] 38 | Maintainer = 1 << 4, 39 | /// 40 | /// 拥有者。 41 | /// 42 | [Description("拥有者")] 43 | Owner = 1 << 5 44 | #endregion 45 | 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Tests/CodeArts.Db.EntityFramework.Tests/Enums/UserSex.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | 3 | namespace UnitTest.Enums 4 | { 5 | /// 6 | /// 用户性别。 7 | /// 8 | public enum UserSex 9 | { 10 | /// 11 | /// 未知。 12 | /// 13 | [Description("未知")] 14 | Unkown = 0, 15 | /// 16 | /// 男。 17 | /// 18 | [Description("男")] 19 | Male = 1 << 1, 20 | /// 21 | /// 女。 22 | /// 23 | [Description("女")] 24 | Female = 1 << 2, 25 | /// 26 | /// 中性。 27 | /// 28 | [Description("中性")] 29 | Neutral = 1 << 3 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Tests/CodeArts.Db.EntityFramework.Tests/Serialize/DefaultDbConfigAttribute.cs: -------------------------------------------------------------------------------- 1 | using CodeArts.Db; 2 | using System; 3 | 4 | namespace UnitTest.Serialize 5 | { 6 | /// 7 | /// 默认数据库。 8 | /// 9 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] 10 | public class DefaultDbConfigAttribute : DbConfigAttribute 11 | { 12 | /// 13 | /// 获取链接配置。 14 | /// 15 | /// 16 | public override ConnectionConfig GetConfig() 17 | { 18 | return new ConnectionConfig 19 | { 20 | Name = "yep.v3.auth", 21 | ProviderName = "MySql", 22 | ConnectionString = "server=127.0.0.1;port=3306;user=root;password=Password12!;database=mysql;"//? 数据库链接 23 | }; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Tests/CodeArts.Db.EntityFramework.Tests/Serialize/SqlServerConnectionAttribute.cs: -------------------------------------------------------------------------------- 1 | using CodeArts.Db; 2 | using CodeArts.Db.Tests; 3 | using System; 4 | 5 | namespace UnitTest.Serialize 6 | { 7 | /// 8 | /// 数据库供应器。 9 | /// 10 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface)] 11 | public class SqlServerConnectionAttribute : DbConfigAttribute 12 | { 13 | public override ConnectionConfig GetConfig() 14 | { 15 | return new ConnectionConfig 16 | { 17 | Name = "de", 18 | ProviderName = "SqlServer", 19 | ConnectionString = string.Format(@"Data Source={0};User ID={2}; Password={3};Initial Catalog={1};Pooling=true", 20 | SqlServerConsts.Domain, 21 | SqlServerConsts.Database, 22 | SqlServerConsts.User, 23 | SqlServerConsts.Password)//? 数据库链接 24 | }; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Tests/CodeArts.Db.EntityFramework.Tests/SqlServerConsts.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace CodeArts.Db.Tests 6 | { 7 | public class SqlServerConsts 8 | { 9 | internal static readonly string Domain = Environment.GetEnvironmentVariable("DEV-DATABASE-SQLSEVER-DOMAIN") ?? "sqlsever.server.com"; 10 | internal static readonly string Database = Environment.GetEnvironmentVariable("DEV-DATABASE-SQLSEVER-DATABASE") ?? "yep_sky_orm"; 11 | internal static readonly string User = Environment.GetEnvironmentVariable("DEV-DATABASE-SQLSEVER-USER") ?? "sa"; 12 | internal static readonly string Password = Environment.GetEnvironmentVariable("DEV-DATABASE-SQLSEVER-PASSWORD") ?? "Password@12"; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Tests/CodeArts.Db.EntityFramework.Tests/SqlServerTest.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinylit/codearts/5002d35735f4dc5318737bca346f261af199dc3b/Tests/CodeArts.Db.EntityFramework.Tests/SqlServerTest.cs -------------------------------------------------------------------------------- /Tests/CodeArts.Db.EntityFramework.Tests/UnitTest1.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | 3 | namespace CodeArts.Db.EntityFramework.Tests 4 | { 5 | [TestClass] 6 | public class Tests 7 | { 8 | [TestInitialize] 9 | public void Setup() 10 | { 11 | } 12 | 13 | [TestMethod] 14 | public void Test1() 15 | { 16 | 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /Tests/CodeArts.Db.Lts.Tests/CodeArts.Db.Lts.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp2.1;net461; 5 | 6 | false 7 | 8 | 9 | 10 | NETSTANDARD2_1; 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /Tests/CodeArts.Db.Lts.Tests/Domain/AuthShipRepository.cs: -------------------------------------------------------------------------------- 1 | using CodeArts.Db.Lts; 2 | using UnitTest.Domain.Entities; 3 | using UnitTest.Serialize; 4 | 5 | namespace UnitTest.Domain 6 | { 7 | [DefaultDbConfig] 8 | public class AuthShipRepository : DbRepository 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Tests/CodeArts.Db.Lts.Tests/Domain/AuthTreeRepository.cs: -------------------------------------------------------------------------------- 1 | using CodeArts.Db.Lts; 2 | using UnitTest.Domain.Entities; 3 | using UnitTest.Serialize; 4 | 5 | namespace UnitTest.Domain 6 | { 7 | [DefaultDbConfig] 8 | public class AuthTreeRepository : DbRepository 9 | { 10 | 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Tests/CodeArts.Db.Lts.Tests/Domain/Entities/OrmTest.cs: -------------------------------------------------------------------------------- 1 | using CodeArts.Db.Tests.Serialize; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace CodeArts.Db.Tests.Domain.Entities 7 | { 8 | /// 9 | /// ORM性能测试。 10 | /// 11 | [Naming("yep_orm_test", NamingType.UrlCase)] 12 | public class OrmTest : BaseEntity 13 | { 14 | /// 15 | /// 名称。 16 | /// 17 | public string Name { get; set; } = string.Empty; 18 | 19 | /// 20 | /// 状态。 21 | /// 22 | public int Status { get; set; } 23 | 24 | /// 25 | /// 创建日期。 26 | /// 27 | public DateTime Created { get; set; } = DateTime.Now; 28 | 29 | /// 30 | /// 修改日期。 31 | /// 32 | [DateTimeToken] 33 | public DateTime Modified { get; set; } = DateTime.Now; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Tests/CodeArts.Db.Lts.Tests/Domain/MySqlUserRespository.cs: -------------------------------------------------------------------------------- 1 | using CodeArts.Db.Lts; 2 | using UnitTest.Domain.Entities; 3 | using UnitTest.Serialize; 4 | 5 | namespace UnitTest.Domain 6 | { 7 | [DefaultDbConfig] 8 | public class MySqlUserRespository : DbRepository 9 | { 10 | 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Tests/CodeArts.Db.Lts.Tests/Domain/OrgTreeRepository.cs: -------------------------------------------------------------------------------- 1 | using CodeArts.Db.Lts; 2 | using UnitTest.Domain.Entities; 3 | using UnitTest.Serialize; 4 | 5 | namespace UnitTest.Domain 6 | { 7 | [DefaultDbConfig] 8 | public class OrgTreeRepository : DbRepository 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Tests/CodeArts.Db.Lts.Tests/Domain/OrmTestRepository.cs: -------------------------------------------------------------------------------- 1 | using CodeArts.Db.Lts; 2 | using CodeArts.Db.Tests.Domain.Entities; 3 | using UnitTest.Serialize; 4 | 5 | namespace CodeArts.Db.Tests.Domain 6 | { 7 | [DefaultDbConfig] 8 | public class OrmTestRepository : DbRepository 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Tests/CodeArts.Db.Lts.Tests/Domain/TaxCodeRepository.cs: -------------------------------------------------------------------------------- 1 | using CodeArts.Db; 2 | using CodeArts.Db.Lts; 3 | using CodeArts.Db.Lts.Tests; 4 | using UnitTest.Domain.Entities; 5 | 6 | namespace UnitTest.Domain 7 | { 8 | /// 9 | /// 发票仓库。 10 | /// 11 | public class TaxCodeRepository : DbRepository 12 | { 13 | protected override IReadOnlyConnectionConfig GetDbConfig() 14 | { 15 | return new ConnectionConfig 16 | { 17 | Name = "yep.v3.invoice", 18 | ProviderName = "MySql", 19 | ConnectionString = string.Format("server={0};port=3306;user={2};password={3};database={1};" 20 | , MySqlConsts.Domain 21 | , MySqlConsts.Database 22 | , MySqlConsts.User 23 | , MySqlConsts.Password)//? 数据库链接 24 | }; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Tests/CodeArts.Db.Lts.Tests/Domain/UserDetailsRepository.cs: -------------------------------------------------------------------------------- 1 | using CodeArts.Db.Lts; 2 | using UnitTest.Domain.Entities; 3 | using UnitTest.Serialize; 4 | 5 | namespace CodeArts.Db.Domain 6 | { 7 | [SqlServerConnection] 8 | public class UserDetailsRepository : Repository 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Tests/CodeArts.Db.Lts.Tests/Domain/UserRepository.cs: -------------------------------------------------------------------------------- 1 | using CodeArts.Db.Lts; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using UnitTest.Domain.Entities; 5 | using UnitTest.Serialize; 6 | 7 | namespace CodeArts.Db.Domain 8 | { 9 | [SqlServerConnection] 10 | public class UserRepository : DbRepository 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Tests/CodeArts.Db.Lts.Tests/Domain/UserWeChatRepository.cs: -------------------------------------------------------------------------------- 1 | using CodeArts.Db.Lts; 2 | using UnitTest.Domain.Entities; 3 | using UnitTest.Serialize; 4 | 5 | namespace CodeArts.Db.Domain 6 | { 7 | [SqlServerConnection] 8 | public class UserWeChatRepository : DbRepository 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Tests/CodeArts.Db.Lts.Tests/Dtos/TaxCodeTreeSimDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace UnitTest.Dtos 6 | { 7 | /// 8 | /// 税务编码树结构出参。 9 | /// 10 | public class TaxCodeTreeSimDto 11 | { 12 | /// 13 | /// ID。 14 | /// 15 | public string Id { get; set; } 16 | 17 | /// 18 | /// 名称。 19 | /// 20 | public string Name { get; set; } 21 | 22 | /// 23 | /// 简称。 24 | /// 25 | public string ShortName { get; set; } 26 | 27 | /// 28 | /// 是否包含孩子节点。 29 | /// 30 | public bool HasChild { get; set; } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Tests/CodeArts.Db.Lts.Tests/Dtos/UserSimDto.cs: -------------------------------------------------------------------------------- 1 | namespace UnitTest.Dtos 2 | { 3 | /// 4 | /// 用户简表。 5 | /// 6 | public class UserSimDto 7 | { 8 | /// 9 | /// ID。 10 | /// 11 | public int Id { get; set; } 12 | /// 13 | /// 用户名称。 14 | /// 15 | public string Username { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Tests/CodeArts.Db.Lts.Tests/Enums/AuthShipEnum.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | 3 | namespace UnitTest.Enums 4 | { 5 | /// 6 | /// 权限关系类型。 7 | /// 8 | public enum AuthShipEnum 9 | { 10 | /// 11 | /// 人员权限。 12 | /// 13 | [Description("人员权限")] 14 | User = 1 << 0, 15 | /// 16 | /// 机构权限。 17 | /// 18 | [Description("机构权限")] 19 | Tree = 1 << 1, 20 | /// 21 | /// 付费权限。 22 | /// 23 | [Description("付费权限")] 24 | Vip = 1 << 2 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Tests/CodeArts.Db.Lts.Tests/Enums/AuthTreeEnum.cs: -------------------------------------------------------------------------------- 1 | namespace UnitTest.Enums 2 | { 3 | /// 4 | /// 权限类型。 5 | /// 6 | public enum AuthTreeEnum 7 | { 8 | /// 9 | /// 项目。 10 | /// 11 | Project = 1 << 0, 12 | /// 13 | /// 导航。 14 | /// 15 | Nav = 1 << 1, 16 | /// 17 | /// 菜单。 18 | /// 19 | Menu = 1 << 2, 20 | /// 21 | /// 页面。 22 | /// 23 | Page = 1 << 3, 24 | /// 25 | /// 功能。 26 | /// 27 | Function = 1 << 4, 28 | /// 29 | /// 面板。 30 | /// 31 | Panel = 1 << 5, 32 | /// 33 | /// 提示。 34 | /// 35 | Alert = 1 << 6, 36 | /// 37 | /// 标记。 38 | /// 39 | Label = 1 << 7 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Tests/CodeArts.Db.Lts.Tests/Enums/CommonStatusEnum.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | 3 | namespace UnitTest.Enums 4 | { 5 | /// 6 | /// 公共状态枚举。 7 | /// 8 | public enum CommonStatusEnum 9 | { 10 | /// 11 | /// 删除。 12 | /// 13 | [Description("已删除")] 14 | Deleted = -1, 15 | /// 16 | /// 未激活。 17 | /// 18 | [Description("未激活")] 19 | NonActivated = 0, 20 | /// 21 | /// 启用。 22 | /// 23 | [Description("启用")] 24 | Enabled = 1, 25 | /// 26 | /// 禁用。 27 | /// 28 | [Description("禁用")] 29 | Disabled = 2 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Tests/CodeArts.Db.Lts.Tests/Enums/OrgTreeEnum.cs: -------------------------------------------------------------------------------- 1 | namespace UnitTest.Enums 2 | { 3 | /// 4 | /// 机构类型。 5 | /// 6 | public enum OrgTreeEnum 7 | { 8 | /// 9 | /// 集团。 10 | /// 11 | G = 1 << 0, 12 | /// 13 | /// 单位。 14 | /// 15 | N = 1 << 1, 16 | /// 17 | /// 部门。 18 | /// 19 | M = 1 << 2, 20 | /// 21 | /// 商铺。 22 | /// 23 | S = 1 << 3, 24 | /// 25 | /// 虚拟节点。 26 | /// 27 | V = 1 << 4 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Tests/CodeArts.Db.Lts.Tests/Enums/OssAclEnum.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | 3 | namespace UnitTest.Enums 4 | { 5 | /// 6 | /// OSS 读写权限。 7 | /// 8 | public enum OssAclEnum 9 | { 10 | /// 11 | /// 私有。 12 | /// 13 | [Description("私有")] 14 | Private, 15 | 16 | /// 17 | /// 公共读。 18 | /// 19 | [Description("公共读")] 20 | PublicRead, 21 | 22 | /// 23 | /// 公共读写。 24 | /// 25 | [Description("公共读写")] 26 | PublicReadWrite 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Tests/CodeArts.Db.Lts.Tests/Enums/OssAlgorithmEnum.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | 3 | namespace UnitTest.Enums 4 | { 5 | /// 6 | /// OSS 加密方式。 7 | /// 8 | public enum OssAlgorithmEnum 9 | { 10 | /// 11 | /// 无。 12 | /// 13 | [Description("无")] 14 | None, 15 | 16 | /// 17 | /// OSS 完全托管。 18 | /// 19 | [Description("OSS完全托管")] 20 | OssProxy, 21 | 22 | /// 23 | /// KMS。 24 | /// 25 | [Description("KMS")] 26 | KMS 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Tests/CodeArts.Db.Lts.Tests/Enums/OssKmsEncryptionAlgorithmEnum.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | 3 | namespace UnitTest.Enums 4 | { 5 | /// 6 | /// OSS 加密算法。 7 | /// 8 | public enum OssKmsEncryptionAlgorithmEnum 9 | { 10 | /// 11 | /// 无。 12 | /// 13 | [Description("无")] 14 | None, 15 | /// 16 | /// AES256。 17 | /// 18 | [Description("AES256")] 19 | AES256, 20 | 21 | /// 22 | /// SM4。 23 | /// 24 | [Description("SM4")] 25 | SM4 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Tests/CodeArts.Db.Lts.Tests/Enums/OssStorageEnum.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | 3 | namespace UnitTest.Enums 4 | { 5 | /// 6 | /// OSS 存储类型。 7 | /// 8 | public enum OssStorageEnum 9 | { 10 | /// 11 | /// 标准。 12 | /// 13 | [Description("标准")] 14 | Standard, 15 | 16 | /// 17 | /// 低频访问。 18 | /// 19 | [Description("低频访问")] 20 | LowAccess, 21 | 22 | /// 23 | /// 归档。 24 | /// 25 | [Description("归档")] 26 | Archived 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Tests/CodeArts.Db.Lts.Tests/Enums/UserRole.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | 3 | namespace UnitTest.Enums 4 | { 5 | /// 6 | /// 用户角色。 7 | /// 8 | public enum UserRole 9 | { 10 | #region 客户 11 | /// 12 | /// 用户。 13 | /// 14 | [Description("用户")] 15 | Normal = 1 << 0, 16 | /// 17 | /// 管理员。 18 | /// 19 | [Description("管理员")] 20 | Administrator = 1 << 1, 21 | #endregion 22 | 23 | #region 系统 24 | /// 25 | /// 销售人员。 26 | /// 27 | [Description("销售人")] 28 | Saler = 1 << 2, 29 | /// 30 | /// 开发者。 31 | /// 32 | [Description("开发者")] 33 | Developer = 1 << 3, 34 | /// 35 | /// 维护人。 36 | /// 37 | [Description("维护人")] 38 | Maintainer = 1 << 4, 39 | /// 40 | /// 拥有者。 41 | /// 42 | [Description("拥有者")] 43 | Owner = 1 << 5 44 | #endregion 45 | 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Tests/CodeArts.Db.Lts.Tests/Enums/UserSex.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | 3 | namespace UnitTest.Enums 4 | { 5 | /// 6 | /// 用户性别。 7 | /// 8 | public enum UserSex 9 | { 10 | /// 11 | /// 未知。 12 | /// 13 | [Description("未知")] 14 | Unkown = 0, 15 | /// 16 | /// 男。 17 | /// 18 | [Description("男")] 19 | Male = 1 << 1, 20 | /// 21 | /// 女。 22 | /// 23 | [Description("女")] 24 | Female = 1 << 2, 25 | /// 26 | /// 中性。 27 | /// 28 | [Description("中性")] 29 | Neutral = 1 << 3 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Tests/CodeArts.Db.Lts.Tests/MySqlConsts.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace CodeArts.Db.Lts.Tests 6 | { 7 | public class MySqlConsts 8 | { 9 | internal static readonly string Domain = Environment.GetEnvironmentVariable("DEV-DATABASE-MYSQL-DOMAIN") ?? "mysql.server.com"; 10 | internal static readonly string Database = Environment.GetEnvironmentVariable("DEV-DATABASE-MYSQL-DATABASE") ?? "yep_sky_orm"; 11 | internal static readonly string User = Environment.GetEnvironmentVariable("DEV-DATABASE-MYSQL-USER") ?? "root"; 12 | internal static readonly string Password = Environment.GetEnvironmentVariable("DEV-DATABASE-MYSQL-PASSWORD") ?? "Password!12"; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Tests/CodeArts.Db.Lts.Tests/Serialize/DateTimeTokenAttribute.cs: -------------------------------------------------------------------------------- 1 | using CodeArts.Db.Lts; 2 | using System; 3 | 4 | namespace CodeArts.Db.Tests.Serialize 5 | { 6 | /// 7 | /// 日期令牌。 8 | /// 9 | [AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = false)] 10 | public class DateTimeTokenAttribute : TokenAttribute 11 | { 12 | public override object Create() => DateTime.Now; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Tests/CodeArts.Db.Lts.Tests/Serialize/DefaultDbConfigAttribute.cs: -------------------------------------------------------------------------------- 1 | using CodeArts.Db; 2 | using CodeArts.Db.Lts.Tests; 3 | using System; 4 | 5 | namespace UnitTest.Serialize 6 | { 7 | /// 8 | /// 默认数据库。 9 | /// 10 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] 11 | public class DefaultDbConfigAttribute : DbConfigAttribute 12 | { 13 | /// 14 | /// 获取链接配置。 15 | /// 16 | /// 17 | public override ConnectionConfig GetConfig() 18 | { 19 | return new ConnectionConfig 20 | { 21 | Name = "yep.v3.auth", 22 | ProviderName = "MySql", 23 | ConnectionString = string.Format("server={0};port=3306;user={2};password={3};database={1};" 24 | , MySqlConsts.Domain 25 | , MySqlConsts.Database 26 | , MySqlConsts.User 27 | , MySqlConsts.Password)//? 数据库链接 28 | }; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Tests/CodeArts.Db.Lts.Tests/Serialize/SqlServerConnectionAttribute.cs: -------------------------------------------------------------------------------- 1 | using CodeArts.Db; 2 | using CodeArts.Db.Tests; 3 | using System; 4 | 5 | namespace UnitTest.Serialize 6 | { 7 | /// 8 | /// 数据库供应器。 9 | /// 10 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface)] 11 | public class SqlServerConnectionAttribute : DbConfigAttribute 12 | { 13 | public override ConnectionConfig GetConfig() 14 | { 15 | return new ConnectionConfig 16 | { 17 | Name = "de", 18 | ProviderName = "SqlServer", 19 | ConnectionString = string.Format(@"Data Source={0};User ID={2}; Password={3};Initial Catalog={1};Pooling=true", 20 | SqlServerConsts.Domain, 21 | SqlServerConsts.Database, 22 | SqlServerConsts.User, 23 | SqlServerConsts.Password)//? 数据库链接 24 | }; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Tests/CodeArts.Db.Lts.Tests/SqlServerConsts.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace CodeArts.Db.Tests 6 | { 7 | public class SqlServerConsts 8 | { 9 | internal static readonly string Domain = Environment.GetEnvironmentVariable("DEV-DATABASE-SQLSEVER-DOMAIN") ?? "sqlsever.server.com"; 10 | internal static readonly string Database = Environment.GetEnvironmentVariable("DEV-DATABASE-SQLSEVER-DATABASE") ?? "yep_sky_orm"; 11 | internal static readonly string User = Environment.GetEnvironmentVariable("DEV-DATABASE-SQLSEVER-USER") ?? "sa"; 12 | internal static readonly string Password = Environment.GetEnvironmentVariable("DEV-DATABASE-SQLSEVER-PASSWORD") ?? "Password@12"; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Tests/CodeArts.Db.Lts.Tests/SqlServerTest.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinylit/codearts/5002d35735f4dc5318737bca346f261af199dc3b/Tests/CodeArts.Db.Lts.Tests/SqlServerTest.cs -------------------------------------------------------------------------------- /Tests/CodeArts.Db.Lts.Tests/UnitTest1.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using UnitTest.Domain.Entities; 5 | 6 | namespace CodeArts.Db.Tests 7 | { 8 | [TestClass] 9 | public class UnitTest1 10 | { 11 | [TestMethod] 12 | public void TestMethod1() 13 | { 14 | var users = new List(); 15 | 16 | var user = users.DefaultIfEmpty(null).First(); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Tests/CodeArts.Emit.Tests/UnitTest1.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinylit/codearts/5002d35735f4dc5318737bca346f261af199dc3b/Tests/CodeArts.Emit.Tests/UnitTest1.cs -------------------------------------------------------------------------------- /Tests/CodeArts.Tests/CodeArts.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp2.1;net461; 5 | 6 | false 7 | 8 | 9 | 10 | Json.NET .NET Standard 2.1 11 | NETSTANDARD2_1; 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /Tests/CodeArts.Tests/CryptoExtentions.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Security.Cryptography; 6 | using System.Text; 7 | 8 | namespace CodeArts.Tests 9 | { 10 | [TestClass] 11 | public class CryptoExtentions 12 | { 13 | [TestMethod] 14 | public void MyTestMethod() 15 | { 16 | var value = "d;ljvhhgortpghfgbfgbgbg"; 17 | 18 | var encrypt = value.Encrypt("@%d^#41&", "%@D^d$2~"); 19 | 20 | var decrypt = encrypt.Decrypt("@%d^#41&", "%@D^d$2~"); 21 | 22 | Assert.IsTrue(value == decrypt); 23 | } 24 | 25 | [TestMethod] 26 | public void MyTestMethod2() 27 | { 28 | var value = "d;ljvhhgortpghfgbfgbgbg"; 29 | 30 | var encrypt = value.Encrypt("92N0La5}AC$@efgt", CryptoKind.AES); 31 | 32 | var decrypt = encrypt.Decrypt("92N0La5}AC$@efgt", CryptoKind.AES); 33 | 34 | Assert.IsTrue(value == decrypt); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Tests/CodeArts.Tests/EnumExtensions.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using CodeArts.Tests.Enums; 3 | using System; 4 | 5 | namespace CodeArts.Tests 6 | { 7 | [TestClass] 8 | public class EnumExtensions 9 | { 10 | [TestMethod] 11 | public void GetText() 12 | { 13 | var text = DateTimeKind.Local.GetText(); 14 | 15 | var text2 = RoleEnum.Admin.GetText(); 16 | } 17 | 18 | [TestMethod] 19 | public void GetTextFlags() 20 | { 21 | var @enum = RoleFlagsEnum.User | RoleFlagsEnum.Admin; 22 | 23 | var text = @enum.GetText(); 24 | } 25 | 26 | [TestMethod] 27 | public void ToValueString() 28 | { 29 | var text = RoleEnum.User.ToValueString(); 30 | 31 | var text2 = RoleEnum.Admin.ToValueString(); 32 | } 33 | 34 | [TestMethod] 35 | public void ToValueStringFlags() 36 | { 37 | var @enum = RoleFlagsEnum.User | RoleFlagsEnum.Admin; 38 | 39 | var text = @enum.ToValueString(); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Tests/CodeArts.Tests/Enums/RoleEnum.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Text; 5 | 6 | namespace CodeArts.Tests.Enums 7 | { 8 | public enum RoleEnum 9 | { 10 | User, 11 | [Description("管理员")] 12 | Admin 13 | } 14 | 15 | [Flags] 16 | public enum RoleFlagsEnum 17 | { 18 | User = 1 << 0, 19 | [Description("管理员")] 20 | Admin = 1 << 1 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Tests/CodeArts.Tests/StringExtentions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using System.Text.RegularExpressions; 4 | using Microsoft.VisualStudio.TestTools.UnitTesting; 5 | 6 | namespace CodeArts.Tests 7 | { 8 | 9 | [TestClass] 10 | public class StringExtentions 11 | { 12 | [TestMethod] 13 | public void PropSugar() 14 | { 15 | for (int i = 0; i < 100000; i++) 16 | { 17 | string value = $"{i}x{{z + 100}}xx{{x ?? z + y}}-{{y?+z}}-{{z}}--{{xyz+sb}}-{{sb}}-{{abc}}".PropSugar(new { x = DateTimeKind.Utc, y = DateTime.Now, z = (string)null, xyz = new int[] { 1, 2, 3 }, sb = new StringBuilder("sb") }, new JsonSettings(NamingType.Normal)); 18 | } 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Tests/CodeArts.Tests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /Tests/ConsoleEmit/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Tests/ConsoleEmit/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的一般信息由以下 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("ConsoleEmit")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("ConsoleEmit")] 13 | [assembly: AssemblyCopyright("Copyright © 2019")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 会使此程序集中的类型 18 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 19 | //请将此类型的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("5b3dedb3-f7c6-4b67-8da0-05bc3e12d785")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 33 | //通过使用 "*",如下所示: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Tests/GrpcClient/GrpcClient.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp3.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Tests/GrpcClient/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Grpc.Net.Client; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Hosting; 9 | 10 | namespace GrpcClient 11 | { 12 | public class Program 13 | { 14 | static async Task Main() 15 | { 16 | // The port number(5001) must match the port of the gRPC server. 17 | var channel = GrpcChannel.ForAddress("https://localhost:44327/"); 18 | var client = new Push.PushClient(channel); 19 | var reply = await client.PushAsync(new PushRequest 20 | { 21 | CompanyId = 109090080uL, 22 | InvoiceCode = "sdfg", 23 | InvoiceNo = "efoehgirht", 24 | InvoiceType = PushRequest.Types.InvoiceType.Electric, 25 | Jshj = "1000.11", 26 | Kprq = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), 27 | Pdf = "dffgggh", 28 | RequestId = "dsdfdf", 29 | Ticket = PushRequest.Types.Ticket.Blue 30 | }); 31 | Console.WriteLine("Greeting: " + reply.Code); 32 | Console.WriteLine("Press any key to exit..."); 33 | Console.ReadKey(); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Tests/GrpcClient/Protos/push.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | option csharp_namespace = "GrpcClient"; 4 | 5 | package main; 6 | 7 | // The greeting service definition. 8 | service Push { 9 | // Sends a greeting 10 | rpc Push (PushRequest) returns (PushResult); 11 | } 12 | 13 | // The request message containing the user's name. 14 | message PushRequest { 15 | uint64 companyId = 1; 16 | string requestId = 2; 17 | enum InvoiceType { 18 | ELECTRIC = 0; 19 | NORMAL = 1; 20 | SPECIAL = 2; 21 | ROLL = 3; 22 | } 23 | InvoiceType invoiceType = 3; 24 | string invoiceCode = 4; 25 | string invoiceNo = 5; 26 | string jshj = 6; 27 | enum Ticket{ 28 | BLUE = 0; 29 | RED = 1; 30 | } 31 | Ticket ticket = 7; 32 | string pdf = 8; 33 | string kprq = 9; 34 | } 35 | 36 | // The response message containing the greetings. 37 | message PushResult { 38 | int32 Code = 1; 39 | string Msg = 2; 40 | } 41 | -------------------------------------------------------------------------------- /Tests/GrpcClient/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Debug", 5 | "System": "Information", 6 | "Grpc": "Information", 7 | "Microsoft": "Information" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Tests/GrpcClient/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Warning", 5 | "Microsoft.Hosting.Lifetime": "Information" 6 | } 7 | }, 8 | "AllowedHosts": "*", 9 | "Kestrel": { 10 | "EndpointDefaults": { 11 | "Protocols": "Http2" 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Tests/MVC461/App_Start/WebApiConfig.cs: -------------------------------------------------------------------------------- 1 | using CodeArts.Runtime; 2 | using System.Linq; 3 | using System.Web.Http; 4 | 5 | namespace Mvc461 6 | { 7 | public static class WebApiConfig 8 | { 9 | public static void Register(HttpConfiguration config) 10 | { 11 | // Web API 配置和服务 12 | 13 | // Web API 路由 14 | config.MapHttpAttributeRoutes(); 15 | 16 | var typeStore = TypeItem.Get(config.GetType()); 17 | 18 | var propertyStore = typeStore.PropertyStores.First(x => x.Name == "Services"); 19 | 20 | config.Routes.MapHttpRoute( 21 | name: "DefaultApi", 22 | routeTemplate: "api/{controller}/{id}", 23 | defaults: new { id = RouteParameter.Optional } 24 | ); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Tests/MVC461/Domain/Entities/User.cs: -------------------------------------------------------------------------------- 1 | using CodeArts; 2 | using CodeArts.Db; 3 | using System; 4 | using System.ComponentModel; 5 | using System.ComponentModel.DataAnnotations; 6 | 7 | namespace Mvc461.Domain.Entities 8 | { 9 | /// 10 | /// 用户信息表。 11 | /// 12 | [Naming("yep_users", NamingType.UrlCase)] 13 | public class User : BaseEntity 14 | { 15 | /// 16 | /// 机构ID。 17 | /// 18 | public ulong OrgId { get; set; } 19 | /// 20 | /// 公司ID。 21 | /// 22 | public long CompanyId { get; set; } 23 | /// 24 | /// 账户。 25 | /// 26 | [Display(Name = "用户账户")] 27 | [Required(ErrorMessage = "{0}为必填项!")] 28 | public string Account { get; set; } 29 | /// 30 | /// 用户名称。 31 | /// 32 | [Display(Name = "用户名称")] 33 | [Required(ErrorMessage = "{0}为必填项!")] 34 | public string Name { get; set; } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Tests/MVC461/Domain/UserRepository.cs: -------------------------------------------------------------------------------- 1 | using CodeArts.Db; 2 | using CodeArts.Db.Lts; 3 | using Mvc461.Domain.Entities; 4 | 5 | namespace Mvc461.Domain 6 | { 7 | /// 8 | /// 用户仓库。 9 | /// 10 | [DbConfig] 11 | public class UserRepository : DbRepository 12 | { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Tests/MVC461/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的常规信息通过下列特性集 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("Mvc461")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Mvc461")] 13 | [assembly: AssemblyCopyright("Copyright © 2019")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 会使此程序集中的类型 18 | // 对 COM 组件不可见。如果需要 19 | // 从 COM 访问此程序集中的某个类型,请针对该类型将 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于 typelib 的 ID 23 | [assembly: Guid("f3f2410e-7640-404b-b3ba-dbbf3203dc6b")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 内部版本号 30 | // 修订版本 31 | // 32 | // 可以指定所有值,也可以使用“修订号”和“内部版本号”的默认值, 33 | // 方法是按如下所示使用 "*": 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /Tests/MVC461/Startup.cs: -------------------------------------------------------------------------------- 1 | using CodeArts; 2 | using CodeArts.Mvc; 3 | using Microsoft.Extensions.DependencyInjection; 4 | using System.ComponentModel.DataAnnotations; 5 | using System.Web.Http; 6 | 7 | namespace Mvc461 8 | { 9 | /// 10 | /// 启动类。 11 | /// 12 | public class Startup : JwtStartup 13 | { 14 | public Startup() 15 | { 16 | using (var startup = new XStartup()) 17 | { 18 | startup.DoStartup(); 19 | } 20 | } 21 | public override void Configuration(HttpConfiguration config) 22 | { 23 | base.Configuration(config); 24 | 25 | ModelValidator.CustomValidate((attr, context) => 26 | { 27 | return $"{context.DisplayName}为必填字段!"; 28 | }); 29 | } 30 | 31 | /// 32 | public void ConfigureServices(IServiceCollection services) 33 | { 34 | services.UseDependencyInjection(); 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /Tests/MVC461/Web.Debug.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 30 | 31 | -------------------------------------------------------------------------------- /Tests/MVC461/Web.Release.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 19 | 31 | 32 | -------------------------------------------------------------------------------- /Tests/Mvc.Core/Domain/EfContext.cs: -------------------------------------------------------------------------------- 1 | using CodeArts.Db; 2 | using CodeArts.Db.EntityFramework; 3 | using Microsoft.EntityFrameworkCore; 4 | using Mvc.Core.Domain.Entities; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Threading.Tasks; 9 | 10 | namespace Mvc.Core.Domain 11 | { 12 | /// 13 | /// 上下文。 14 | /// 15 | [DbConfig("connectionStrings:mssql")] 16 | public class EfContext : DbContext 17 | { 18 | /// 19 | /// 用户。 20 | /// 21 | public DbSet Users { get; set; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Tests/Mvc.Core/Domain/Entities/User.cs: -------------------------------------------------------------------------------- 1 | using CodeArts; 2 | using CodeArts.Db; 3 | using System; 4 | using System.ComponentModel; 5 | using System.ComponentModel.DataAnnotations; 6 | 7 | namespace Mvc.Core.Domain.Entities 8 | { 9 | /// 10 | /// 用户信息表。 11 | /// 12 | [Naming("yep_users", NamingType.UrlCase)] 13 | public class User : BaseEntity 14 | { 15 | /// 16 | /// 机构ID。 17 | /// 18 | public ulong OrgId { get; set; } 19 | /// 20 | /// 公司ID。 21 | /// 22 | public long CompanyId { get; set; } 23 | /// 24 | /// 账户。 25 | /// 26 | [Display(Name = "用户账户")] 27 | [Required(ErrorMessage = "{0}为必填项!")] 28 | public string Account { get; set; } 29 | /// 30 | /// 用户名称。 31 | /// 32 | [Display(Name = "用户名称")] 33 | [Required(ErrorMessage = "{0}为必填项!")] 34 | public string Name { get; set; } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Tests/Mvc.Core/Domain/UserRepository.cs: -------------------------------------------------------------------------------- 1 | using Mvc.Core.Domain.Entities; 2 | using CodeArts.Db; 3 | using CodeArts.Db.Lts; 4 | 5 | namespace Mvc.Core.Domain 6 | { 7 | /// 8 | /// 用户仓库。 9 | /// 10 | [DbConfig("connectionStrings:default")] 11 | public class UserRepository : DbRepository 12 | { 13 | 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Tests/Mvc.Core/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using AspectCore.Extensions.DependencyInjection; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.Extensions.Configuration; 8 | using Microsoft.Extensions.Hosting; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace Mvc.Core 12 | { 13 | /// 14 | public class Program 15 | { 16 | /// 17 | public static void Main(string[] args) 18 | { 19 | CreateHostBuilder(args).Build().Run(); 20 | } 21 | /// 22 | public static IHostBuilder CreateHostBuilder(string[] args) => 23 | Host.CreateDefaultBuilder(args) 24 | .ConfigureLogging(builder => builder.AddLog4Net("log4net.config", true)) 25 | .ConfigureWebHostDefaults(webBuilder => 26 | { 27 | webBuilder.UseStartup(); 28 | }); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Tests/Mvc.Core/Protos/push.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | option csharp_namespace = "Mvc.Core"; 4 | 5 | package main; 6 | 7 | // The greeting service definition. 8 | service Push { 9 | // Sends a greeting 10 | rpc Push (PushRequest) returns (PushResult); 11 | } 12 | 13 | // The request message containing the user's name. 14 | message PushRequest { 15 | uint64 companyId = 1; 16 | string requestId = 2; 17 | enum InvoiceType { 18 | ELECTRIC = 0; 19 | NORMAL = 1; 20 | SPECIAL = 2; 21 | ROLL = 3; 22 | } 23 | InvoiceType invoiceType = 3; 24 | string invoiceCode = 4; 25 | string invoiceNo = 5; 26 | string jshj = 6; 27 | enum Ticket{ 28 | BLUE = 0; 29 | RED = 1; 30 | } 31 | Ticket ticket = 7; 32 | string pdf = 8; 33 | string kprq = 9; 34 | } 35 | 36 | // The response message containing the greetings. 37 | message PushResult { 38 | int32 Code = 1; 39 | string Msg = 2; 40 | } 41 | -------------------------------------------------------------------------------- /Tests/Mvc.Core/Services/PushService.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinylit/codearts/5002d35735f4dc5318737bca346f261af199dc3b/Tests/Mvc.Core/Services/PushService.cs -------------------------------------------------------------------------------- /Tests/Mvc.Core/Startup.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinylit/codearts/5002d35735f4dc5318737bca346f261af199dc3b/Tests/Mvc.Core/Startup.cs -------------------------------------------------------------------------------- /Tests/Mvc.Core/WeatherForecast.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | 5 | namespace Mvc.Core 6 | { 7 | /// 8 | public class WeatherForecast 9 | { 10 | /// 11 | public DateTime? Date { get; set; } 12 | 13 | /// 14 | public int TemperatureC { get; set; } 15 | 16 | /// 17 | public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); 18 | 19 | /// 20 | public List Codes { get; set; } 21 | 22 | /// 23 | [Required] 24 | public string Summary { get; set; } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Tests/Mvc.Core/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Debug", 5 | "System": "Information", 6 | "Microsoft": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Tests/Mvc.Core/appsettings.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinylit/codearts/5002d35735f4dc5318737bca346f261af199dc3b/Tests/Mvc.Core/appsettings.json -------------------------------------------------------------------------------- /Tests/Mvc.Core2_1/Domain/Entities/User.cs: -------------------------------------------------------------------------------- 1 | using CodeArts; 2 | using CodeArts.Db; 3 | using System.ComponentModel.DataAnnotations; 4 | 5 | namespace Mvc.Core2_1.Domain.Entities 6 | { 7 | /// 8 | /// 用户信息表。 9 | /// 10 | [DbConfig("connectionStrings:default")] 11 | [Naming("yep_users", NamingType.UrlCase)] 12 | public class User : BaseEntity 13 | { 14 | /// 15 | /// 机构ID。 16 | /// 17 | public ulong OrgId { get; set; } 18 | /// 19 | /// 公司ID。 20 | /// 21 | public long CompanyId { get; set; } 22 | /// 23 | /// 账户。 24 | /// 25 | [Display(Name = "用户账户")] 26 | [Required(ErrorMessage = "{0}为必填项!")] 27 | public string Account { get; set; } 28 | /// 29 | /// 用户名称。 30 | /// 31 | [Display(Name = "用户名称")] 32 | [Required(ErrorMessage = "{0}为必填项!")] 33 | public string Name { get; set; } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Tests/Mvc.Core2_1/Domain/UserRepository.cs: -------------------------------------------------------------------------------- 1 | using Mvc.Core2_1.Domain.Entities; 2 | using CodeArts.Db; 3 | using CodeArts.Db.Lts; 4 | 5 | namespace Mvc.Core2_1.Domain 6 | { 7 | /// 8 | /// 用户仓库。 9 | /// 10 | [DbConfig] 11 | public class UserRepository : DbRepository 12 | { 13 | 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Tests/Mvc.Core2_1/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace Mvc.Core2_1 12 | { 13 | /// 14 | public class Program 15 | { 16 | /// 17 | public static void Main(string[] args) 18 | { 19 | CreateWebHostBuilder(args).Build().Run(); 20 | } 21 | /// 22 | public static IWebHostBuilder CreateWebHostBuilder(string[] args) => 23 | WebHost.CreateDefaultBuilder(args) 24 | .UseStartup(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Tests/Mvc.Core2_1/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Debug", 5 | "System": "Information", 6 | "Microsoft": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Tests/Mvc.Core2_1/appsettings.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinylit/codearts/5002d35735f4dc5318737bca346f261af199dc3b/Tests/Mvc.Core2_1/appsettings.json -------------------------------------------------------------------------------- /Tests/Mvc.Core2_1/log4net.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Tests/Mvc4/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的常规信息通过下列特性集 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("Mvc4")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Mvc4")] 13 | [assembly: AssemblyCopyright("Copyright © 2019")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 会使此程序集中的类型 18 | // 对 COM 组件不可见。如果需要 19 | // 从 COM 访问此程序集中的某个类型,请针对该类型将 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于 typelib 的 ID 23 | [assembly: Guid("92857809-f149-4e3c-835f-f2a3e0b5d3f1")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 内部版本号 30 | // 修订版本 31 | // 32 | // 可以指定所有值,也可以使用“修订号”和“内部版本号”的默认值, 33 | // 方法是按如下所示使用 "*": 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /Tests/Mvc4/Startup.cs: -------------------------------------------------------------------------------- 1 | using CodeArts; 2 | using CodeArts.Mvc; 3 | using CodeArts.Mvc.Builder; 4 | using Microsoft.Extensions.DependencyInjection; 5 | using System; 6 | 7 | namespace Mvc4 8 | { 9 | public class Startup : JwtStartup 10 | { 11 | public Startup() 12 | { 13 | using (var startup = new XStartup()) 14 | { 15 | startup.DoStartup(); 16 | } 17 | } 18 | public void Configure(IApplicationBuilder builder, IServiceProvider serviceProvider) 19 | { 20 | base.Configure(builder.MapPost("/test", "/api/values/test")); 21 | } 22 | 23 | /// 24 | public void ConfigureServices(IServiceCollection services) 25 | { 26 | services.UseDependencyInjection(); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /Tests/Mvc4/Views/TestView.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | 6 | namespace Mvc4.Views 7 | { 8 | public class TestView 9 | { 10 | public int Id { get; set; } 11 | 12 | public string Name { get; set; } 13 | } 14 | } -------------------------------------------------------------------------------- /Tests/Mvc4/Web.Debug.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 30 | 31 | -------------------------------------------------------------------------------- /Tests/Mvc4/Web.Release.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 19 | 31 | 32 | -------------------------------------------------------------------------------- /Tests/Mvc4/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Tests/Mvc45/Controllers/ValuesController.cs: -------------------------------------------------------------------------------- 1 | using CodeArts; 2 | using CodeArts.Exceptions; 3 | using CodeArts.Mvc; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Web.Http; 7 | 8 | namespace Mvc45.Controllers 9 | { 10 | /// 11 | public interface IDependency 12 | { 13 | 14 | } 15 | /// 16 | public class Dependency : IDependency 17 | { 18 | 19 | } 20 | 21 | /// 22 | public class ValuesController : BaseController 23 | { 24 | /// 25 | public ValuesController(IDependency dependency) 26 | { 27 | } 28 | 29 | /// 30 | [HttpGet] 31 | public IEnumerable Get() 32 | { 33 | return new string[] { "value1", "value2" }; 34 | } 35 | 36 | /// 37 | [HttpPost] 38 | public void Post([FromBody] string value) 39 | { 40 | } 41 | 42 | /// 43 | [HttpPut] 44 | public void Put(int id, [FromBody] string value) 45 | { 46 | } 47 | 48 | /// 49 | [Authorize] 50 | [HttpDelete] 51 | public void Delete(int id) 52 | { 53 | throw new BusiException("认证测试成功"); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Tests/Mvc45/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的常规信息通过下列特性集 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("Mvc45")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Mvc45")] 13 | [assembly: AssemblyCopyright("Copyright © 2019")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 会使此程序集中的类型 18 | // 对 COM 组件不可见。如果需要 19 | // 从 COM 访问此程序集中的某个类型,请针对该类型将 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于 typelib 的 ID 23 | [assembly: Guid("760f79bb-86ec-4a71-b65e-3cbda370fed1")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 内部版本号 30 | // 修订版本 31 | // 32 | // 可以指定所有值,也可以使用“修订号”和“内部版本号”的默认值, 33 | // 方法是按如下所示使用 "*": 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /Tests/Mvc45/Startup.cs: -------------------------------------------------------------------------------- 1 | using CodeArts; 2 | using CodeArts.Mvc; 3 | using Microsoft.Extensions.DependencyInjection; 4 | 5 | namespace Mvc45 6 | { 7 | public class Startup : JwtStartup 8 | { 9 | public Startup() 10 | { 11 | using (var startup = new XStartup()) 12 | { 13 | startup.DoStartup(); 14 | } 15 | } 16 | 17 | /// 18 | public void ConfigureServices(IServiceCollection services) 19 | { 20 | services.UseDependencyInjection(); 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /Tests/Mvc45/Web.Debug.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 30 | 31 | -------------------------------------------------------------------------------- /Tests/Mvc45/Web.Release.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 19 | 31 | 32 | -------------------------------------------------------------------------------- /Tests/Mvc45/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /codearts.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinylit/codearts/5002d35735f4dc5318737bca346f261af199dc3b/codearts.png -------------------------------------------------------------------------------- /project.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "netstandard.library": "1.6.0" 4 | }, 5 | "frameworks": { 6 | "netstandard2.0": { 7 | "imports": "dnxcore50" 8 | }, 9 | "net40": {} 10 | }, 11 | "buildOptions": { 12 | "xmlDoc": true 13 | } 14 | } -------------------------------------------------------------------------------- /src/CodeArts.Caching/CodeArts.Caching.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net461;net45;net40;netstandard2.0;netstandard2.1; 5 | $(LibraryFrameworks) 6 | false 7 | true 8 | 8.1.5 9 | Tiny Lit 10 | Tiny Lit 11 | The caching control center. 12 | https://github.com/tinylit/codearts/blob/master/LICENSE.txt 13 | https://github.com/tinylit/codearts 14 | git 15 | https://github.com/tinylit/codearts/blob/master/LICENSE.txt 16 | https://raw.githubusercontent.com/tinylit/codearts/master/codearts.png 17 | https://github.com/tinylit/codearts 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/CodeArts.Caching/ICachingProvider.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace CodeArts.Caching 3 | { 4 | /// 5 | /// 缓存服务供应商。 6 | /// 7 | public interface ICachingProvider 8 | { 9 | /// 获取缓存对象。 10 | /// 缓存名称。 11 | /// 12 | ICaching GetCache(string name); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/CodeArts.Caching/Level.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel; 3 | 4 | namespace CodeArts.Caching 5 | { 6 | /// 缓存级别。 7 | [Flags] 8 | public enum Level 9 | { 10 | /// 一级缓存,本机内存。 11 | [Description("一级缓存")] 12 | First = 1, 13 | 14 | /// 二级缓存,分布式。 15 | [Description("二级缓存")] 16 | Second = 2, 17 | 18 | /// 三级缓存,预留。 19 | [Description("三级缓存")] 20 | Third = 4 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/CodeArts.Casting/CastingStartup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace CodeArts.Casting 8 | { 9 | /// 10 | /// 启动。 11 | /// 12 | public class CastingStartup : IStartup 13 | { 14 | /// 15 | /// 功能码。 16 | /// 17 | public int Code => 100; 18 | 19 | /// 20 | /// 权重。 21 | /// 22 | public int Weight => 1; 23 | 24 | /// 25 | /// 启动。 26 | /// 27 | public void Startup() => RuntimeServPools.TryAddSingleton(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/CodeArts.Casting/CodeArts.Casting.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net461;net45;net40;netstandard2.0;netstandard2.1; 5 | $(LibraryFrameworks) 6 | false 7 | true 8 | 8.1.5 9 | Tiny Lit 10 | Tiny Lit 11 | The type conversion. 12 | https://github.com/tinylit/codearts/blob/master/LICENSE.txt 13 | https://github.com/tinylit/codearts 14 | git 15 | https://github.com/tinylit/codearts/blob/master/LICENSE.txt 16 | https://raw.githubusercontent.com/tinylit/codearts/master/codearts.png 17 | https://github.com/tinylit/codearts 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/CodeArts.Casting/IMapConfiguration.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq.Expressions; 3 | 4 | namespace CodeArts.Casting 5 | { 6 | /// 7 | /// 映射。 8 | /// 9 | public interface IMapConfiguration : IProfileConfiguration 10 | { 11 | /// 12 | /// 映射。 13 | /// 14 | /// 结果类型。 15 | /// 源对象。 16 | /// 默认值。 17 | /// 18 | TResult Map(object source, TResult def = default); 19 | 20 | /// 21 | /// 映射。 22 | /// 23 | /// 源数据。 24 | /// 目标类型。 25 | /// 目标默认值。 26 | /// 27 | Expression Map(Expression sourceExpression, Type conversionType, Expression def = null); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/CodeArts.Casting/IMapExpression.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CodeArts.Casting 4 | { 5 | /// 6 | /// 映射。 7 | /// 8 | public interface IMapExpression 9 | { 10 | /// 11 | /// 是否匹配。 12 | /// 13 | /// 源类型。 14 | /// 目标类型。 15 | /// 16 | bool IsMatch(Type sourceType, Type conversionType); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/CodeArts.Casting/IProfile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CodeArts.Casting 4 | { 5 | /// 6 | /// 配置文件。 7 | /// 8 | public interface IProfile 9 | { 10 | /// 11 | /// 创建工厂。 12 | /// 13 | /// 源数据类型。 14 | /// 目标数据类型。 15 | /// 16 | Func CreateMap(Type sourceType); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/CodeArts.Casting/IProfileConfiguration.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CodeArts.Casting 4 | { 5 | /// 6 | /// 拷贝配置。 7 | /// 8 | public interface IProfileConfiguration 9 | { 10 | /// 11 | /// 匹配模式。 12 | /// 13 | PatternKind Kind { get; } 14 | 15 | /// 16 | /// 深度映射。 17 | /// 18 | bool? IsDepthMapping { get; } 19 | 20 | /// 21 | /// 允许空值传播映射。 22 | /// 23 | bool? AllowNullMapping { get; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/CodeArts.Casting/IProfileExpression.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace CodeArts.Casting 5 | { 6 | /// 7 | /// 表达式配置。 8 | /// 9 | public interface IProfileExpression 10 | { 11 | /// 12 | /// 映射。 13 | /// 14 | /// 目标类型。 15 | /// 判断源类型是否支持转到目标类型。 16 | /// 将对象转为目标类型的方案。 17 | void Map(Predicate predicate, Func project); 18 | 19 | /// 20 | /// 映射。 21 | /// 22 | /// 源类型。 23 | /// 目标类型。 24 | /// 将对象转为目标类型的方案。 25 | void Absolute(Func project); 26 | 27 | /// 28 | /// 运行(目标类型和源类型相同,或目标类型继承或实现源类型)。 29 | /// 30 | /// 源数据类型。 31 | /// 目标类型。 32 | /// 将源数据转为目标数据的方案。 33 | void Run(Func project); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/CodeArts.Casting/IProfileMap.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace CodeArts.Casting 8 | { 9 | /// 10 | /// 映射配置。 11 | /// 12 | public interface IProfileMap : IProfile, IProfileConfiguration 13 | { 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/CodeArts.Casting/ProfileConfiguration.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CodeArts.Casting 4 | { 5 | /// 6 | /// 克隆配置。 7 | /// 8 | public sealed class ProfileConfiguration : IProfileConfiguration 9 | { 10 | /// 11 | /// 匹配模式。 12 | /// 13 | public PatternKind Kind { get; set; } = PatternKind.Property; 14 | 15 | /// 16 | /// 深度映射。 17 | /// 18 | public bool? IsDepthMapping { get; set; } 19 | 20 | /// 21 | /// 允许空值传播映射。 22 | /// 23 | public bool? AllowNullMapping { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/CodeArts.Configuration/ConfigurationStartup.cs: -------------------------------------------------------------------------------- 1 | using CodeArts.Config; 2 | 3 | namespace CodeArts 4 | { 5 | /// 6 | /// 配置文件启动项。 7 | /// 8 | public class ConfigurationStartup : IStartup 9 | { 10 | /// 11 | /// 代码(200)。 12 | /// 13 | public int Code => 200; 14 | 15 | /// 16 | /// 权重。 17 | /// 18 | public int Weight => 1; 19 | 20 | /// 21 | /// 启动。 22 | /// 23 | public void Startup() => RuntimeServPools.TryAddSingleton(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/CodeArts.Db.EntityFramework.SqlServer/SqlServerLinqAdapter.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | 3 | namespace CodeArts.Db.EntityFramework 4 | { 5 | /// 6 | /// SqlServer 适配器。 7 | /// 8 | public class SqlServerLinqAdapter : SqlServerAdapter, IDbConnectionLinqAdapter, IDbConnectionAdapter, IDbConnectionFactory 9 | { 10 | /// 11 | /// 配置SqlServer支持。 12 | /// 13 | /// 配置器。 14 | /// 链接配置。 15 | public virtual void OnConfiguring(DbContextOptionsBuilder optionsBuilder, IReadOnlyConnectionConfig connectionConfig) => optionsBuilder.UseSqlServer(connectionConfig.ConnectionString); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/CodeArts.Db.EntityFramework.Sqlite/SqliteLinqAdapter.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | 3 | namespace CodeArts.Db.EntityFramework 4 | { 5 | /// 6 | /// SqlServer 适配器。 7 | /// 8 | public class SqliteLinqAdapter : SqliteAdapter, IDbConnectionLinqAdapter, IDbConnectionAdapter, IDbConnectionFactory 9 | { 10 | /// 11 | /// 配置SqlServer支持。 12 | /// 13 | /// 配置器。 14 | /// 链接配置。 15 | public virtual void OnConfiguring(DbContextOptionsBuilder optionsBuilder, IReadOnlyConnectionConfig connectionConfig) => optionsBuilder.UseSqlite(connectionConfig.ConnectionString); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/CodeArts.Db.EntityFramework/DbTransactionProvider.cs: -------------------------------------------------------------------------------- 1 | #if NETSTANDARD2_0_OR_GREATER 2 | using Microsoft.EntityFrameworkCore; 3 | #else 4 | using System.Data.Entity; 5 | #endif 6 | 7 | namespace CodeArts.Db.EntityFramework 8 | { 9 | /// 10 | /// 数据供应器。 11 | /// 12 | public class DbTransactionProvider : IDbTransactionProvider 13 | { 14 | /// 15 | /// 使用事务。 16 | /// 17 | /// 上下文集合。 18 | /// 19 | public IDbTransaction BeginTransaction(params DbContext[] dbContexts) => new DbTransaction(dbContexts); 20 | 21 | /// 22 | /// 使用事务。 23 | /// 24 | /// 仓库集合。 25 | /// 26 | public IDbTransaction BeginTransaction(params ILinqRepository[] repositories) => new DbTransaction(repositories); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/CodeArts.Db.EntityFramework/IDbConnectionLinqAdapter.cs: -------------------------------------------------------------------------------- 1 | #if NETSTANDARD2_0_OR_GREATER 2 | using Microsoft.EntityFrameworkCore; 3 | 4 | namespace CodeArts.Db.EntityFramework 5 | { 6 | /// 7 | /// 数据连接适配器。 8 | /// 9 | public interface IDbConnectionLinqAdapter : IDbConnectionAdapter 10 | { 11 | /// 12 | /// 连接配置。 13 | /// 14 | /// 构造器。 15 | /// 数据库连接配置。 16 | void OnConfiguring(DbContextOptionsBuilder optionsBuilder, IReadOnlyConnectionConfig connectionConfig); 17 | } 18 | } 19 | #endif -------------------------------------------------------------------------------- /src/CodeArts.Db.EntityFramework/IDbTransactionProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | #if NETSTANDARD2_0_OR_GREATER 3 | using Microsoft.EntityFrameworkCore; 4 | #else 5 | using System.Data.Entity; 6 | #endif 7 | 8 | namespace CodeArts.Db.EntityFramework 9 | { 10 | /// 11 | /// 数据供应器。 12 | /// 13 | public interface IDbTransactionProvider 14 | { 15 | /// 16 | /// 使用事务。 17 | /// 18 | /// 上下文集合。 19 | /// 20 | IDbTransaction BeginTransaction(params DbContext[] dbContexts); 21 | 22 | /// 23 | /// 使用事务。 24 | /// 25 | /// 仓库集合。 26 | /// 27 | IDbTransaction BeginTransaction(params ILinqRepository[] repositories); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/CodeArts.Db.Linq2Sql/CommandBehavior.cs: -------------------------------------------------------------------------------- 1 | namespace CodeArts.Db 2 | { 3 | /// 4 | /// 执行行为。 5 | /// 6 | public enum ActionBehavior 7 | { 8 | /// 9 | /// 查询。 10 | /// 11 | Select = 0, 12 | /// 13 | /// 更新。 14 | /// 15 | Update = 1, 16 | /// 17 | /// 删除。 18 | /// 19 | Delete = 2, 20 | /// 21 | /// 插入。 22 | /// 23 | Insert = 3 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/CodeArts.Db.Linq2Sql/CustomVisitorList.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace CodeArts.Db 4 | { 5 | /// 6 | /// 自定义表达式集合。 7 | /// 8 | public class CustomVisitorList : List, ICustomVisitorList 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/CodeArts.Db.Linq2Sql/Expressions/JoinSelectVisitor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | 4 | namespace CodeArts.Db.Expressions 5 | { 6 | /// 7 | /// Join (Select //...) 8 | /// 9 | public sealed class JoinSelectVisitor : SelectVisitor 10 | { 11 | private JoinSelectVisitor(BaseVisitor visitor) : base(visitor, true) 12 | { 13 | 14 | } 15 | 16 | /// 17 | public JoinSelectVisitor(JoinVisitor visitor) : base(visitor, true) 18 | { 19 | } 20 | 21 | /// 22 | public override SelectVisitor CreateInstance(BaseVisitor baseVisitor) => new JoinSelectVisitor(baseVisitor); 23 | 24 | /// 25 | protected override void DefMemberAs(string field, string alias) 26 | { 27 | } 28 | 29 | /// 30 | protected override void DefNewMemberAs(MemberInfo memberInfo, Type memberOfHostType) 31 | { 32 | if (memberInfo.ReflectedType != memberOfHostType && memberInfo.DeclaringType != memberOfHostType) 33 | { 34 | writer.As(memberInfo.Name); 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/CodeArts.Db.Linq2Sql/Expressions/NestedContainsVisitor.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using System.Linq.Expressions; 3 | 4 | namespace CodeArts.Db.Expressions 5 | { 6 | /// 7 | /// . 8 | /// 9 | public class NestedContainsVisitor : BaseVisitor 10 | { 11 | /// 12 | public NestedContainsVisitor(BaseVisitor visitor) : base(visitor, false) 13 | { 14 | } 15 | 16 | /// 17 | public override bool CanResolve(MethodCallExpression node) => node.Method.DeclaringType == Types.Queryable && node.Method.Name == MethodCall.Contains && node.Arguments.Count == 2 && !IsPlainVariable(node.Arguments[1]); 18 | 19 | /// 20 | protected override void StartupCore(MethodCallExpression node) 21 | { 22 | base.Visit(node.Arguments[1]); 23 | 24 | writer.Contains(); 25 | 26 | writer.OpenBrace(); 27 | 28 | using (var visitor = new SelectVisitor(this)) 29 | { 30 | visitor.Startup(node.Arguments[0]); 31 | } 32 | 33 | writer.CloseBrace(); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/CodeArts.Db.Linq2Sql/ICustomVisitor.cs: -------------------------------------------------------------------------------- 1 | using System.Linq.Expressions; 2 | 3 | namespace CodeArts.Db 4 | { 5 | /// 6 | /// 自定义的访问器。 7 | /// 8 | public interface ICustomVisitor : IVisitor 9 | { 10 | /// 11 | /// 表达式分析。 12 | /// 13 | /// 访问器。 14 | /// SQL写入器。 15 | /// 表达式。 16 | void Visit(ExpressionVisitor visitor, Writer writer, MethodCallExpression node); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/CodeArts.Db.Linq2Sql/ICustomVisitorList.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace CodeArts.Db 4 | { 5 | /// 6 | /// 自定义表达式集合。 7 | /// 8 | public interface ICustomVisitorList : IList 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/CodeArts.Db.Linq2Sql/IExecuteVisitor.cs: -------------------------------------------------------------------------------- 1 | using System.Data; 2 | 3 | namespace CodeArts.Db 4 | { 5 | /// 6 | /// 执行能力访问器。 7 | /// 8 | public interface IExecuteVisitor : IStartupVisitor 9 | { 10 | /// 11 | /// SQL语句。 12 | /// 13 | /// 14 | CommandSql ToSQL(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/CodeArts.Db.Linq2Sql/IQueryVisitor.cs: -------------------------------------------------------------------------------- 1 | namespace CodeArts.Db 2 | { 3 | /// 4 | /// 查询访问器。 5 | /// 6 | public interface IQueryVisitor : IStartupVisitor 7 | { 8 | /// 9 | /// SQL语句。 10 | /// 11 | /// 12 | CommandSql ToSQL(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/CodeArts.Db.Linq2Sql/IStartupVisitor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq.Expressions; 3 | 4 | namespace CodeArts.Db 5 | { 6 | /// 7 | /// 启动访问器。 8 | /// 9 | public interface IStartupVisitor : IVisitor, IDisposable 10 | { 11 | /// 12 | /// 启动。 13 | /// 14 | /// 分析表达式。 15 | /// 16 | void Startup(Expression node); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/CodeArts.Db.Linq2Sql/IVisitor.cs: -------------------------------------------------------------------------------- 1 | using System.Linq.Expressions; 2 | 3 | namespace CodeArts.Db 4 | { 5 | /// 6 | /// 访问器。 7 | /// 8 | public interface IVisitor 9 | { 10 | /// 11 | /// 能否解决表达式。 12 | /// 13 | /// 表达式。 14 | /// 15 | bool CanResolve(MethodCallExpression node); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/CodeArts.Db.Linq2Sql/IWriterMap.cs: -------------------------------------------------------------------------------- 1 | namespace CodeArts.Db 2 | { 3 | /// 4 | /// SQL写入器。 5 | /// 6 | public interface IWriterMap 7 | { 8 | /// 9 | /// 逗号。 10 | /// 11 | string Delimiter { get; } 12 | 13 | /// 14 | /// 左括号。 15 | /// 16 | string OpenBrace { get; } 17 | 18 | /// 19 | /// 右括号。 20 | /// 21 | string CloseBrace { get; } 22 | 23 | /// 24 | /// 空字符。 25 | /// 26 | string EmptyString { get; } 27 | 28 | /// 29 | /// 空格。 30 | /// 31 | string WhiteSpace { get; } 32 | 33 | /// 34 | /// 参数名称。 35 | /// 36 | /// 名称。 37 | /// 38 | string ParamterName(string name); 39 | 40 | /// 41 | /// 写入字段名。 42 | /// 43 | /// 名称。 44 | string Name(string name); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/CodeArts.Db.Lts.MySql/MySqlLtsAdapter.cs: -------------------------------------------------------------------------------- 1 | namespace CodeArts.Db.Lts 2 | { 3 | /// 4 | /// MySQL 适配器。 5 | /// 6 | public class MySqlLtsAdapter : MySqlAdapter, IDbConnectionLtsAdapter, IDbConnectionAdapter, IDbConnectionFactory 7 | { 8 | private CustomVisitorList visitters; 9 | 10 | /// 11 | /// 格式化。 12 | /// 13 | #if NETSTANDARD2_1_OR_GREATER 14 | public ICustomVisitorList Visitors => visitters ??= new CustomVisitorList(); 15 | #else 16 | public ICustomVisitorList Visitors => visitters ?? (visitters = new CustomVisitorList()); 17 | #endif 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/CodeArts.Db.Lts.SqlServer/SqlServer2012LtsAdapter.cs: -------------------------------------------------------------------------------- 1 | namespace CodeArts.Db.Lts 2 | { 3 | /// 4 | /// SqlServer 2012 适配器(OFFSET/FETCH NEXT)。 5 | /// 6 | public class SqlServer2012LtsAdapter : SqlServer2012Adapter, IDbConnectionLtsAdapter, IDbConnectionAdapter, IDbConnectionFactory 7 | { 8 | private CustomVisitorList visitters; 9 | 10 | /// 11 | /// 格式化。 12 | /// 13 | #if NETSTANDARD2_1_OR_GREATER 14 | public ICustomVisitorList Visitors => visitters ??= new CustomVisitorList(); 15 | #else 16 | public ICustomVisitorList Visitors => visitters ?? (visitters = new CustomVisitorList()); 17 | #endif 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/CodeArts.Db.Lts.SqlServer/SqlServerLtsAdapter.cs: -------------------------------------------------------------------------------- 1 | namespace CodeArts.Db.Lts 2 | { 3 | /// 4 | /// SqlServer 适配器。 5 | /// 6 | public class SqlServerLtsAdapter : SqlServerAdapter, IDbConnectionLtsAdapter, IDbConnectionAdapter, IDbConnectionFactory 7 | { 8 | private CustomVisitorList visitters; 9 | 10 | /// 11 | /// 格式化。 12 | /// 13 | #if NETSTANDARD2_1_OR_GREATER 14 | public ICustomVisitorList Visitors => visitters ??= new CustomVisitorList(); 15 | #else 16 | public ICustomVisitorList Visitors => visitters ?? (visitters = new CustomVisitorList()); 17 | #endif 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/CodeArts.Db.Lts/Extentions/QueryableAsyncExtentions.cs: -------------------------------------------------------------------------------- 1 | #if NET45_OR_GREATER || NETSTANDARD2_0_OR_GREATER 2 | using CodeArts; 3 | using System.Linq; 4 | using System.Threading; 5 | using System.Threading.Tasks; 6 | 7 | namespace System.LinqAsync 8 | { 9 | /// 10 | /// 异步查询扩展。 11 | /// 12 | public static class QueryableAsyncExtentions 13 | { 14 | /// 15 | /// 转分页数据。 16 | /// 17 | /// 源。 18 | /// 源。 19 | /// 页码(索引从“0”开始)。 20 | /// 分页条数。 21 | /// 取消。 22 | /// 23 | public static async Task> ToListAsync(this IQueryable source, int page, int size, CancellationToken cancellationToken = default) 24 | { 25 | var count_task = source 26 | .CountAsync(cancellationToken) 27 | .ConfigureAwait(false); 28 | 29 | var result_task = source 30 | .Skip(size * page) 31 | .Take(size) 32 | .ToListAsync(cancellationToken) 33 | .ConfigureAwait(false); 34 | 35 | return new PagedList(await result_task, page, size, await count_task); 36 | } 37 | } 38 | } 39 | #endif -------------------------------------------------------------------------------- /src/CodeArts.Db.Lts/IAsyncQueryProvider.cs: -------------------------------------------------------------------------------- 1 | #if NET45_OR_GREATER || NETSTANDARD2_0_OR_GREATER 2 | using System.Linq.Expressions; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | 6 | namespace System.Linq 7 | { 8 | 9 | /// 10 | /// 异步查询器。 11 | /// 12 | public interface IAsyncQueryProvider : IQueryProvider 13 | { 14 | /// 15 | /// 执行结果。 16 | /// 17 | /// 结果。 18 | /// 表达式。 19 | /// 取消。 20 | /// 21 | Task ExecuteAsync(Expression expression, CancellationToken cancellationToken = default); 22 | } 23 | } 24 | #endif -------------------------------------------------------------------------------- /src/CodeArts.Db.Lts/IDbConnectionLtsAdapter.cs: -------------------------------------------------------------------------------- 1 | namespace CodeArts.Db.Lts 2 | { 3 | /// 4 | /// 数据库链接适配器。 5 | /// 6 | public interface IDbConnectionLtsAdapter : IDbConnectionAdapter 7 | { 8 | /// 9 | /// 访问器。 10 | /// 11 | ICustomVisitorList Visitors { get; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/CodeArts.Db.Lts/IRepository.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace CodeArts.Db.Lts 6 | { 7 | /// 8 | /// 仓储基本接口。 9 | /// 10 | public interface IRepository : IOrderedQueryable, IQueryable, IEnumerable 11 | { 12 | } 13 | 14 | /// 15 | /// 仓储基本接口。 16 | /// 17 | /// 实体类型。 18 | public interface IRepository : IOrderedQueryable, IQueryable, IEnumerable, IRepository, IOrderedQueryable, IQueryable, IEnumerable 19 | { 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/CodeArts.Db.MySql/MySqlAdapter.cs: -------------------------------------------------------------------------------- 1 | namespace CodeArts.Db 2 | { 3 | /// 4 | /// MySQL 适配器。 5 | /// 6 | public class MySqlAdapter : MySqlFactory, IDbConnectionAdapter, IDbConnectionFactory 7 | { 8 | /// 9 | /// 矫正配置。 10 | /// 11 | public virtual ISQLCorrectSettings Settings => Singleton.Instance; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/CodeArts.Db.MySql/MySqlFactory.cs: -------------------------------------------------------------------------------- 1 | using MySql.Data.MySqlClient; 2 | using System; 3 | using System.Data; 4 | 5 | namespace CodeArts.Db 6 | { 7 | /// 8 | /// MySQL 适配器。 9 | /// 10 | public class MySqlFactory : IDbConnectionFactory 11 | { 12 | /// 13 | /// MySql。 14 | /// 15 | public const string Name = "MySql"; 16 | 17 | /// 18 | /// 适配器名称。 19 | /// 20 | public string ProviderName => Name; 21 | 22 | /// 23 | /// 线程池数量。 24 | /// 25 | public int MaxPoolSize { set; get; } = 100; 26 | 27 | /// 28 | /// 心跳。 29 | /// 30 | public virtual double ConnectionHeartbeat { get; set; } = 5D; 31 | 32 | /// 33 | /// typeof() 34 | /// 35 | public Type DbConnectionType => typeof(MySqlConnection); 36 | 37 | /// 38 | /// 创建数据库连接。 39 | /// 40 | /// 数据库连接字符串。 41 | /// 42 | public virtual IDbConnection Create(string connectionString) => new MySqlConnection(connectionString); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/CodeArts.Db.SqlServer/SqlServer2012Adapter.cs: -------------------------------------------------------------------------------- 1 | namespace CodeArts.Db 2 | { 3 | /// 4 | /// SqlServer 适配器。 5 | /// 6 | public class SqlServer2012Adapter : SqlServerFactory, IDbConnectionAdapter, IDbConnectionFactory 7 | { 8 | /// 9 | /// 矫正配置。 10 | /// 11 | public virtual ISQLCorrectSettings Settings => Singleton.Instance; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/CodeArts.Db.SqlServer/SqlServer2012CorrectSettings.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | 4 | namespace CodeArts.Db 5 | { 6 | /// 7 | /// SqlServer 2012 矫正设置。 8 | /// 9 | public class SqlServer2012CorrectSettings : SqlServerCorrectSettings 10 | { 11 | /// 12 | /// SQL。 13 | /// 14 | /// SQL。 15 | /// 获取“”条数据。 16 | /// 跳过“”条数据。 17 | /// 排序。 18 | /// 19 | public override string ToSQL(string sql, int take, int skip, string orderBy) 20 | { 21 | if (orderBy.IsEmpty()) 22 | { 23 | orderBy = " ORDER BY 1"; 24 | } 25 | 26 | var sb = new StringBuilder(); 27 | 28 | sb.Append(sql) 29 | .Append(orderBy) 30 | .Append(" OFFSET ") 31 | .Append(skip) 32 | .Append(" ROWS"); 33 | 34 | if (take > 0) 35 | { 36 | sb.Append(" FETCH NEXT ") 37 | .Append(take) 38 | .Append(" ROWS ONLY"); 39 | } 40 | 41 | return sb.ToString(); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/CodeArts.Db.SqlServer/SqlServerAdapter.cs: -------------------------------------------------------------------------------- 1 | namespace CodeArts.Db 2 | { 3 | /// 4 | /// SqlServer 适配器。 5 | /// 6 | public class SqlServerAdapter : SqlServerFactory, IDbConnectionAdapter, IDbConnectionFactory 7 | { 8 | /// 9 | /// 矫正配置。 10 | /// 11 | public virtual ISQLCorrectSettings Settings => Singleton.Instance; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/CodeArts.Db.SqlServer/SqlServerFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data; 3 | using System.Data.SqlClient; 4 | 5 | namespace CodeArts.Db 6 | { 7 | /// 8 | /// SqlServer 适配器。 9 | /// 10 | public class SqlServerFactory : IDbConnectionFactory 11 | { 12 | /// 13 | /// SqlServer。 14 | /// 15 | public const string Name = "SqlServer"; 16 | 17 | /// 适配器名称。 18 | public string ProviderName => Name; 19 | 20 | /// 21 | /// 线程池数量。 22 | /// 23 | public int MaxPoolSize { set; get; } = 100; 24 | 25 | /// 26 | /// 心跳。 27 | /// 28 | public virtual double ConnectionHeartbeat { get; set; } = 5D; 29 | 30 | /// 31 | /// typeof() 32 | /// 33 | public Type DbConnectionType => typeof(SqlConnection); 34 | 35 | /// 创建数据库连接。 36 | /// 37 | public virtual IDbConnection Create(string connectionString) => new SqlConnection(connectionString); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/CodeArts.Db.Sqlite/SqliteAdapter.cs: -------------------------------------------------------------------------------- 1 | namespace CodeArts.Db 2 | { 3 | /// 4 | /// Sqlite 适配器。 5 | /// 6 | public class SqliteAdapter : SqliteFactory, IDbConnectionAdapter, IDbConnectionFactory 7 | { 8 | /// 9 | /// 矫正配置。 10 | /// 11 | public virtual ISQLCorrectSettings Settings => Singleton.Instance; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/CodeArts.Db/CommandTypes.cs: -------------------------------------------------------------------------------- 1 | namespace CodeArts.Db 2 | { 3 | /// 4 | /// 命令。 5 | /// 6 | public static class CommandTypes 7 | { 8 | /// 9 | /// 增加。 10 | /// 11 | public static readonly UppercaseString Insert = new UppercaseString("INSERT"); 12 | 13 | /// 14 | /// 删除。 15 | /// 16 | public static readonly UppercaseString Delete = new UppercaseString("DELETE"); 17 | 18 | /// 19 | /// 查询。 20 | /// 21 | public static readonly UppercaseString Select = new UppercaseString("SELECT"); 22 | 23 | /// 24 | /// 更新。 25 | /// 26 | public static readonly UppercaseString Update = new UppercaseString("UPDATE"); 27 | 28 | /// 29 | /// 创建。 30 | /// 31 | public static readonly UppercaseString Create = new UppercaseString("CREATE"); 32 | 33 | /// 34 | /// 更改。 35 | /// 36 | public static readonly UppercaseString Alter = new UppercaseString("ALTER"); 37 | 38 | /// 39 | /// 移除。 40 | /// 41 | public static readonly UppercaseString Drop = new UppercaseString("DROP"); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/CodeArts.Db/ConnectionConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CodeArts.Db 4 | { 5 | /// 6 | /// 数据库连接字符配置。 7 | /// 8 | [Serializable] 9 | public sealed class ConnectionConfig : IConfigable, IReadOnlyConnectionConfig 10 | { 11 | /// 连接名称。 12 | public string Name { get; set; } 13 | 14 | /// 数据库驱动名称。 15 | public string ProviderName { get; set; } 16 | 17 | /// 连接字符串。 18 | public string ConnectionString { get; set; } 19 | 20 | /// 21 | /// 权重。 22 | /// 23 | public int Weight { get; set; } 24 | 25 | /// 26 | /// 监听到变更后的新数据。 27 | /// 28 | /// 变更后的数据。 29 | public void SaveChanges(ConnectionConfig changedValue) 30 | { 31 | if (changedValue is null) 32 | { 33 | return; 34 | } 35 | 36 | Name = changedValue.Name; 37 | ProviderName = changedValue.ProviderName; 38 | ConnectionString = changedValue.ConnectionString; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/CodeArts.Db/DatabaseEngine.cs: -------------------------------------------------------------------------------- 1 | namespace CodeArts.Db 2 | { 3 | /// 4 | /// 数据库引擎。 5 | /// 6 | public enum DatabaseEngine 7 | { 8 | /// 9 | /// 正常。 10 | /// 11 | Normal = 0, 12 | /// 13 | /// Oracle。 14 | /// 15 | Oracle = 1, 16 | /// 17 | /// MySQL。 18 | /// 19 | MySQL = 2, 20 | /// 21 | /// SqlServer。 22 | /// 23 | SqlServer = 3, 24 | /// 25 | /// PostgreSQL。 26 | /// 27 | PostgreSQL = 4, 28 | /// 29 | /// DB2。 30 | /// 31 | DB2 = 5, 32 | /// 33 | /// Sybase。 34 | /// 35 | Sybase = 6, 36 | /// 37 | /// Access。 38 | /// 39 | Access = 7, 40 | /// 41 | /// SQLite。 42 | /// 43 | SQLite = 8 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/CodeArts.Db/DbConfigAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CodeArts.Db 4 | { 5 | /// 6 | /// 数据库连接。 7 | /// 8 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = true, Inherited = false)] 9 | public class DbConfigAttribute : Attribute 10 | { 11 | private readonly string configName; 12 | 13 | /// 14 | /// 默认数据库连接配置。 15 | /// 16 | #if NETSTANDARD2_0_OR_GREATER 17 | public const string DefaultConfigName = "connectionStrings:default"; 18 | #else 19 | public const string DefaultConfigName = "connectionStrings/default"; 20 | #endif 21 | 22 | /// 23 | /// 构造函数(使用默认数据库链接【connectionStrings:default】)。 24 | /// 25 | public DbConfigAttribute() : this(DefaultConfigName) { } 26 | 27 | /// 28 | /// 构造函数(使用默认数据库链接)。 29 | /// 30 | public DbConfigAttribute(string configName) => this.configName = configName ?? throw new ArgumentNullException(nameof(configName)); 31 | 32 | /// 33 | /// 获取数据库链接配置。 34 | /// 35 | /// 36 | public virtual ConnectionConfig GetConfig() => configName.Config(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/CodeArts.Db/DbWriteConfigAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CodeArts.Db 4 | { 5 | /// 6 | /// 可读写的数据库。 7 | /// 8 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = true, Inherited = false)] 9 | public sealed class DbWriteConfigAttribute : DbConfigAttribute 10 | { 11 | /// 12 | /// 构造函数。 13 | /// 14 | public DbWriteConfigAttribute() : base() 15 | { 16 | } 17 | /// 18 | /// 构造函数。 19 | /// 20 | /// 21 | public DbWriteConfigAttribute(string configName) : base(configName) 22 | { 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/CodeArts.Db/Exceptions/DRequiredException.cs: -------------------------------------------------------------------------------- 1 | using CodeArts.Exceptions; 2 | 3 | namespace CodeArts.Db.Exceptions 4 | { 5 | /// 6 | /// 数据必填异常。 7 | /// 8 | public class DRequiredException : CodeException 9 | { 10 | private const string DefaultError = "未查询到满足指定条件的相关信息!"; 11 | /// 12 | /// 构造函数。 13 | /// 14 | public DRequiredException() : base(DefaultError, StatusCodes.DbNotFoundError) 15 | { 16 | } 17 | /// 18 | /// 构造函数。 19 | /// 20 | /// 错误信息。 21 | public DRequiredException(string message) : base(message ?? DefaultError, StatusCodes.DbNotFoundError) 22 | { 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/CodeArts.Db/Exceptions/DSyntaxErrorException.cs: -------------------------------------------------------------------------------- 1 | using CodeArts.Exceptions; 2 | using System; 3 | 4 | namespace CodeArts.Db.Exceptions 5 | { 6 | /// 7 | /// 执行语句语法错误。 8 | /// 9 | public class DSyntaxErrorException : SyntaxException 10 | { 11 | /// 12 | /// 构造函数。 13 | /// 14 | public DSyntaxErrorException() : base("语法异常!") 15 | { 16 | } 17 | 18 | /// 19 | /// 构造函数。 20 | /// 21 | /// 错误信息。 22 | public DSyntaxErrorException(string message) : base(message) 23 | { 24 | } 25 | 26 | /// 27 | /// 构造函数。 28 | /// 29 | /// 错误信息。 30 | /// 引发错误的异常。 31 | public DSyntaxErrorException(string message, Exception innerException) : base(message, innerException) 32 | { 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/CodeArts.Db/Exceptions/NonAuthorizedException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CodeArts.Db.Exceptions 4 | { 5 | /// 6 | /// 未授权的异常。 7 | /// 8 | public class NonAuthorizedException : InvalidOperationException 9 | { 10 | /// 11 | /// 构造函数。 12 | /// 13 | public NonAuthorizedException() 14 | { 15 | } 16 | /// 17 | /// 构造函数。 18 | /// 19 | /// 错误信息。 20 | public NonAuthorizedException(string message) : base(message) 21 | { 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/CodeArts.Db/Exceptions/NotImplementedKeyException.cs: -------------------------------------------------------------------------------- 1 | namespace CodeArts.Db.Exceptions 2 | { 3 | /// 4 | /// 未实现主键异常。 5 | /// 6 | public class NotImplementedKeyException : DException 7 | { 8 | /// 9 | /// 构造函数。 10 | /// 11 | public NotImplementedKeyException() : base() 12 | { 13 | } 14 | /// 15 | /// 构造函数。 16 | /// 17 | /// 错误信息。 18 | public NotImplementedKeyException(string message) : base(message) 19 | { 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/CodeArts.Db/Exceptions/TypeAccessInvalidException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | 4 | namespace CodeArts.Db.Exceptions 5 | { 6 | /// 7 | /// 访问类型无效。 8 | /// 9 | [Serializable] 10 | public class TypeAccessInvalidException : TypeAccessException 11 | { 12 | /// 13 | /// 构造函数。 14 | /// 15 | public TypeAccessInvalidException() 16 | { 17 | } 18 | 19 | /// 20 | /// 构造函数。 21 | /// 22 | /// 错误消息。 23 | public TypeAccessInvalidException(string message) : base(message) 24 | { 25 | } 26 | /// 27 | /// 构造函数。 28 | /// 29 | /// 错误消息。 30 | /// 引发的异常。 31 | public TypeAccessInvalidException(string message, Exception innerException) : base(message, innerException) 32 | { 33 | } 34 | /// 35 | /// 构造函数。 36 | /// 37 | /// 序列化信息。 38 | /// 数据流上下文。 39 | protected TypeAccessInvalidException(SerializationInfo info, StreamingContext context) : base(info, context) 40 | { 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /src/CodeArts.Db/Extentions/QueryableExtentions.cs: -------------------------------------------------------------------------------- 1 | using CodeArts.Db; 2 | using System.Linq.Expressions; 3 | 4 | namespace System.Linq 5 | { 6 | /// 7 | /// 查询器扩展。 8 | /// 9 | public static class QueryableExtentions 10 | { 11 | /// 12 | /// 查询条件。 13 | /// 14 | /// 资源类型。 15 | /// 查询器。 16 | /// 是否追加条件。 17 | /// 条件表达式。 18 | /// 19 | public static IQueryable WhereIf(this IQueryable source, bool condition, Expression> predicate) 20 | { 21 | if (condition) 22 | { 23 | return source.Where(predicate); 24 | } 25 | 26 | return source; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/CodeArts.Db/IDbConnectionAdapter.cs: -------------------------------------------------------------------------------- 1 | namespace CodeArts.Db 2 | { 3 | /// 4 | /// 数据库链接适配器。 5 | /// 6 | public interface IDbConnectionAdapter : IDbConnectionFactory 7 | { 8 | /// 9 | /// SQL矫正设置。 10 | /// 11 | ISQLCorrectSettings Settings { get; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/CodeArts.Db/IDbConnectionFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data; 3 | 4 | namespace CodeArts.Db 5 | { 6 | /// 7 | /// 数据连接工程。 8 | /// 9 | public interface IDbConnectionFactory 10 | { 11 | /// 创建数据库连接。 12 | /// 13 | IDbConnection Create(string connectionString); 14 | 15 | /// 16 | /// 连接类型。 17 | /// 18 | Type DbConnectionType { get; } 19 | 20 | /// 21 | /// 供应器名称。 22 | /// 23 | string ProviderName { get; } 24 | 25 | /// 26 | /// 链接心跳(链接可以在心跳活动时间内被重用不需要重新分配链接,单位:分钟)。 27 | /// 28 | double ConnectionHeartbeat { get; } 29 | 30 | /// 31 | /// 线程池数量。 32 | /// 33 | int MaxPoolSize { get; } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/CodeArts.Db/IDbRouter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq.Expressions; 3 | 4 | namespace CodeArts.Db 5 | { 6 | /// 7 | /// 路由执行提供者。 8 | /// 9 | /// 实体类型。 10 | public interface IDbRouter where TEntity : class, IEntiy 11 | { 12 | /// 13 | /// 动作需要操作的字段。 14 | /// 15 | /// 获取字段的类型。 16 | /// 字段。 17 | /// 18 | string[] Where(Expression> columns); 19 | 20 | /// 21 | /// 动作需要操作的字段。 22 | /// 23 | /// 获取字段的类型。 24 | /// 字段。 25 | /// 26 | string[] Except(Expression> columns); 27 | 28 | /// 29 | /// 动作需要操作的字段。 30 | /// 31 | /// 获取字段的类型。 32 | /// 字段。 33 | /// 34 | string[] Limit(Expression> columns); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/CodeArts.Db/IDispatchConnections.cs: -------------------------------------------------------------------------------- 1 | using System.Data; 2 | 3 | namespace CodeArts.Db 4 | { 5 | /// 6 | /// 连接调度。 7 | /// 8 | public interface IDispatchConnections 9 | { 10 | /// 11 | /// 获取数据库连接。 12 | /// 13 | /// 链接字符串。 14 | /// 数据库工厂器。 15 | /// 使用缓存。 16 | /// 17 | IDbConnection Create(string connectionString, IDbConnectionFactory adapter, bool useCache = true); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/CodeArts.Db/IEntiy.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CodeArts.Db 4 | { 5 | /// 6 | /// 实体基本接口。 7 | /// 8 | public interface IEntiy 9 | { 10 | } 11 | 12 | /// 13 | /// 实体基本接口。 14 | /// 15 | public interface IEntiy : IEntiy where TKey : IEquatable, IComparable 16 | { 17 | /// 18 | /// 主键。 19 | /// 20 | TKey Id { get; set; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/CodeArts.Db/IFormatter.cs: -------------------------------------------------------------------------------- 1 | using System.Text.RegularExpressions; 2 | 3 | namespace CodeArts.Db 4 | { 5 | /// 6 | /// 格式化。 7 | /// 8 | public interface IFormatter 9 | { 10 | /// 11 | /// 表达式。 12 | /// 13 | Regex RegularExpression { get; } 14 | 15 | /// 16 | /// 替换内容。 17 | /// 18 | /// 匹配到的内容。 19 | /// 20 | string Evaluator(Match match); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/CodeArts.Db/IReadOnlyConnectionConfig.cs: -------------------------------------------------------------------------------- 1 | namespace CodeArts.Db 2 | { 3 | /// 4 | /// 只读配置。 5 | /// 6 | public interface IReadOnlyConnectionConfig 7 | { 8 | /// 连接名称。 9 | string Name { get; } 10 | 11 | /// 数据库驱动名称。 12 | string ProviderName { get; } 13 | 14 | /// 连接字符串。 15 | string ConnectionString { get; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/CodeArts.Db/ITableInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | #if NET40 4 | using System.Collections.ObjectModel; 5 | #endif 6 | 7 | 8 | namespace CodeArts.Db 9 | { 10 | /// 11 | /// 范围。 12 | /// 13 | public interface ITableInfo 14 | { 15 | /// 16 | /// 表实体类型。 17 | /// 18 | Type TableType { get; } 19 | 20 | /// 21 | /// 数据库表名称。 22 | /// 23 | string TableName { get; } 24 | 25 | /// 26 | /// 主键。 27 | /// 28 | IReadOnlyCollection Keys { get; } 29 | 30 | /// 31 | /// 只读键。 32 | /// 33 | IReadOnlyCollection ReadOnlys { get; } 34 | 35 | /// 36 | /// 令牌。 37 | /// 38 | IReadOnlyDictionary Tokens { get; } 39 | 40 | /// 41 | /// 可读写的键。 42 | /// 43 | IReadOnlyDictionary ReadWrites { get; } 44 | 45 | /// 46 | /// 属性和字段。 47 | /// 48 | IReadOnlyDictionary ReadOrWrites { get; } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/CodeArts.Db/TokenAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CodeArts.Db 4 | { 5 | /// 6 | /// 令牌(作为更新数据库的唯一标识,会体现在更新的条件语句中)。 7 | /// 8 | [AttributeUsage(AttributeTargets.Property, AllowMultiple = false)] 9 | public abstract class TokenAttribute : Attribute 10 | { 11 | /// 12 | /// 创建新令牌。 13 | /// 14 | /// 15 | public abstract object Create(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/CodeArts.Db/Types.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Linq; 4 | 5 | namespace CodeArts.Db 6 | { 7 | /// 8 | /// 类型。 9 | /// 10 | internal static class Types 11 | { 12 | /// 13 | /// 14 | /// 15 | public static readonly Type String = typeof(string); 16 | 17 | /// 18 | /// 19 | /// 20 | public static readonly Type Guid = typeof(Guid); 21 | 22 | /// 23 | /// 24 | /// 25 | public static readonly Type Version = typeof(Version); 26 | 27 | /// 28 | /// 29 | /// 30 | public static readonly Type DateTime = typeof(DateTime); 31 | 32 | /// 33 | /// 34 | /// 35 | public static readonly Type DateTimeOffset = typeof(DateTimeOffset); 36 | 37 | /// 38 | /// 39 | /// 40 | public static readonly Type Object = typeof(object); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/CodeArts.DependencyInjection.Abstractions/CodeArts.DependencyInjection.Abstractions.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | net461;net45;net40; 4 | false 5 | true 6 | 8.1.0.0 7 | Tiny Lit 8 | Tiny Lit 9 | Compatibility changes based on Microsoft.Extensions.DependencyInjection.Abstractions source code. 10 | https://github.com/tinylit/codearts/blob/master/LICENSE.txt 11 | https://github.com/tinylit/codearts 12 | git 13 | https://github.com/tinylit/codearts/blob/master/LICENSE.txt 14 | https://raw.githubusercontent.com/tinylit/codearts/master/codearts.png 15 | https://github.com/tinylit/codearts 16 | 17 | 18 | 19 | $(DefineConstants);NET45_OR_GREATER 20 | true 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/CodeArts.DependencyInjection.Abstractions/IServiceCollection.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.Collections.Generic; 5 | 6 | namespace Microsoft.Extensions.DependencyInjection 7 | { 8 | /// 9 | /// Specifies the contract for a collection of service descriptors. 10 | /// 11 | public interface IServiceCollection : IList 12 | { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/CodeArts.DependencyInjection.Abstractions/IServiceProviderFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Microsoft.Extensions.DependencyInjection 4 | { 5 | /// 6 | /// Provides an extension point for creating a container specific builder and an . 7 | /// 8 | public interface IServiceProviderFactory 9 | { 10 | /// 11 | /// Creates a container builder from an . 12 | /// 13 | /// The collection of services 14 | /// A container builder that can be used to create an . 15 | TContainerBuilder CreateBuilder(IServiceCollection services); 16 | 17 | /// 18 | /// Creates an from the container builder. 19 | /// 20 | /// The container builder 21 | /// An 22 | IServiceProvider CreateServiceProvider(TContainerBuilder containerBuilder); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/CodeArts.DependencyInjection.Abstractions/IServiceScope.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | 6 | namespace Microsoft.Extensions.DependencyInjection 7 | { 8 | /// 9 | /// The method ends the scope lifetime. Once Dispose 10 | /// is called, any scoped services that have been resolved from 11 | /// will be 12 | /// disposed. 13 | /// 14 | public interface IServiceScope : IDisposable 15 | { 16 | /// 17 | /// The used to resolve dependencies from the scope. 18 | /// 19 | IServiceProvider ServiceProvider { get; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/CodeArts.DependencyInjection.Abstractions/IServiceScopeFactory.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | namespace Microsoft.Extensions.DependencyInjection 5 | { 6 | /// 7 | /// A factory for creating instances of , which is used to create 8 | /// services within a scope. 9 | /// 10 | public interface IServiceScopeFactory 11 | { 12 | /// 13 | /// Create an which 14 | /// contains an used to resolve dependencies from a 15 | /// newly created scope. 16 | /// 17 | /// 18 | /// An controlling the 19 | /// lifetime of the scope. Once this is disposed, any scoped services that have been resolved 20 | /// from the 21 | /// will also be disposed. 22 | /// 23 | IServiceScope CreateScope(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/CodeArts.DependencyInjection.Abstractions/ISupportRequiredService.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | 6 | namespace Microsoft.Extensions.DependencyInjection 7 | { 8 | /// 9 | /// Optional contract used by 10 | /// to resolve services if supported by . 11 | /// 12 | public interface ISupportRequiredService 13 | { 14 | /// 15 | /// Gets service of type from the implementing 16 | /// this interface. 17 | /// 18 | /// An object that specifies the type of service object to get. 19 | /// A service object of type . 20 | /// Throws an exception if the cannot create the object. 21 | object GetRequiredService(Type serviceType); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/CodeArts.DependencyInjection.Abstractions/ServiceLifetime.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | namespace Microsoft.Extensions.DependencyInjection 5 | { 6 | /// 7 | /// Specifies the lifetime of a service in an . 8 | /// 9 | public enum ServiceLifetime 10 | { 11 | /// 12 | /// Specifies that a single instance of the service will be created. 13 | /// 14 | Singleton, 15 | /// 16 | /// Specifies that a new instance of the service will be created for each scope. 17 | /// 18 | /// 19 | /// In ASP.NET Core applications a scope is created around each server request. 20 | /// 21 | Scoped, 22 | /// 23 | /// Specifies that a new instance of the service will be created every time it is requested. 24 | /// 25 | Transient 26 | } 27 | } -------------------------------------------------------------------------------- /src/CodeArts.DependencyInjection/ServiceLookup/CallSiteExpressionBuilderContext.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.Linq.Expressions; 5 | 6 | namespace Microsoft.Extensions.DependencyInjection.ServiceLookup 7 | { 8 | internal class CallSiteExpressionBuilderContext 9 | { 10 | public ParameterExpression ScopeParameter { get; set; } 11 | public bool RequiresResolvedServices { get; set; } 12 | } 13 | } -------------------------------------------------------------------------------- /src/CodeArts.DependencyInjection/ServiceLookup/CallSiteKind.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.Extensions.DependencyInjection.ServiceLookup 2 | { 3 | internal enum CallSiteKind 4 | { 5 | Factory, 6 | 7 | Constructor, 8 | 9 | Constant, 10 | 11 | IEnumerable, 12 | 13 | ServiceProvider, 14 | 15 | Scope, 16 | 17 | Transient, 18 | 19 | CreateInstance, 20 | 21 | ServiceScopeFactory, 22 | 23 | Singleton 24 | } 25 | } -------------------------------------------------------------------------------- /src/CodeArts.DependencyInjection/ServiceLookup/CallSiteResultCacheLocation.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | namespace Microsoft.Extensions.DependencyInjection.ServiceLookup 5 | { 6 | internal enum CallSiteResultCacheLocation 7 | { 8 | Root, 9 | Scope, 10 | Dispose, 11 | None 12 | } 13 | } -------------------------------------------------------------------------------- /src/CodeArts.DependencyInjection/ServiceLookup/CompiledServiceProviderEngine.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | 7 | namespace Microsoft.Extensions.DependencyInjection.ServiceLookup 8 | { 9 | internal abstract class CompiledServiceProviderEngine : ServiceProviderEngine 10 | { 11 | public ExpressionResolverBuilder ExpressionResolverBuilder { get; } 12 | 13 | public CompiledServiceProviderEngine(IEnumerable serviceDescriptors, IServiceProviderEngineCallback callback) : base(serviceDescriptors, callback) 14 | { 15 | ExpressionResolverBuilder = new ExpressionResolverBuilder(RuntimeResolver, this, Root); 16 | } 17 | 18 | protected override Func RealizeService(ServiceCallSite callSite) 19 | { 20 | var realizedService = ExpressionResolverBuilder.Build(callSite); 21 | RealizedServices[callSite.ServiceType] = realizedService; 22 | return realizedService; 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /src/CodeArts.DependencyInjection/ServiceLookup/ConstantCallSite.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | 6 | namespace Microsoft.Extensions.DependencyInjection.ServiceLookup 7 | { 8 | internal class ConstantCallSite : ServiceCallSite 9 | { 10 | internal object DefaultValue { get; } 11 | 12 | public ConstantCallSite(Type serviceType, object defaultValue): base(ResultCache.None) 13 | { 14 | DefaultValue = defaultValue; 15 | } 16 | 17 | public override Type ServiceType => DefaultValue.GetType(); 18 | public override Type ImplementationType => DefaultValue.GetType(); 19 | public override CallSiteKind Kind { get; } = CallSiteKind.Constant; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/CodeArts.DependencyInjection/ServiceLookup/ConstructorCallSite.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.Reflection; 6 | 7 | namespace Microsoft.Extensions.DependencyInjection.ServiceLookup 8 | { 9 | internal class ConstructorCallSite : ServiceCallSite 10 | { 11 | internal ConstructorInfo ConstructorInfo { get; } 12 | internal ServiceCallSite[] ParameterCallSites { get; } 13 | 14 | public ConstructorCallSite(ResultCache cache, Type serviceType, ConstructorInfo constructorInfo) : this(cache, serviceType, constructorInfo, new ServiceCallSite[0]) 15 | { 16 | } 17 | 18 | public ConstructorCallSite(ResultCache cache, Type serviceType, ConstructorInfo constructorInfo, ServiceCallSite[] parameterCallSites) : base(cache) 19 | { 20 | ServiceType = serviceType; 21 | ConstructorInfo = constructorInfo; 22 | ParameterCallSites = parameterCallSites; 23 | } 24 | 25 | public override Type ServiceType { get; } 26 | 27 | public override Type ImplementationType => ConstructorInfo.DeclaringType; 28 | public override CallSiteKind Kind { get; } = CallSiteKind.Constructor; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/CodeArts.DependencyInjection/ServiceLookup/CreateInstanceCallSite.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.Runtime.ExceptionServices; 6 | 7 | namespace Microsoft.Extensions.DependencyInjection.ServiceLookup 8 | { 9 | } 10 | -------------------------------------------------------------------------------- /src/CodeArts.DependencyInjection/ServiceLookup/DynamicServiceProviderEngine.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Threading; 7 | using System.Threading.Tasks; 8 | 9 | namespace Microsoft.Extensions.DependencyInjection.ServiceLookup 10 | { 11 | internal class DynamicServiceProviderEngine : CompiledServiceProviderEngine 12 | { 13 | public DynamicServiceProviderEngine(IEnumerable serviceDescriptors, IServiceProviderEngineCallback callback) : base(serviceDescriptors, callback) 14 | { 15 | } 16 | 17 | protected override Func RealizeService(ServiceCallSite callSite) 18 | { 19 | var callCount = 0; 20 | return scope => 21 | { 22 | if (Interlocked.Increment(ref callCount) == 2) 23 | { 24 | #if NET40 25 | Task.Factory.StartNew(() => base.RealizeService(callSite)); 26 | #else 27 | Task.Run(() => base.RealizeService(callSite)); 28 | #endif 29 | } 30 | 31 | return RuntimeResolver.Resolve(callSite, scope); 32 | }; 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /src/CodeArts.DependencyInjection/ServiceLookup/Expressions/ExpressionsServiceProviderEngine.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Microsoft.Extensions.DependencyInjection.ServiceLookup 5 | { 6 | internal class ExpressionsServiceProviderEngine : ServiceProviderEngine 7 | { 8 | private readonly ExpressionResolverBuilder _expressionResolverBuilder; 9 | public ExpressionsServiceProviderEngine(IEnumerable serviceDescriptors, IServiceProviderEngineCallback callback) : base(serviceDescriptors, callback) 10 | { 11 | _expressionResolverBuilder = new ExpressionResolverBuilder(RuntimeResolver, this, Root); 12 | } 13 | 14 | protected override Func RealizeService(ServiceCallSite callSite) 15 | { 16 | var realizedService = _expressionResolverBuilder.Build(callSite); 17 | RealizedServices[callSite.ServiceType] = realizedService; 18 | return realizedService; 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /src/CodeArts.DependencyInjection/ServiceLookup/FactoryCallSite.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | 6 | namespace Microsoft.Extensions.DependencyInjection.ServiceLookup 7 | { 8 | internal class FactoryCallSite : ServiceCallSite 9 | { 10 | public Func Factory { get; } 11 | 12 | public FactoryCallSite(ResultCache cache, Type serviceType, Func factory) : base(cache) 13 | { 14 | Factory = factory; 15 | ServiceType = serviceType; 16 | } 17 | 18 | public override Type ServiceType { get; } 19 | public override Type ImplementationType => null; 20 | 21 | public override CallSiteKind Kind { get; } = CallSiteKind.Factory; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/CodeArts.DependencyInjection/ServiceLookup/IEnumerableCallSite.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | 7 | namespace Microsoft.Extensions.DependencyInjection.ServiceLookup 8 | { 9 | internal class IEnumerableCallSite : ServiceCallSite 10 | { 11 | internal Type ItemType { get; } 12 | internal ServiceCallSite[] ServiceCallSites { get; } 13 | 14 | public IEnumerableCallSite(Type itemType, ServiceCallSite[] serviceCallSites) : base(ResultCache.None) 15 | { 16 | ItemType = itemType; 17 | ServiceCallSites = serviceCallSites; 18 | } 19 | 20 | public override Type ServiceType => typeof(IEnumerable<>).MakeGenericType(ItemType); 21 | public override Type ImplementationType => ItemType.MakeArrayType(); 22 | public override CallSiteKind Kind { get; } = CallSiteKind.IEnumerable; 23 | } 24 | } -------------------------------------------------------------------------------- /src/CodeArts.DependencyInjection/ServiceLookup/ILEmit/ILEmitCallSiteAnalysisResult.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | namespace Microsoft.Extensions.DependencyInjection.ServiceLookup 5 | { 6 | internal readonly struct ILEmitCallSiteAnalysisResult 7 | { 8 | public ILEmitCallSiteAnalysisResult(int size) : this() 9 | { 10 | Size = size; 11 | } 12 | 13 | public ILEmitCallSiteAnalysisResult(int size, bool hasScope) 14 | { 15 | Size = size; 16 | HasScope = hasScope; 17 | } 18 | 19 | public readonly int Size; 20 | 21 | public readonly bool HasScope; 22 | 23 | public ILEmitCallSiteAnalysisResult Add(in ILEmitCallSiteAnalysisResult other) => 24 | new ILEmitCallSiteAnalysisResult(Size + other.Size, HasScope | other.HasScope); 25 | } 26 | } -------------------------------------------------------------------------------- /src/CodeArts.DependencyInjection/ServiceLookup/ILEmit/ILEmitResolverBuilderContext.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Reflection.Emit; 7 | 8 | namespace Microsoft.Extensions.DependencyInjection.ServiceLookup 9 | { 10 | internal class ILEmitResolverBuilderContext 11 | { 12 | public ILGenerator Generator { get; set; } 13 | public List Constants { get; set; } 14 | public List> Factories { get; set; } 15 | } 16 | } -------------------------------------------------------------------------------- /src/CodeArts.DependencyInjection/ServiceLookup/ILEmit/ILEmitServiceProviderEngine.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | 7 | namespace Microsoft.Extensions.DependencyInjection.ServiceLookup 8 | { 9 | internal class ILEmitServiceProviderEngine : ServiceProviderEngine 10 | { 11 | private readonly ILEmitResolverBuilder _expressionResolverBuilder; 12 | public ILEmitServiceProviderEngine(IEnumerable serviceDescriptors, IServiceProviderEngineCallback callback) : base(serviceDescriptors, callback) 13 | { 14 | _expressionResolverBuilder = new ILEmitResolverBuilder(RuntimeResolver, this, Root); 15 | } 16 | 17 | protected override Func RealizeService(ServiceCallSite callSite) 18 | { 19 | var realizedService = _expressionResolverBuilder.Build(callSite); 20 | RealizedServices[callSite.ServiceType] = realizedService; 21 | return realizedService; 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /src/CodeArts.DependencyInjection/ServiceLookup/IServiceProviderEngine.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | 6 | namespace Microsoft.Extensions.DependencyInjection.ServiceLookup 7 | { 8 | internal interface IServiceProviderEngine : IDisposable, IServiceProvider 9 | { 10 | IServiceScope RootScope { get; } 11 | } 12 | } -------------------------------------------------------------------------------- /src/CodeArts.DependencyInjection/ServiceLookup/IServiceProviderEngineCallback.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | 6 | namespace Microsoft.Extensions.DependencyInjection.ServiceLookup 7 | { 8 | internal interface IServiceProviderEngineCallback 9 | { 10 | void OnCreate(ServiceCallSite callSite); 11 | void OnResolve(Type serviceType, IServiceScope scope); 12 | } 13 | } -------------------------------------------------------------------------------- /src/CodeArts.DependencyInjection/ServiceLookup/RuntimeServiceProviderEngine.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | 7 | namespace Microsoft.Extensions.DependencyInjection.ServiceLookup 8 | { 9 | internal class RuntimeServiceProviderEngine : ServiceProviderEngine 10 | { 11 | public RuntimeServiceProviderEngine(IEnumerable serviceDescriptors, IServiceProviderEngineCallback callback) : base(serviceDescriptors, callback) 12 | { 13 | } 14 | 15 | protected override Func RealizeService(ServiceCallSite callSite) 16 | { 17 | return scope => 18 | { 19 | Func realizedService = p => RuntimeResolver.Resolve(callSite, p); 20 | 21 | RealizedServices[callSite.ServiceType] = realizedService; 22 | return realizedService(scope); 23 | }; 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /src/CodeArts.DependencyInjection/ServiceLookup/ServiceCallSite.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | 6 | namespace Microsoft.Extensions.DependencyInjection.ServiceLookup 7 | { 8 | /// 9 | /// Summary description for IServiceCallSite 10 | /// 11 | internal abstract class ServiceCallSite 12 | { 13 | protected ServiceCallSite(ResultCache cache) 14 | { 15 | Cache = cache; 16 | } 17 | 18 | public abstract Type ServiceType { get; } 19 | public abstract Type ImplementationType { get; } 20 | public abstract CallSiteKind Kind { get; } 21 | public ResultCache Cache { get; } 22 | } 23 | } -------------------------------------------------------------------------------- /src/CodeArts.DependencyInjection/ServiceLookup/ServiceProviderCallSite.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | 6 | namespace Microsoft.Extensions.DependencyInjection.ServiceLookup 7 | { 8 | internal class ServiceProviderCallSite : ServiceCallSite 9 | { 10 | public ServiceProviderCallSite() : base(ResultCache.None) 11 | { 12 | } 13 | 14 | public override Type ServiceType { get; } = typeof(IServiceProvider); 15 | public override Type ImplementationType { get; } = typeof(ServiceProvider); 16 | public override CallSiteKind Kind { get; } = CallSiteKind.ServiceProvider; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/CodeArts.DependencyInjection/ServiceLookup/ServiceScopeFactoryCallSite.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | 6 | namespace Microsoft.Extensions.DependencyInjection.ServiceLookup 7 | { 8 | internal class ServiceScopeFactoryCallSite : ServiceCallSite 9 | { 10 | public ServiceScopeFactoryCallSite() : base(ResultCache.None) 11 | { 12 | } 13 | 14 | public override Type ServiceType { get; } = typeof(IServiceScopeFactory); 15 | public override Type ImplementationType { get; } = typeof(ServiceProviderEngine); 16 | public override CallSiteKind Kind { get; } = CallSiteKind.ServiceScopeFactory; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/CodeArts.DependencyInjection/ServiceLookup/SingletonCallSite.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | namespace Microsoft.Extensions.DependencyInjection.ServiceLookup 5 | { 6 | } -------------------------------------------------------------------------------- /src/CodeArts.DependencyInjection/ServiceLookup/ThrowHelper.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.Runtime.CompilerServices; 6 | 7 | namespace Microsoft.Extensions.DependencyInjection.ServiceLookup 8 | { 9 | internal class ThrowHelper 10 | { 11 | [MethodImpl(MethodImplOptions.NoInlining)] 12 | internal static void ThrowObjectDisposedException() 13 | { 14 | throw new ObjectDisposedException(nameof(IServiceProvider)); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /src/CodeArts.DependencyInjection/ServiceProviderMode.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | namespace Microsoft.Extensions.DependencyInjection 5 | { 6 | internal enum ServiceProviderMode 7 | { 8 | Dynamic, 9 | Runtime, 10 | Expressions, 11 | ILEmit 12 | } 13 | } -------------------------------------------------------------------------------- /src/CodeArts.DependencyInjection/ServiceProviderOptions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | 6 | namespace Microsoft.Extensions.DependencyInjection 7 | { 8 | /// 9 | /// Options for configuring various behaviors of the default implementation. 10 | /// 11 | public class ServiceProviderOptions 12 | { 13 | // Avoid allocating objects in the default case 14 | internal static readonly ServiceProviderOptions Default = new ServiceProviderOptions(); 15 | 16 | /// 17 | /// true to perform check verifying that scoped services never gets resolved from root provider; otherwise false. 18 | /// 19 | public bool ValidateScopes { get; set; } 20 | 21 | internal ServiceProviderMode Mode { get; set; } = ServiceProviderMode.Dynamic; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/CodeArts.Emit/AstException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CodeArts.Emit 4 | { 5 | /// 6 | /// 表达式异常。 7 | /// 8 | public class AstException : Exception 9 | { 10 | /// 11 | /// 构造函数。 12 | /// 13 | public AstException() 14 | { 15 | } 16 | /// 17 | /// 构造函数。 18 | /// 19 | /// 异常信息。 20 | public AstException(string message) : base(message) 21 | { 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/CodeArts.Emit/CodeArts.Emit.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net461;net45;net40;netstandard2.0;netstandard2.1; 5 | $(LibraryFrameworks) 6 | false 7 | true 8 | 8.1.5 9 | Tiny Lit 10 | Tiny Lit 11 | Provides classes that allow a compiler or tool to emit metadata and optionally generate a PE file on disk. 12 | https://github.com/tinylit/codearts/blob/master/LICENSE.txt 13 | https://github.com/tinylit/codearts 14 | git 15 | https://github.com/tinylit/codearts/blob/master/LICENSE.txt 16 | https://raw.githubusercontent.com/tinylit/codearts/master/codearts.png 17 | https://github.com/tinylit/codearts 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/CodeArts.Emit/Emitters/ClassEmitter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection.Emit; 3 | 4 | namespace CodeArts.Emit 5 | { 6 | /// 7 | /// 类。 8 | /// 9 | public sealed class ClassEmitter : AbstractTypeEmitter 10 | { 11 | /// 12 | /// 构造函数。 13 | /// 14 | /// 类型构造器。 15 | /// 命名。 16 | public ClassEmitter(TypeBuilder builder, INamingScope namingScope) : base(builder, namingScope) 17 | { 18 | } 19 | 20 | /// 21 | /// 创建类型。 22 | /// 23 | /// 24 | public Type CreateType() => Emit(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/CodeArts.Emit/Expressions/ArrayLengthAst.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Reflection.Emit; 4 | 5 | namespace CodeArts.Emit.Expressions 6 | { 7 | /// 8 | /// 数组长度。 9 | /// 10 | [DebuggerDisplay("{array}.Length")] 11 | public class ArrayLengthAst : AstExpression 12 | { 13 | private readonly AstExpression array; 14 | 15 | /// 16 | /// 构造函数。 17 | /// 18 | /// 19 | public ArrayLengthAst(AstExpression array) : base(typeof(int)) 20 | { 21 | this.array = array ?? throw new ArgumentNullException(nameof(array)); 22 | 23 | if (!array.RuntimeType.IsArray || !typeof(Array).IsAssignableFrom(array.RuntimeType) || array.RuntimeType.GetArrayRank() > 1) 24 | { 25 | throw new ArgumentException("不是数组,或不是一维数组!", nameof(array)); 26 | } 27 | } 28 | 29 | /// 30 | /// 加载数据。 31 | /// 32 | /// 指令。 33 | public override void Load(ILGenerator ilg) 34 | { 35 | array.Load(ilg); 36 | 37 | ilg.Emit(OpCodes.Ldlen); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/CodeArts.Emit/Expressions/DefaultAst.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Reflection.Emit; 4 | 5 | namespace CodeArts.Emit.Expressions 6 | { 7 | /// 8 | /// 默认值。 9 | /// 10 | [DebuggerDisplay("default({RuntimeType.Name})")] 11 | public class DefaultAst : AstExpression 12 | { 13 | /// 14 | /// 构造函数。 15 | /// 16 | /// 类型。 17 | public DefaultAst(Type defaultType) : base(defaultType) 18 | { 19 | } 20 | 21 | /// 22 | /// 生成。 23 | /// 24 | /// 指令。 25 | public override void Load(ILGenerator ilg) => EmitUtils.EmitDefaultOfType(ilg, RuntimeType); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/CodeArts.Emit/Expressions/NewArrayAst.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Reflection.Emit; 4 | 5 | namespace CodeArts.Emit.Expressions 6 | { 7 | /// 8 | /// 创建数组。 9 | /// 10 | [DebuggerDisplay("new {RuntimeType.Name}[{size}]")] 11 | public class NewArrayAst : AstExpression 12 | { 13 | private readonly int size; 14 | private readonly Type elementType; 15 | 16 | /// 17 | /// 构造函数【生成object[]】。 18 | /// 19 | /// 数组大小。 20 | public NewArrayAst(int size) : this(size, typeof(object)) 21 | { 22 | } 23 | 24 | /// 25 | /// 构造函数。 26 | /// 27 | /// 数组大小。 28 | /// 数组元素类型。 29 | public NewArrayAst(int size, Type elementType) : base(elementType.MakeArrayType()) 30 | { 31 | this.size = size; 32 | this.elementType = elementType; 33 | } 34 | 35 | /// 36 | /// 生成。 37 | /// 38 | /// 指令。 39 | public override void Load(ILGenerator ilg) 40 | { 41 | ilg.Emit(OpCodes.Ldc_I4, size); 42 | ilg.Emit(OpCodes.Newarr, elementType); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/CodeArts.Emit/INamingScope.cs: -------------------------------------------------------------------------------- 1 | namespace CodeArts.Emit 2 | { 3 | /// 4 | /// 名称供应器。 5 | /// 6 | public interface INamingScope 7 | { 8 | /// 9 | /// 获取范围内唯一的名称。 10 | /// 11 | /// 显示名称。 12 | /// 13 | string GetUniqueName(string displayName); 14 | 15 | /// 16 | /// 子命名范围。 17 | /// 18 | /// 19 | INamingScope BeginScope(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/CodeArts.Emit/Intercept.cs: -------------------------------------------------------------------------------- 1 | namespace CodeArts.Emit 2 | { 3 | /// 4 | /// 拦截执行方法。 5 | /// 6 | public class Intercept 7 | { 8 | /// 9 | /// 调用方法。 10 | /// 11 | /// 上下文。 12 | public virtual void Run(InterceptContext context) => context.Main.Invoke(context.Target, context.Inputs); 13 | } 14 | 15 | /// 16 | /// 拦截执行方法。 17 | /// 18 | public class Intercept 19 | { 20 | /// 21 | /// 调用方法。 22 | /// 23 | /// 上下文。 24 | public virtual T Run(InterceptContext context) => (T)context.Main.Invoke(context.Target, context.Inputs); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/CodeArts.Emit/InterceptAsync.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | 3 | namespace CodeArts.Emit 4 | { 5 | /// 6 | /// 拦截执行方法。 7 | /// 8 | public class InterceptAsync 9 | { 10 | /// 11 | /// 调用方法。 12 | /// 13 | /// 上下文。 14 | public virtual Task RunAsync(InterceptContext context) => (Task)context.Main.Invoke(context.Target, context.Inputs); 15 | } 16 | 17 | /// 18 | /// 拦截执行方法。 19 | /// 20 | public class InterceptAsync 21 | { 22 | /// 23 | /// 调用方法。 24 | /// 25 | /// 上下文。 26 | public virtual Task RunAsync(InterceptContext context) => (Task)context.Main.Invoke(context.Target, context.Inputs); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/CodeArts.Emit/InterceptContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | 4 | namespace CodeArts.Emit 5 | { 6 | /// 7 | /// 拦截上下文。 8 | /// 9 | public class InterceptContext 10 | { 11 | /// 12 | /// 构造函数。 13 | /// 14 | /// 上下文。 15 | /// 调用函数。 16 | /// 函数参数。 17 | public InterceptContext(object target, MethodInfo main, object[] inputs) 18 | { 19 | Target = target ?? throw new ArgumentNullException(nameof(target)); 20 | Main = main ?? throw new ArgumentNullException(nameof(main)); 21 | Inputs = inputs ?? throw new ArgumentNullException(nameof(inputs)); 22 | } 23 | 24 | /// 25 | /// 上下文。 26 | /// 27 | public object Target { get; } 28 | 29 | /// 30 | /// 方法主体。 31 | /// 32 | public MethodInfo Main { get; } 33 | 34 | /// 35 | /// 输入参数。 36 | /// 37 | public object[] Inputs { get; } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/CodeArts.Emit/NamingScope.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace CodeArts.Emit 4 | { 5 | /// 6 | /// 名称提供者。 7 | /// 8 | public class NamingScope : INamingScope 9 | { 10 | private readonly Dictionary names = new Dictionary(); 11 | 12 | /// 13 | /// 子命名范围。 14 | /// 15 | /// 16 | public INamingScope BeginScope() => new NamingScope(); 17 | 18 | /// 19 | /// 获取范围内唯一的名称。 20 | /// 21 | /// 显示名称。 22 | /// 23 | public string GetUniqueName(string displayName) 24 | { 25 | if (names.TryGetValue(displayName, out int counter)) 26 | { 27 | names[displayName] = ++counter; 28 | 29 | return displayName + "_" + counter.ToString(); 30 | } 31 | 32 | names.Add(displayName, 0); 33 | 34 | return displayName; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/CodeArts.Emit/NoninterceptAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CodeArts 4 | { 5 | /// 6 | /// 不拦截拦截属性。 7 | /// 8 | [AttributeUsage( AttributeTargets.Method | AttributeTargets.Property, AllowMultiple = true, Inherited = true)] 9 | public sealed class NoninterceptAttribute : Attribute 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/CodeArts.Json/JsonStartup.cs: -------------------------------------------------------------------------------- 1 | using CodeArts.Serialize.Json; 2 | 3 | namespace CodeArts 4 | { 5 | /// 6 | /// Json 启动器。 7 | /// 8 | public class JsonStartup : IStartup 9 | { 10 | /// 11 | /// 代码(300)。 12 | /// 13 | public int Code => 300; 14 | 15 | /// 16 | /// 权重。 17 | /// 18 | public int Weight => 1; 19 | 20 | /// 21 | /// 启动。 22 | /// 23 | public void Startup() => RuntimeServPools.TryAddSingleton(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/CodeArts.MemoryCaching/MemoryCachingProvider.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Concurrent; 2 | 3 | namespace CodeArts.Caching 4 | { 5 | /// 6 | /// 内存缓存服务提供商。 7 | /// 8 | public class MemoryCachingProvider : ICachingProvider 9 | { 10 | /// 11 | /// 缓存对象。 12 | /// 13 | private readonly ConcurrentDictionary Caches; 14 | 15 | /// 16 | /// 构造函数。 17 | /// 18 | public MemoryCachingProvider() => Caches = new ConcurrentDictionary(); 19 | 20 | /// 获取缓存对象。 21 | /// 缓存名称。 22 | /// 23 | public ICaching GetCache(string regionName) 24 | { 25 | if (regionName is null) 26 | { 27 | throw new System.ArgumentNullException(nameof(regionName)); 28 | } 29 | 30 | if (string.IsNullOrWhiteSpace(regionName)) 31 | { 32 | throw new System.ArgumentException("参数不能为空或空格字符!", nameof(regionName)); 33 | } 34 | 35 | return Caches.GetOrAdd(regionName, name => new MemoryCaching(name)); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/CodeArts.MemoryCaching/MemoryCachingStartup.cs: -------------------------------------------------------------------------------- 1 | namespace CodeArts.Caching 2 | { 3 | /// 4 | /// 内存启动项。 5 | /// 6 | public class MemoryCachingStartup : IStartup 7 | { 8 | /// 9 | /// 代码(450)。 10 | /// 11 | public int Code => 450; 12 | 13 | /// 14 | /// 权重。 15 | /// 16 | public int Weight => 1; 17 | 18 | /// 19 | /// 启动。 20 | /// 21 | public void Startup() => CachingManager.RegisterProvider(new MemoryCachingProvider(), Level.First); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/CodeArts.Middleware/IProxyByPattern.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | 3 | namespace CodeArts 4 | { 5 | /// 6 | /// 代理方式。 7 | /// 8 | public interface IProxyByPattern 9 | { 10 | /// 11 | /// 创建类型。 12 | /// 13 | /// 14 | ServiceDescriptor Resolve(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/CodeArts.Middleware/Proxies/ProxyByFactory.cs: -------------------------------------------------------------------------------- 1 | using CodeArts.Emit; 2 | using Microsoft.Extensions.DependencyInjection; 3 | using System; 4 | 5 | namespace CodeArts.Proxies 6 | { 7 | class ProxyByFactory : ProxyByServiceType 8 | { 9 | private readonly Func implementationFactory; 10 | 11 | public ProxyByFactory(ModuleEmitter moduleEmitter, Type serviceType, Func implementationFactory, ServiceLifetime lifetime) : base(moduleEmitter, serviceType, lifetime) 12 | { 13 | this.implementationFactory = implementationFactory ?? throw new ArgumentNullException(nameof(implementationFactory)); 14 | } 15 | protected override ServiceDescriptor Resolve(Type serviceType, Type implementationType, ServiceLifetime lifetime) 16 | { 17 | return new ServiceDescriptor(serviceType, serviceProvider => 18 | { 19 | var instance = implementationFactory.Invoke(serviceProvider); 20 | 21 | return Activator.CreateInstance(implementationType, instance); 22 | 23 | }, lifetime); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/CodeArts.Middleware/Proxies/ProxyByInstance.cs: -------------------------------------------------------------------------------- 1 | using CodeArts.Emit; 2 | using Microsoft.Extensions.DependencyInjection; 3 | using System; 4 | 5 | namespace CodeArts.Proxies 6 | { 7 | class ProxyByInstance : ProxyByServiceType 8 | { 9 | private readonly object instance; 10 | 11 | public ProxyByInstance(ModuleEmitter moduleEmitter, Type serviceType, object instance) : base(moduleEmitter, serviceType, ServiceLifetime.Singleton) 12 | { 13 | this.instance = instance ?? throw new ArgumentNullException(nameof(instance)); 14 | } 15 | 16 | protected override ServiceDescriptor Resolve(Type serviceType, Type implementationType, ServiceLifetime lifetime) 17 | { 18 | return new ServiceDescriptor(serviceType, Activator.CreateInstance(implementationType, instance)); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/CodeArts.Mvc/Algorithms/HMACSHA256AlgorithmGen.cs: -------------------------------------------------------------------------------- 1 | #if NET40_OR_GREATER 2 | #if !NET461_OR_GREATER 3 | using JWT; 4 | #endif 5 | using JWT.Algorithms; 6 | 7 | namespace CodeArts.Mvc.Algorithms 8 | { 9 | /// 10 | /// HMACSHA256 加密。 11 | /// 12 | public class HMACSHA256AlgorithmGen : IJwtAlgorithmGen 13 | { 14 | /// 15 | /// 创建 JWT 算法。 16 | /// 17 | /// 18 | public IJwtAlgorithm Create() => new HMACSHA256Algorithm(); 19 | } 20 | } 21 | #endif -------------------------------------------------------------------------------- /src/CodeArts.Mvc/Builder/IApplicationBuilder.cs: -------------------------------------------------------------------------------- 1 | #if NET40_OR_GREATER 2 | using System; 3 | #if NET45_OR_GREATER 4 | using System.Threading.Tasks; 5 | #endif 6 | using System.Web; 7 | 8 | namespace CodeArts.Mvc.Builder 9 | { 10 | #if NET40 11 | /// 12 | /// 请求委托。 13 | /// 14 | /// 请求上下文。 15 | /// 16 | public delegate void RequestDelegate(HttpContext context); 17 | #else 18 | /// 19 | /// 请求委托。 20 | /// 21 | /// 请求上下文。 22 | /// 23 | public delegate Task RequestDelegate(HttpContext context); 24 | #endif 25 | /// 26 | /// 程序构造器。 27 | /// 28 | public interface IApplicationBuilder 29 | { 30 | /// 31 | /// 使用中间件。 32 | /// 33 | /// 中间件。 34 | /// 35 | IApplicationBuilder Use(Func middleware); 36 | } 37 | } 38 | #endif -------------------------------------------------------------------------------- /src/CodeArts.Mvc/DependencyInjectionOptions.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | 3 | namespace CodeArts.Mvc 4 | { 5 | /// 6 | /// 依赖注入配置。 7 | /// 8 | public class DependencyInjectionOptions 9 | { 10 | /// 11 | /// 需要依赖注入的.DLL包过滤规则,默认:* 12 | /// 13 | /// 缩小依赖注入程序集范围,作为的第二个参数,默认:“*”。 14 | public string Pattern { get; set; } = "*"; 15 | 16 | /// 17 | /// 最大依赖注入深度,默认:5。 18 | /// 19 | public int MaxDepth { get; set; } = 5; 20 | 21 | /// 22 | /// 参数注入的声明周期,默认:。 23 | /// 24 | public ServiceLifetime Lifetime { get; set; } = ServiceLifetime.Scoped; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/CodeArts.Mvc/HttpVerbs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CodeArts.Mvc 4 | { 5 | /// 6 | /// 请求方式。 7 | /// 8 | [Flags] 9 | public enum HttpVerbs 10 | { 11 | /// 12 | /// Get。 13 | /// 14 | GET = 1, 15 | /// 16 | /// Post。 17 | /// 18 | POST = 2, 19 | /// 20 | /// Put。 21 | /// 22 | PUT = 4, 23 | /// 24 | /// Delete。 25 | /// 26 | DELETE = 8, 27 | /// 28 | /// Head。 29 | /// 30 | HEAD = 16, 31 | /// 32 | /// Patch。 33 | /// 34 | PATCH = 32, 35 | /// 36 | /// Options。 37 | /// 38 | OPTIONS = 64 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/CodeArts.Mvc/IJwtAlgorithmGen.cs: -------------------------------------------------------------------------------- 1 | #if NET40_OR_GREATER 2 | #if NET461_OR_GREATER 3 | using JWT.Algorithms; 4 | #else 5 | using JWT; 6 | #endif 7 | 8 | namespace CodeArts.Mvc 9 | { 10 | /// 11 | /// JWT 算法工厂。 12 | /// 13 | public interface IJwtAlgorithmGen 14 | { 15 | /// 16 | /// 创建 JWT 算法。 17 | /// 18 | /// 19 | IJwtAlgorithm Create(); 20 | } 21 | } 22 | #endif -------------------------------------------------------------------------------- /src/CodeArts.Mvc/JwtAlgorithmGen.cs: -------------------------------------------------------------------------------- 1 | #if NET40_OR_GREATER 2 | using CodeArts.Mvc.Algorithms; 3 | #if NET461 4 | using JWT.Algorithms; 5 | #else 6 | using JWT; 7 | #endif 8 | 9 | namespace CodeArts.Mvc 10 | { 11 | /// 12 | /// JWT 算法工厂。 13 | /// 14 | public static class JwtAlgorithmGen 15 | { 16 | private static readonly IJwtAlgorithmGen _algorithmGen; 17 | static JwtAlgorithmGen() => _algorithmGen = RuntimeServPools.Singleton(); 18 | 19 | /// 20 | /// 创建 JWT 算法。 21 | /// 22 | /// 23 | public static IJwtAlgorithm Create() => _algorithmGen.Create(); 24 | } 25 | } 26 | #endif -------------------------------------------------------------------------------- /src/CodeArts.Mvc/JwtToken.cs: -------------------------------------------------------------------------------- 1 | #if NETCOREAPP2_0_OR_GREATER 2 | namespace CodeArts.Mvc 3 | { 4 | /// 5 | /// JWT令牌。 6 | /// 7 | public class JwtToken 8 | { 9 | /// 10 | /// 类型。 11 | /// 12 | public string Type { get; set; } = "Bearer"; 13 | /// 14 | /// 令牌。 15 | /// 16 | public string Token { get; set; } 17 | } 18 | } 19 | #endif -------------------------------------------------------------------------------- /src/CodeArts.Net/WebCoreClient.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net; 3 | 4 | namespace CodeArts.Net 5 | { 6 | /// 7 | /// Web客户端。 8 | /// 9 | public class WebCoreClient : WebClient 10 | { 11 | /// 12 | /// 静态构造函数。 13 | /// 14 | static WebCoreClient() 15 | { 16 | ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true; 17 | } 18 | 19 | /// 20 | /// 过期时间(单位:毫秒)。 21 | /// 22 | public int Timeout { get; set; } = 5000; 23 | 24 | /// 25 | /// 获取 Web 请求实例。 26 | /// 27 | /// 请求地址。 28 | /// 29 | protected override WebRequest GetWebRequest(Uri address) 30 | { 31 | var request = base.GetWebRequest(address); 32 | 33 | request.Timeout = Timeout; 34 | 35 | return request; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/CodeArts.RedisCaching/RedisCachingStartup.cs: -------------------------------------------------------------------------------- 1 | namespace CodeArts.Caching 2 | { 3 | /// 4 | /// 内存启动项。 5 | /// 6 | public class RedisCachingStartup : IStartup 7 | { 8 | /// 9 | /// 代码(500)。 10 | /// 11 | public int Code => 500; 12 | 13 | /// 14 | /// 权重。 15 | /// 16 | public int Weight => 1; 17 | 18 | /// 19 | /// 启动。 20 | /// 21 | public void Startup() => CachingManager.RegisterProvider(new RedisCachingProvider(), Level.Second); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/CodeArts/CodeArts.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net461;net45;net40;netstandard2.0;netstandard2.1; 5 | $(LibraryFrameworks) 6 | false 7 | true 8 | 8.1.5.1 9 | Tiny Lit 10 | Tiny Lit 11 | A lightweight infrastructure. 12 | https://github.com/tinylit/codearts/blob/master/LICENSE.txt 13 | https://github.com/tinylit/codearts 14 | git 15 | https://github.com/tinylit/codearts/blob/master/LICENSE.txt 16 | https://raw.githubusercontent.com/tinylit/codearts/master/codearts.png 17 | https://github.com/tinylit/codearts 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/CodeArts/Collections/Generic/IAsyncEnumerable.cs: -------------------------------------------------------------------------------- 1 | #if NET45_OR_GREATER || NETSTANDARD2_0 2 | using System.Threading; 3 | 4 | namespace System.Collections.Generic 5 | { 6 | /// 7 | /// 异步迭代能力。 8 | /// 9 | /// 结果类型。 10 | public interface IAsyncEnumerable 11 | { 12 | /// 13 | /// 获取迭代器。 14 | /// 15 | /// 取消。 16 | /// 17 | IAsyncEnumerator GetAsyncEnumerator(CancellationToken cancellationToken); 18 | } 19 | } 20 | #endif -------------------------------------------------------------------------------- /src/CodeArts/Collections/Generic/IAsyncEnumerator.cs: -------------------------------------------------------------------------------- 1 | #if NET45_OR_GREATER || NETSTANDARD2_0 2 | using System.Threading.Tasks; 3 | 4 | namespace System.Collections.Generic 5 | { 6 | /// 7 | /// 异步迭代器。 8 | /// 9 | /// 结果类型。 10 | public interface IAsyncEnumerator : IDisposable 11 | { 12 | /// 13 | /// 当前数据。 14 | /// 15 | T Current { get; } 16 | 17 | /// 18 | /// 下一份数据。 19 | /// 20 | /// 21 | Task MoveNextAsync(); 22 | } 23 | } 24 | #endif -------------------------------------------------------------------------------- /src/CodeArts/Collections/Generic/IReadOnlyCollection.cs: -------------------------------------------------------------------------------- 1 | #if NET40 2 | namespace System.Collections.Generic 3 | { 4 | /// 5 | /// 表示元素的强类型化只读集合。 6 | /// 7 | /// 元素的类型。 8 | public interface IReadOnlyCollection : IEnumerable, IEnumerable 9 | { 10 | /// 11 | /// 获取集合中的元素数。 12 | /// 13 | int Count { get; } 14 | } 15 | } 16 | #endif -------------------------------------------------------------------------------- /src/CodeArts/Collections/Generic/IReadOnlyList.cs: -------------------------------------------------------------------------------- 1 | #if NET40 2 | namespace System.Collections.Generic 3 | { 4 | /// 5 | /// 表示可按照索引进行访问的元素的只读集合。 6 | /// 7 | /// 只读列表中元素的类型 8 | public interface IReadOnlyList : IReadOnlyCollection, IEnumerable, IEnumerable 9 | { 10 | /// 11 | /// 获取位于只读列表中指定索引处的元素。 12 | /// 13 | /// 要获取的元素的索引(索引从零开始)。 14 | /// 在只读列表中指定索引处的元素。 15 | T this[int index] { get; } 16 | } 17 | } 18 | #endif -------------------------------------------------------------------------------- /src/CodeArts/Config/IConfigHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CodeArts.Config 4 | { 5 | /// 6 | /// 配置文件帮助类。 7 | /// 8 | public interface IConfigHelper 9 | { 10 | /// 配置文件变更事件。 11 | event Action OnConfigChanged; 12 | 13 | /// 14 | /// 配置文件读取。 15 | /// 16 | /// 读取数据类型。 17 | /// 健。 18 | /// 默认值。 19 | /// 20 | T Get(string key, T defaultValue = default); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/CodeArts/DevelopAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace CodeArts 8 | { 9 | /// 10 | /// 开发模拟标记。 11 | /// 12 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] 13 | public sealed class DevelopAttribute : Attribute 14 | { 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/CodeArts/Exceptions/BusiException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CodeArts.Exceptions 4 | { 5 | /// 业务执行中,业务逻辑不满足返回异常。 6 | public class BusiException : CodeException 7 | { 8 | /// 9 | /// 构造函数。 10 | /// 11 | /// 异常消息。 12 | /// 状态编码。 13 | public BusiException(string message, int errorCode = StatusCodes.BusiError) : base(message, errorCode) 14 | { 15 | } 16 | 17 | /// 18 | /// 异常。 19 | /// 20 | /// 异常消息。 21 | /// 引发异常的异常。 22 | /// 错误编码。 23 | public BusiException(string message, Exception innerException, int errorCode = StatusCodes.Error) : base(message, innerException, errorCode) 24 | { 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/CodeArts/Exceptions/CodeException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CodeArts.Exceptions 4 | { 5 | /// 6 | /// 异常。 7 | /// 8 | public class CodeException : Exception 9 | { 10 | /// 11 | /// 错误码。 12 | /// 13 | public int ErrorCode { get; } 14 | 15 | /// 16 | /// 异常。 17 | /// 18 | /// 异常消息。 19 | /// 错误编码。 20 | public CodeException(string message, int errorCode = StatusCodes.Error) 21 | : base(message) 22 | { 23 | ErrorCode = errorCode; 24 | } 25 | 26 | /// 27 | /// 异常。 28 | /// 29 | /// 异常消息。 30 | /// 引发异常的异常。 31 | /// 错误编码。 32 | public CodeException(string message, Exception innerException, int errorCode = StatusCodes.Error) : base(message, innerException) 33 | { 34 | ErrorCode = errorCode; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/CodeArts/Exceptions/ServException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CodeArts.Exceptions 4 | { 5 | /// 6 | /// 各服务层异常。 7 | /// 8 | public class ServException : CodeException 9 | { 10 | /// 11 | /// 构造函数。 12 | /// 13 | /// 错误消息。 14 | /// 错误编码。 15 | public ServException(string message, int errorCode = StatusCodes.ServError) : base(message, errorCode) 16 | { 17 | } 18 | 19 | /// 20 | /// 异常。 21 | /// 22 | /// 异常消息。 23 | /// 引发异常的异常。 24 | /// 错误编码。 25 | public ServException(string message, Exception innerException, int errorCode = StatusCodes.Error) : base(message, innerException, errorCode) 26 | { 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/CodeArts/Exceptions/SyntaxException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data; 3 | 4 | namespace CodeArts.Exceptions 5 | { 6 | /// 7 | /// 语法异常。 8 | /// 9 | public class SyntaxException : SyntaxErrorException 10 | { 11 | /// 12 | /// 错误码。 13 | /// 14 | public int ErrorCode { get; } 15 | 16 | /// 17 | /// 异常。 18 | /// 19 | /// 异常消息。 20 | /// 错误编码。 21 | public SyntaxException(string message, int errorCode = StatusCodes.SyntaxError) 22 | : base(message) 23 | { 24 | ErrorCode = errorCode; 25 | } 26 | 27 | /// 28 | /// 异常。 29 | /// 30 | /// 异常消息。 31 | /// 引发异常的异常。 32 | /// 错误编码。 33 | public SyntaxException(string message, Exception innerException, int errorCode = StatusCodes.SyntaxError) : base(message, innerException) 34 | { 35 | ErrorCode = errorCode; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/CodeArts/Extentions/QueryableExtentions.cs: -------------------------------------------------------------------------------- 1 | using CodeArts; 2 | 3 | namespace System.Linq 4 | { 5 | /// 6 | /// 查询器扩展。 7 | /// 8 | public static class QueryableExtentions 9 | { 10 | /// 11 | /// 转分页数据。 12 | /// 13 | /// 源。 14 | /// 源。 15 | /// 页码(索引从“0”开始)。 16 | /// 分页条数。 17 | /// 18 | public static PagedList ToList(this IQueryable source, int page, int size) 19 | => new PagedList(source, page, size); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/CodeArts/IConfigable.cs: -------------------------------------------------------------------------------- 1 | namespace CodeArts 2 | { 3 | /// 4 | /// 配置变更监听能力。 5 | /// 6 | public interface IConfigable where TSelf : class, IConfigable 7 | { 8 | /// 9 | /// 监听到变更后的新数据。 10 | /// 11 | /// 变更后的数据。 12 | void SaveChanges(TSelf changedValue); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/CodeArts/IKeyGen.cs: -------------------------------------------------------------------------------- 1 | namespace CodeArts 2 | { 3 | /// 4 | /// 主键生成器接口。 5 | /// 6 | public interface IKeyGen 7 | { 8 | /// 9 | /// 生成新主键。 10 | /// 11 | /// 12 | long Id(); 13 | 14 | /// 15 | /// 创建主键。 16 | /// 17 | /// 主键值。 18 | /// 19 | Key Create(long key); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/CodeArts/IKeyGenFactory.cs: -------------------------------------------------------------------------------- 1 | namespace CodeArts 2 | { 3 | /// 4 | /// KeyGen 创建器。 5 | /// 6 | public interface IKeyGenFactory 7 | { 8 | /// 9 | /// 创建。 10 | /// 11 | /// 12 | IKeyGen Create(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/CodeArts/IMapper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CodeArts 4 | { 5 | /// 6 | /// 映射器。 7 | /// 8 | public interface IMapper 9 | { 10 | /// 11 | /// 对象克隆。 12 | /// 13 | /// 数据源。 14 | /// 默认值。 15 | /// 目标类型。 16 | /// 17 | T Copy(T obj, T def = default); 18 | 19 | /// 20 | /// 对象映射。 21 | /// 22 | /// 数据源。 23 | /// 默认值。 24 | /// 目标类型。 25 | /// 26 | T Map(object obj, T def = default); 27 | 28 | /// 29 | /// 对象映射。 30 | /// 31 | /// 数据源。 32 | /// 目标类型。 33 | /// 34 | object Map(object obj, Type conversionType); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/CodeArts/IResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace CodeArts 5 | { 6 | /// 7 | /// 数据结果接口。 8 | /// 9 | public interface IResult 10 | { 11 | /// 12 | /// 状态码。 13 | /// 14 | int Code { get; } 15 | 16 | /// 17 | /// 是否成功。 18 | /// 19 | bool Success { get; } 20 | 21 | /// 22 | /// 时间戳。 23 | /// 24 | DateTime Timestamp { get; } 25 | } 26 | 27 | /// 28 | /// 数据结果接口。 29 | /// 30 | public interface IResult : IResult 31 | { 32 | /// 33 | /// 数据。 34 | /// 35 | T Data { get; } 36 | } 37 | 38 | /// 39 | /// 分页数据结果接口。 40 | /// 41 | public interface IResults : IResult> 42 | { 43 | /// 44 | /// 总条数。 45 | /// 46 | int Count { get; } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/CodeArts/IStartup.cs: -------------------------------------------------------------------------------- 1 | namespace CodeArts 2 | { 3 | /// 4 | /// 启动项()。 5 | /// 6 | public interface IStartup 7 | { 8 | /// 9 | /// 代码(相同代码只会使用一个,优先启动代码值更小)。 10 | /// 11 | int Code { get; } 12 | 13 | /// 14 | /// 相同【】时,优先使用权重更高的启动项。 15 | /// 16 | int Weight { get; } 17 | 18 | /// 19 | /// 启动。 20 | /// 21 | void Startup(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/CodeArts/IgnoreAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CodeArts 4 | { 5 | /// 6 | /// 忽略的键。 7 | /// 8 | [AttributeUsage(AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] 9 | public sealed class IgnoreAttribute : Attribute 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/CodeArts/JsonSettings.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.RegularExpressions; 3 | 4 | namespace CodeArts 5 | { 6 | /// 7 | /// JSON 属性设置(非数字格式的内容会加双引号)。 8 | /// 9 | public class JsonSettings : DefaultSettings 10 | { 11 | private static readonly Regex NumberPattern = new Regex("^[-]?(0|[1-9][0-9]*)(\\.[0-9]+)?$", RegexOptions.Singleline | RegexOptions.Compiled); 12 | 13 | /// 14 | /// 构造函数。 15 | /// 16 | /// 命名规则。 17 | public JsonSettings(NamingType namingCase) : base(namingCase) 18 | { 19 | } 20 | 21 | /// 22 | /// ‘null’值处理。 23 | /// 24 | /// 25 | public override string NullValue => "null"; 26 | 27 | /// 28 | /// 打包数据。 29 | /// 30 | /// 数据。 31 | /// 源数据类型。 32 | /// 33 | protected override string ValuePackaging(string value, Type typeToConvert) 34 | { 35 | if (typeToConvert.IsValueType && NumberPattern.IsMatch(value)) 36 | { 37 | return value; 38 | } 39 | 40 | return string.Concat("\"", value, "\""); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/CodeArts/KeyGenFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CodeArts 4 | { 5 | /// 6 | /// KeyGen构建器。 7 | /// 8 | public static class KeyGenFactory 9 | { 10 | private static readonly IKeyGenFactory _keyGen; 11 | 12 | /// 13 | /// 静态构造函数。 14 | /// 15 | static KeyGenFactory() => _keyGen = RuntimeServPools.Singleton(); 16 | 17 | /// 18 | /// 生成主键工具箱(请用静态属性或字段接收)。 19 | /// 20 | /// 21 | public static IKeyGen Create() => _keyGen.Create(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/CodeArts/NamingAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CodeArts 4 | { 5 | /// 6 | /// 命名特性。 7 | /// 8 | [AttributeUsage(AttributeTargets.All, AllowMultiple = false, Inherited = false)] 9 | public sealed class NamingAttribute : Attribute 10 | { 11 | /// 12 | /// 名称。 13 | /// 14 | public string Name { get; set; } 15 | 16 | /// 17 | /// 命名规范。 18 | /// 19 | public NamingType NamingType { get; set; } 20 | 21 | /// 22 | /// 构造函数。 23 | /// 24 | /// 名称。 25 | public NamingAttribute(string name) 26 | { 27 | Name = name; 28 | } 29 | 30 | /// 31 | /// 构造函数。 32 | /// 33 | /// 名称风格。 34 | public NamingAttribute(NamingType namingType) 35 | { 36 | NamingType = namingType; 37 | } 38 | /// 39 | /// 构造函数。 40 | /// 41 | /// 名称。 42 | /// 名称风格。 43 | public NamingAttribute(string name, NamingType namingType) : this(name) 44 | { 45 | NamingType = namingType; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/CodeArts/NamingType.cs: -------------------------------------------------------------------------------- 1 | namespace CodeArts 2 | { 3 | /// 命名规范。 4 | public enum NamingType 5 | { 6 | /// 默认命名(原样/业务自定义)。 7 | Normal = 0, 8 | 9 | /// 驼峰命名,如:userName。 10 | CamelCase = 1, 11 | 12 | /// url命名,如:user_name,注:反序列化时也需要指明。 13 | UrlCase = 2, 14 | 15 | /// 帕斯卡命名,如:UserName。 16 | PascalCase = 3 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/CodeArts/PatternKind.cs: -------------------------------------------------------------------------------- 1 | namespace CodeArts 2 | { 3 | /// 4 | /// 匹配性质。 5 | /// 6 | public enum PatternKind 7 | { 8 | /// 9 | /// 属性。 10 | /// 11 | Property = 1 << 0, 12 | /// 13 | /// 字段。 14 | /// 15 | Field = 1 << 1, 16 | /// 17 | /// 属性与字段。 18 | /// 19 | All = 1 << 2 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/CodeArts/Serialize/Json/IJsonHelper.cs: -------------------------------------------------------------------------------- 1 | namespace CodeArts.Serialize.Json 2 | { 3 | /// 4 | /// JSON序列化。 5 | /// 6 | public interface IJsonHelper 7 | { 8 | /// Json序列化。 9 | /// 数据类型。 10 | /// 对象。 11 | /// 命名规则。 12 | /// 是否缩进。 13 | /// 14 | string ToJson(T jsonObj, NamingType namingType = NamingType.CamelCase, bool indented = false); 15 | 16 | /// Json反序列化。 17 | /// 结果类型。 18 | /// JSON字符串。 19 | /// 命名规则。 20 | /// 21 | T Json(string json, NamingType namingType = NamingType.CamelCase); 22 | 23 | /// 匿名对象反序列化。 24 | /// 结果类型。 25 | /// JSON字符串。 26 | /// 匿名对象。 27 | /// 命名规则。 28 | /// 29 | T Json(string json, T anonymousTypeObject, NamingType namingType = NamingType.CamelCase); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/CodeArts/Singleton.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CodeArts 4 | { 5 | /// 6 | /// 单例封装类。 7 | /// 8 | /// 基类类型。 9 | public class Singleton where T : class 10 | { 11 | /// 12 | /// 静态构造函数。 13 | /// 14 | static Singleton() { } 15 | 16 | /// 17 | /// 单例。 18 | /// 19 | public static T Instance => Nested.Instance; 20 | 21 | private static class Nested 22 | { 23 | static Nested() => Instance = RuntimeServPools.Singleton(); 24 | 25 | public static readonly T Instance; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/CodeArts/SnowflakeFactory.cs: -------------------------------------------------------------------------------- 1 | namespace CodeArts 2 | { 3 | /// 4 | /// 雪花算法创建器。 5 | /// 6 | public class SnowflakeFactory : IKeyGenFactory 7 | { 8 | private readonly int workerId = 0; 9 | private readonly int datacenterId = 0; 10 | 11 | /// 12 | /// 构造函数。 13 | /// 14 | public SnowflakeFactory() { } 15 | 16 | /// 17 | /// 构造函数。 18 | /// 19 | /// 机器ID。 20 | /// 机房ID。 21 | public SnowflakeFactory(int workerId, int datacenterId) 22 | { 23 | this.workerId = workerId; 24 | this.datacenterId = datacenterId; 25 | } 26 | 27 | /// 28 | /// 创建。 29 | /// 30 | /// 31 | public IKeyGen Create() => new SnowflakeKeyGen(workerId, datacenterId); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/CodeArts/Threading/AsyncLocalValueChangedArgs.cs: -------------------------------------------------------------------------------- 1 | #if NET40 || NET45 2 | 3 | namespace System.Threading 4 | { 5 | /// 6 | /// 异步数据改变参数。 7 | /// 8 | /// 数据类型。 9 | public struct AsyncLocalValueChangedArgs 10 | { 11 | /// 12 | /// 改变前的数据。 13 | /// 14 | public T PreviousValue { get; } 15 | 16 | /// 17 | /// 当前数据。 18 | /// 19 | public T CurrentValue { get; } 20 | 21 | /// 22 | /// 线程上下文是否发生改变。 23 | /// 24 | public bool ThreadContextChanged { get; } 25 | 26 | /// 27 | /// 构造函数。 28 | /// 29 | /// 改变前的数据。 30 | /// 当前数据。 31 | /// 上下文是否改变。 32 | internal AsyncLocalValueChangedArgs(T previousValue, T currentValue, bool contextChanged) 33 | { 34 | PreviousValue = previousValue; 35 | CurrentValue = currentValue; 36 | ThreadContextChanged = contextChanged; 37 | } 38 | } 39 | } 40 | #endif --------------------------------------------------------------------------------