├── .config └── dotnet-tools.json ├── .editorconfig ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── dependabot.yml └── workflows │ ├── codeql-analysis.yml │ ├── dependabot-reviewer.yml │ ├── docsfx.yml │ ├── dotnet-publish.yml │ └── dotnet-test.yml ├── .gitignore ├── .husky ├── commit-msg ├── csxScripts │ └── commit-lint.csx ├── pre-commit └── task-runner.json ├── .versionize ├── BigBook.Benchmarks ├── BigBook.Benchmarks.csproj ├── GlobalSuppressions.cs ├── Program.cs └── Tests │ ├── ActivatorCreateInstanceTests.cs │ ├── ConcurrentDictionarySetTests.cs │ ├── ConcurrentDictionaryTests.cs │ ├── DynamoTests.cs │ ├── GetPropertyTests.cs │ ├── GetTypeInfoTests.cs │ ├── IEnumerableTests.cs │ ├── IsTests.cs │ ├── ListMappingTests.cs │ ├── NullEqualityTests.cs │ ├── StringFormatVsStringBuilder.cs │ ├── TestClasses │ ├── ListMapping.cs │ └── NewDynamo.cs │ ├── ToRedux.cs │ ├── TrieVsContains.cs │ └── ValueTypeCreation.cs ├── BigBook.Example ├── BigBook.Example.csproj ├── Example1.cs ├── Example2.cs ├── Example3.cs └── Program.cs ├── BigBook.Tests ├── BTree.cs ├── Bag.cs ├── BaseClasses │ └── TestBaseClass.cs ├── BigBook.Tests.csproj ├── BloomFilterTests.cs ├── Comparison │ ├── GenericComparer.cs │ ├── GenericEqualityComparer.cs │ ├── SimpleComparer.cs │ └── SimpleEqualityComparer.cs ├── Data │ ├── Testing │ │ └── Test.txt │ └── Web │ │ ├── HanselmanSite.html │ │ ├── RandomCSS.css │ │ └── RandomJS.js ├── DateSpan.cs ├── Dynamo.cs ├── ExtensionMethods │ ├── ArrayExtensions.cs │ ├── ConcurrentBagExtensions.cs │ ├── ConcurrentDictionaryExtensions.cs │ ├── DateTimeExtensions.cs │ ├── ExceptionExtensions.cs │ ├── GenericObjectExtensions.cs │ ├── ICollectionExtensions.cs │ ├── IComparableExtensions.cs │ ├── IDictionaryExtensions.cs │ ├── IEnumerableExtensions.cs │ ├── MatchCollectionExtensions.cs │ ├── MathExtensions.cs │ ├── PermutationExtensions.cs │ ├── PredicateExtensions.cs │ ├── ProcessExtensions.cs │ ├── ReflectionExtensions.cs │ ├── StreamExtensions.cs │ ├── StringBuilderExtensions.cs │ ├── StringExtensions.cs │ ├── TaskExtensionTests.cs │ ├── TimeSpanExtensions.cs │ └── ValueType.cs ├── Fraction.cs ├── GlobalSuppressions.cs ├── GraphTests.cs ├── IO │ └── BitReaderTests.cs ├── LazyAsyncTests.cs ├── ListMapping.cs ├── ManyToManyIndexTests.cs ├── Matrix.cs ├── ObservableList.cs ├── PriorityQueue.cs ├── Properties │ └── AssemblyInfo.cs ├── Reflection │ └── TypeCacheForTests.cs ├── RingBuffer.cs ├── Set.cs ├── Table.cs ├── TagDictionary.cs ├── TaskQueueTests.cs ├── TrieTests.cs ├── Vector3.cs └── xunit.runner.json ├── BigBook.sln ├── BigBook ├── AsyncHelper.cs ├── Bag.cs ├── BigBook.csproj ├── BinaryTree.cs ├── BloomFilter.cs ├── CanisterModules │ └── BigBookModule.cs ├── Comparison │ ├── GenericComparer.cs │ ├── GenericEqualityComparer.cs │ ├── SimpleComparer.cs │ └── SimpleEqualityComparer.cs ├── DateSpan.cs ├── Dynamo.cs ├── DynamoUtils │ ├── Change.cs │ ├── DynamoClass.cs │ ├── DynamoData.cs │ ├── DynamoProperties.cs │ ├── DynamoTypes.cs │ └── Interfaces │ │ └── IDynamoProperties.cs ├── EventArgs │ └── EventArgs.cs ├── ExtensionMethods │ ├── ArrayExtensions.cs │ ├── ConcurrentBagExtensions.cs │ ├── ConcurrentDictionaryExtensions.cs │ ├── DateTimeExtensions.cs │ ├── ExceptionExtensions.cs │ ├── GenericObjectExtensions.cs │ ├── ICollectionExtensions.cs │ ├── IComparableExtensions.cs │ ├── IDictionaryExtensions.cs │ ├── IEnumerableExtensions.cs │ ├── MatchCollectionExtensions.cs │ ├── MathExtensions.cs │ ├── PermutationExtensions.cs │ ├── PredicateExtensions.cs │ ├── ProcessExtensions.cs │ ├── ReflectionExtensions.cs │ ├── StackTraceExtensions.cs │ ├── StreamExtensions.cs │ ├── StringBuilderExtensions.cs │ ├── StringExtensions.cs │ ├── TaskExtensions.cs │ ├── TimeSpanExtensions.cs │ ├── Utils │ │ └── DefaultValueLookup.cs │ └── ValueTypeExtensions.cs ├── Formatters │ ├── GenericStringFormatter.cs │ └── Interfaces │ │ └── IStringFormatter.cs ├── Fraction.cs ├── GlobalSuppressions.cs ├── Graph.cs ├── IO │ ├── BitReader.cs │ ├── Converters │ │ ├── BaseClasses │ │ │ └── EndianBitConverterBase.cs │ │ ├── BigEndianBitConverter.cs │ │ ├── LittleEndianBitConverter.cs │ │ └── Structs │ │ │ └── IntFloatUnion.cs │ ├── EndianBinaryReader.cs │ └── EndianBinaryWriter.cs ├── LazyAsync.cs ├── ListMapping.cs ├── ManyToManyIndex.cs ├── Matrix.cs ├── ObservableList.cs ├── Patterns │ ├── BaseClasses │ │ ├── SafeDisposableBaseClass.cs │ │ ├── Singleton.cs │ │ └── StringEnumBaseClass.cs │ ├── Factory.cs │ └── IFluentInterface.cs ├── PriorityQueue.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ └── Resources.resx ├── Queryable │ ├── BaseClasses │ │ └── QueryProviderBase.cs │ └── Query.cs ├── Reflection │ └── TypeCacheFor.cs ├── Registration │ └── CanisterExtensions.cs ├── RingBuffer.cs ├── Set.cs ├── Table.cs ├── TagDictionary.cs ├── TaskQueue.cs ├── Trie.cs └── Vector3.cs ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── Icon.png ├── LICENSE ├── README.md ├── SECURITY.md ├── TestSize ├── Program.cs └── TestSize.csproj ├── docfx_project ├── .gitignore ├── api │ ├── .gitignore │ └── index.md ├── articles │ ├── example2.md │ ├── example3.md │ ├── intro.md │ └── toc.yml ├── docfx.json ├── images │ └── icon.png ├── index.md ├── templates │ └── mytemplate │ │ └── public │ │ └── main.css └── toc.yml └── setup.bat /.config/dotnet-tools.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1, 3 | "isRoot": true, 4 | "tools": { 5 | "husky": { 6 | "version": "0.7.2", 7 | "commands": [ 8 | "husky" 9 | ], 10 | "rollForward": false 11 | }, 12 | "versionize": { 13 | "version": "2.3.1", 14 | "commands": [ 15 | "versionize" 16 | ], 17 | "rollForward": false 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: bug 6 | assignees: JaCraig 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **Example code** 14 | Please provide example code that produces the bug either in a gist or pull request adding a test case and link here. 15 | 16 | **Expected behavior** 17 | A clear and concise description of what you expected to happen. 18 | 19 | **Screenshots** 20 | If applicable, add screenshots to help explain your problem. 21 | 22 | **Version Information** 23 | - OS: [e.g. iOS] 24 | - .Net Version: [e.g. .Net 6] 25 | - Release Version of Library [e.g. 2.0.1] 26 | 27 | **Additional context** 28 | Add any other context about the problem here. 29 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: "nuget" # See documentation for possible values 9 | directory: "/BigBook" # Location of package manifests 10 | schedule: 11 | interval: "daily" 12 | commit-message: 13 | prefix: "fix" 14 | groups: 15 | dependencies: 16 | patterns: 17 | - "*" 18 | 19 | - package-ecosystem: "nuget" # See documentation for possible values 20 | directory: "/BigBook.Tests/" # Location of package manifests 21 | schedule: 22 | interval: "daily" 23 | commit-message: 24 | prefix: "chore" 25 | groups: 26 | dependencies: 27 | patterns: 28 | - "*" 29 | 30 | - package-ecosystem: "nuget" # See documentation for possible values 31 | directory: "/BigBook.Benchmarks/" # Location of package manifests 32 | schedule: 33 | interval: "daily" 34 | commit-message: 35 | prefix: "chore" 36 | groups: 37 | dependencies: 38 | patterns: 39 | - "*" 40 | 41 | - package-ecosystem: "nuget" # See documentation for possible values 42 | directory: "/BigBook.Example/" # Location of package manifests 43 | schedule: 44 | interval: "daily" 45 | commit-message: 46 | prefix: "chore" 47 | groups: 48 | dependencies: 49 | patterns: 50 | - "*" 51 | 52 | - package-ecosystem: "nuget" # See documentation for possible values 53 | directory: "/TestSize/" # Location of package manifests 54 | schedule: 55 | interval: "daily" 56 | commit-message: 57 | prefix: "chore" 58 | groups: 59 | dependencies: 60 | patterns: 61 | - "*" 62 | 63 | - package-ecosystem: "github-actions" 64 | directory: "/" 65 | schedule: 66 | interval: "daily" 67 | commit-message: 68 | prefix: "chore" 69 | groups: 70 | dependencies: 71 | patterns: 72 | - "*" 73 | -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | # For most projects, this workflow file will not need changing; you simply need 2 | # to commit it to your repository. 3 | # 4 | # You may wish to alter this file to override the set of languages analyzed, 5 | # or to provide custom queries or build logic. 6 | # 7 | # ******** NOTE ******** 8 | # We have attempted to detect the languages in your repository. Please check 9 | # the `language` matrix defined below to confirm you have the correct set of 10 | # supported CodeQL languages. 11 | # 12 | name: "CodeQL" 13 | 14 | on: 15 | push: 16 | branches: [ "master" ] 17 | pull_request: 18 | branches: [ "master" ] 19 | schedule: 20 | - cron: '37 18 * * 3' 21 | 22 | permissions: 23 | actions: read 24 | contents: read 25 | security-events: write 26 | 27 | jobs: 28 | analyze: 29 | uses: JaCraig/Centralized-Workflows/.github/workflows/codeql.yml@main -------------------------------------------------------------------------------- /.github/workflows/dependabot-reviewer.yml: -------------------------------------------------------------------------------- 1 | name: Dependabot Reviewer 2 | 3 | on: pull_request_target 4 | 5 | permissions: 6 | pull-requests: write 7 | contents: write 8 | 9 | jobs: 10 | review-dependabot-pr: 11 | if: ${{ github.event.pull_request.user.login == 'dependabot[bot]' }} 12 | uses: JaCraig/Centralized-Workflows/.github/workflows/dependabot-reviewer.yml@main 13 | secrets: 14 | token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} -------------------------------------------------------------------------------- /.github/workflows/docsfx.yml: -------------------------------------------------------------------------------- 1 | name: Document Site Publish 2 | 3 | on: 4 | push: 5 | branches: [ "master" ] 6 | 7 | permissions: 8 | contents: write 9 | 10 | jobs: 11 | publish-docs: 12 | uses: JaCraig/Centralized-Workflows/.github/workflows/docsfx.yml@main -------------------------------------------------------------------------------- /.github/workflows/dotnet-publish.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a .NET project 2 | # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net 3 | 4 | name: .NET Publish 5 | 6 | on: 7 | push: 8 | branches: [ "master" ] 9 | 10 | jobs: 11 | build: 12 | uses: 'JaCraig/Centralized-Workflows/.github/workflows/dotnet-publish.yml@main' 13 | with: 14 | user: 'JaCraig' 15 | user-email: 'JaCraig@users.noreply.github.com' 16 | coveralls-upload: "./BigBook.Tests/TestResults-9.0.x/coverage.net8.0.info" 17 | test-filter: "BigBook.Tests" 18 | secrets: 19 | PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} 20 | NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} -------------------------------------------------------------------------------- /.github/workflows/dotnet-test.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a .NET project 2 | # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net 3 | 4 | name: .NET Test Pull Requests 5 | 6 | on: 7 | pull_request: 8 | branches: [ "master" ] 9 | 10 | jobs: 11 | build: 12 | uses: 'JaCraig/Centralized-Workflows/.github/workflows/dotnet-test.yml@main' -------------------------------------------------------------------------------- /.husky/commit-msg: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | 4 | ## husky task runner examples ------------------- 5 | ## Note : for local installation use 'dotnet' prefix. e.g. 'dotnet husky' 6 | 7 | ## run all tasks 8 | #husky run 9 | 10 | ### run all tasks with group: 'group-name' 11 | #husky run --group group-name 12 | 13 | ## run task with name: 'task-name' 14 | #husky run --name task-name 15 | 16 | ## pass hook arguments to task 17 | #husky run --args "$1" "$2" 18 | 19 | ## or put your custom commands ------------------- 20 | #echo 'Husky.Net is awesome!' 21 | 22 | dotnet husky run --name "commit-message-linter" --args "$1" 23 | -------------------------------------------------------------------------------- /.husky/csxScripts/commit-lint.csx: -------------------------------------------------------------------------------- 1 | using System.Text.RegularExpressions; 2 | 3 | private var pattern = @"^(?=.{1,90}$)(?:build|feat|ci|chore|docs|fix|perf|refactor|revert|style|test)(?:\(.+\))*(?::).{4,}(?:#\d+)*(? 2 | 3 | 4 | Exe 5 | net8.0;net9.0 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /BigBook.Benchmarks/GlobalSuppressions.cs: -------------------------------------------------------------------------------- 1 | // This file is used by Code Analysis to maintain SuppressMessage 2 | // attributes that are applied to this project. 3 | // Project-level suppressions either have no target or are given 4 | // a specific target and scoped to a namespace, type, member, etc. 5 | 6 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Redundancy", "RCS1132:Remove redundant overriding member.", Justification = "", Scope = "member", Target = "~M:BigBook.Benchmarks.Tests.NullEqualityTests.TestClass.ToString~System.String")] 7 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0041:Use 'is null' check", Justification = "", Scope = "member", Target = "~M:BigBook.Benchmarks.Tests.NullEqualityTests.ReferenceEquals~System.Boolean")] -------------------------------------------------------------------------------- /BigBook.Benchmarks/Program.cs: -------------------------------------------------------------------------------- 1 | using BenchmarkDotNet.Running; 2 | 3 | namespace BigBook.Benchmarks 4 | { 5 | internal static class Program 6 | { 7 | private static void Main(string[] args) => new BenchmarkSwitcher(typeof(Program).Assembly).Run(args); 8 | } 9 | } -------------------------------------------------------------------------------- /BigBook.Benchmarks/Tests/ActivatorCreateInstanceTests.cs: -------------------------------------------------------------------------------- 1 | using BenchmarkDotNet.Attributes; 2 | using System; 3 | using System.Reflection.Emit; 4 | 5 | namespace BigBook.Benchmarks.Tests 6 | { 7 | [RankColumn, MemoryDiagnoser] 8 | public class ActivatorCreateInstanceTests 9 | { 10 | private Func? CachedMethod; 11 | 12 | [Benchmark(Baseline = true)] 13 | public void ActivatorCreateInstance() 14 | { 15 | _ = Activator.CreateInstance(typeof(TestClass)); 16 | } 17 | 18 | [Benchmark] 19 | public void CachedDynamicMethod() 20 | { 21 | _ = CachedMethod?.Invoke(); 22 | } 23 | 24 | [Benchmark] 25 | public void DynamicMethod() 26 | { 27 | var type = typeof(TestClass); 28 | var target = type.GetConstructor(Type.EmptyTypes); 29 | var dynamic = new DynamicMethod(string.Empty, 30 | type, 31 | Array.Empty(), 32 | target?.DeclaringType!); 33 | var il = dynamic.GetILGenerator(); 34 | il.DeclareLocal(target?.DeclaringType!); 35 | il.Emit(OpCodes.Newobj, target!); 36 | //il.Emit(OpCodes.Stloc_0); 37 | //il.Emit(OpCodes.Ldloc_0); 38 | il.Emit(OpCodes.Ret); 39 | 40 | var method = (Func)dynamic.CreateDelegate(typeof(Func)); 41 | _ = method(); 42 | } 43 | 44 | [GlobalSetup] 45 | public void Setup() 46 | { 47 | var type = typeof(TestClass); 48 | var target = type.GetConstructor(Type.EmptyTypes); 49 | var dynamic = new DynamicMethod(string.Empty, 50 | type, 51 | Array.Empty(), 52 | target?.DeclaringType!); 53 | var il = dynamic.GetILGenerator(); 54 | il.DeclareLocal(target?.DeclaringType!); 55 | il.Emit(OpCodes.Newobj, target!); 56 | //il.Emit(OpCodes.Stloc_0); 57 | //il.Emit(OpCodes.Ldloc_0); 58 | il.Emit(OpCodes.Ret); 59 | 60 | CachedMethod = (Func)dynamic.CreateDelegate(typeof(Func)); 61 | } 62 | 63 | private class TestClass 64 | { 65 | public string? A { get; set; } 66 | 67 | public int B { get; set; } 68 | 69 | public float C { get; set; } 70 | } 71 | } 72 | } -------------------------------------------------------------------------------- /BigBook.Benchmarks/Tests/ConcurrentDictionarySetTests.cs: -------------------------------------------------------------------------------- 1 | using BenchmarkDotNet.Attributes; 2 | using BigBook.Registration; 3 | using Microsoft.Extensions.DependencyInjection; 4 | using System.Collections.Concurrent; 5 | 6 | namespace BigBook.Benchmarks.Tests 7 | { 8 | public class ConcurrentDictionarySetTests 9 | { 10 | public ConcurrentDictionary Data { get; set; } 11 | 12 | [Benchmark(Baseline = true)] 13 | public void AddOrUpdate() => Data.AddOrUpdate("A", "A", (_, __) => "A"); 14 | 15 | [Benchmark] 16 | public void DoesContainKeyAssign() 17 | { 18 | if (Data.ContainsKey("A")) 19 | { 20 | Data["A"] = "A"; 21 | } 22 | else 23 | { 24 | Data.AddOrUpdate("A", "A", (_, __) => "A"); 25 | } 26 | } 27 | 28 | [Benchmark] 29 | public void DoesNotContainKey() 30 | { 31 | if (Data.ContainsKey("B")) 32 | { 33 | Data["B"] = "A"; 34 | } 35 | else 36 | { 37 | Data.AddOrUpdate("B", "A", (__, _) => "A"); 38 | } 39 | } 40 | 41 | [GlobalSetup] 42 | public void Setup() 43 | { 44 | Data = new ConcurrentDictionary(); 45 | Data.AddOrUpdate("A", 1, (_, __) => 1); 46 | new ServiceCollection().AddCanisterModules(configure => configure.RegisterBigBookOfDataTypes()); 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /BigBook.Benchmarks/Tests/ConcurrentDictionaryTests.cs: -------------------------------------------------------------------------------- 1 | using BenchmarkDotNet.Attributes; 2 | using BigBook.Registration; 3 | using Microsoft.Extensions.DependencyInjection; 4 | using System.Collections.Concurrent; 5 | 6 | namespace BigBook.Benchmarks.Tests 7 | { 8 | public class ConcurrentDictionaryTests 9 | { 10 | public ConcurrentDictionary Data { get; set; } 11 | 12 | [Benchmark(Baseline = true)] 13 | public void ContainsKey() 14 | { 15 | if (Data.ContainsKey("A")) 16 | { 17 | if (Data.TryGetValue("A", out var Value)) 18 | { 19 | } 20 | } 21 | } 22 | 23 | [Benchmark] 24 | public void ContainsKeyIndex() 25 | { 26 | if (Data.ContainsKey("A")) 27 | { 28 | var Value = Data["A"]; 29 | } 30 | } 31 | 32 | [Benchmark] 33 | public void DoesNotContainsKey() 34 | { 35 | if (Data.ContainsKey("B")) 36 | { 37 | if (Data.TryGetValue("B", out var Value)) 38 | { 39 | } 40 | } 41 | } 42 | 43 | [GlobalSetup] 44 | public void Setup() 45 | { 46 | Data = new ConcurrentDictionary(); 47 | Data.AddOrUpdate("A", 1, (_, __) => 1); 48 | new ServiceCollection().AddCanisterModules(configure => configure.RegisterBigBookOfDataTypes()); 49 | } 50 | 51 | [Benchmark] 52 | public void TryGetValue() 53 | { 54 | if (Data.TryGetValue("A", out var Value)) 55 | { 56 | } 57 | } 58 | } 59 | } -------------------------------------------------------------------------------- /BigBook.Benchmarks/Tests/GetPropertyTests.cs: -------------------------------------------------------------------------------- 1 | using BenchmarkDotNet.Attributes; 2 | using BigBook.Reflection; 3 | using BigBook.Registration; 4 | using Microsoft.Extensions.DependencyInjection; 5 | using System; 6 | 7 | namespace BigBook.Benchmarks.Tests 8 | { 9 | public class GetPropertyTests 10 | { 11 | [Benchmark(Baseline = true)] 12 | public void GetPropertyTest() 13 | { 14 | var Result = typeof(TestClass).GetProperty("A"); 15 | } 16 | 17 | [Benchmark] 18 | public void OldPropertyExtensionFromTypeTest() 19 | { 20 | var Result = typeof(TestClass).GetProperty("A"); 21 | } 22 | 23 | [Benchmark] 24 | public void PropertyExtensionFromTypeTest() 25 | { 26 | var Result = typeof(TestClass).GetProperty("A", true); 27 | } 28 | 29 | [Benchmark] 30 | public void PropertyLookUpFromTypeTest() 31 | { 32 | var Result = Array.Find(typeof(TestClass).GetProperties(), y => y.Name == "A"); 33 | } 34 | 35 | [Benchmark] 36 | public void PropertyLookUpTest() 37 | { 38 | var Result = Array.Find(TypeCacheFor.Properties, y => y.Name == "A"); 39 | } 40 | 41 | [GlobalSetup] 42 | public void Setup() => new ServiceCollection().AddCanisterModules(configure => configure.RegisterBigBookOfDataTypes()); 43 | 44 | private class TestClass 45 | { 46 | public string A { get; set; } 47 | public int B { get; set; } 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /BigBook.Benchmarks/Tests/GetTypeInfoTests.cs: -------------------------------------------------------------------------------- 1 | using BenchmarkDotNet.Attributes; 2 | using BigBook.Reflection; 3 | 4 | namespace BigBook.Benchmarks.Tests 5 | { 6 | public class GetTypeInfoTests 7 | { 8 | [Benchmark] 9 | public void CachedTypeOf() 10 | { 11 | var TypeInfo = TypeCacheFor.Type; 12 | } 13 | 14 | [Benchmark(Baseline = true)] 15 | public void TypeOf() 16 | { 17 | var TypeInfo = typeof(GetTypeInfoTests); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /BigBook.Benchmarks/Tests/IEnumerableTests.cs: -------------------------------------------------------------------------------- 1 | using BenchmarkDotNet.Attributes; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | 6 | namespace BigBook.Benchmarks.Tests 7 | { 8 | public static class NewExtensions 9 | { 10 | public static IEnumerable ForNew(this IEnumerable list, int start, int end, Func function) 11 | { 12 | if (list is null || function is null || !list.Any()) 13 | { 14 | return Array.Empty(); 15 | } 16 | 17 | int Count = 0; 18 | var ReturnList = new TResult[end + 1 - start]; 19 | 20 | foreach (var Item in list.ElementsBetween(start, end + 1)) 21 | { 22 | ReturnList[Count] = function(Item, Count); 23 | ++Count; 24 | } 25 | return ReturnList; 26 | } 27 | } 28 | 29 | [MemoryDiagnoser] 30 | public class IEnumerableTests 31 | { 32 | [Params(10, 100, 1000, 10000)] 33 | public int Count; 34 | 35 | private static List List1 { get; set; } 36 | 37 | private static List List2 { get; set; } 38 | 39 | private static List List3 { get; set; } 40 | 41 | [Benchmark] 42 | public void New() 43 | { 44 | _ = ((IEnumerable)List1).ForNew(List1.Count / 4, List1.Count / 2, (x, y) => x); 45 | } 46 | 47 | [Benchmark(Baseline = true)] 48 | public void Old() 49 | { 50 | _ = ((IEnumerable)List1).For(List1.Count / 4, List1.Count / 2, (x, y) => x); 51 | } 52 | 53 | [GlobalSetup] 54 | public void Setup() 55 | { 56 | List1 = new List(); 57 | List2 = new List(); 58 | List3 = new List(); 59 | for (int x = 0; x < Count; ++x) 60 | { 61 | List1.Add(x); 62 | List2.Add(x); 63 | List3.Add(x); 64 | } 65 | } 66 | } 67 | } -------------------------------------------------------------------------------- /BigBook.Benchmarks/Tests/IsTests.cs: -------------------------------------------------------------------------------- 1 | using BenchmarkDotNet.Attributes; 2 | using BigBook.Registration; 3 | using Microsoft.Extensions.DependencyInjection; 4 | 5 | namespace BigBook.Benchmarks.Tests 6 | { 7 | [MemoryDiagnoser] 8 | public class IsTests 9 | { 10 | private TestClass[] Data { get; set; } 11 | 12 | [Benchmark] 13 | public void IsAssignableTest() 14 | { 15 | _ = Data.GetType().IsAssignableFrom(typeof(ITestClass[])); 16 | } 17 | 18 | [Benchmark] 19 | public void IsMethodTest() 20 | { 21 | _ = Data.Is(); 22 | } 23 | 24 | [Benchmark(Baseline = true)] 25 | public void IsTest() 26 | { 27 | _ = Data is ITestClass[]; 28 | } 29 | 30 | [Benchmark] 31 | public void IsTypeTest() 32 | { 33 | _ = Data.GetType().Is(); 34 | } 35 | 36 | [GlobalSetup] 37 | public void Setup() 38 | { 39 | Data = new TestClass[100]; 40 | new ServiceCollection().AddCanisterModules(configure => configure.RegisterBigBookOfDataTypes()); 41 | } 42 | 43 | private interface ITestClass 44 | { 45 | } 46 | 47 | private class TestClass : ITestClass 48 | { 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /BigBook.Benchmarks/Tests/ListMappingTests.cs: -------------------------------------------------------------------------------- 1 | using BenchmarkDotNet.Attributes; 2 | using BigBook.Registration; 3 | using Microsoft.Extensions.DependencyInjection; 4 | using System.Linq; 5 | 6 | namespace BigBook.Benchmarks.Tests 7 | { 8 | [MemoryDiagnoser] 9 | public class ListMappingTests 10 | { 11 | private BigBook.Benchmarks.Tests.TestClasses.ListMapping NewOne { get; } = new TestClasses.ListMapping(); 12 | 13 | private BigBook.ListMapping Original { get; } = new BigBook.ListMapping(); 14 | 15 | [Params(1, 10, 100, 1000)] 16 | public int Count; 17 | 18 | //[Benchmark] 19 | //public void NewerListAdd() 20 | //{ 21 | // Parallel.For(0, 10, x => 22 | // { 23 | // NewOne.Add("A", new { A = 1 }); 24 | // NewOne.Add("B", new { A = 1 }); 25 | // NewOne.Add("C", new { A = 1 }); 26 | // }); 27 | //} 28 | 29 | //[Benchmark] 30 | //public void NewerListAddAndRead() 31 | //{ 32 | // Count.Times(x => NewOne.Add("A", new { A = 1 })); 33 | // NewOne.TryGetValue("A", out var Values); 34 | // NewOne.Clear(); 35 | //} 36 | 37 | [Benchmark] 38 | public void NewerListAddAndRemove() 39 | { 40 | Count.Times(x => NewOne.Add("A", new { A = 1 })); 41 | NewOne.TryGetValue("A", out var Values); 42 | NewOne.Remove("A", Values.Take(10).ToList()); 43 | NewOne.Clear(); 44 | } 45 | 46 | //[Benchmark] 47 | //public void OriginalListAddAndRead() 48 | //{ 49 | // Count.Times(x => Original.Add("A", new { A = 1 })); 50 | // Original.TryGetValue("A", out var Values); 51 | // Original.Clear(); 52 | //} 53 | 54 | [Benchmark(Baseline = true)] 55 | public void OriginalListAddAndRemove() 56 | { 57 | Count.Times(x => Original.Add("A", new { A = 1 })); 58 | Original.TryGetValue("A", out var Values); 59 | foreach (var Item in Values.Take(10).ToList()) 60 | { 61 | Original.Remove("A", Item); 62 | } 63 | Original.Clear(); 64 | } 65 | 66 | [GlobalSetup] 67 | public void Setup() 68 | { 69 | new ServiceCollection().AddCanisterModules(configure => configure.RegisterBigBookOfDataTypes()); 70 | } 71 | } 72 | } -------------------------------------------------------------------------------- /BigBook.Benchmarks/Tests/NullEqualityTests.cs: -------------------------------------------------------------------------------- 1 | using BenchmarkDotNet.Attributes; 2 | 3 | namespace BigBook.Benchmarks.Tests 4 | { 5 | public class NullEqualityTests 6 | { 7 | private TestClass? Data { get; } 8 | 9 | [Benchmark] 10 | public bool Equals() => Data == null; 11 | 12 | [Benchmark] 13 | public bool EqualsFunc() => Equals(Data, null); 14 | 15 | [Benchmark] 16 | public bool EqualsObject() => ((object)Data) == null; 17 | 18 | [Benchmark(Baseline = true)] 19 | public bool Is() => Data is null; 20 | 21 | [Benchmark] 22 | public bool ReferenceEquals() => ReferenceEquals(Data, null); 23 | 24 | private class TestClass 25 | { 26 | public int ID { get; set; } 27 | 28 | public static bool operator !=(TestClass? left, TestClass? right) 29 | { 30 | return !(left == right); 31 | } 32 | 33 | public static bool operator ==(TestClass? left, TestClass? right) 34 | { 35 | if (left is null && right is null) 36 | return true; 37 | if (left is null || right is null) 38 | return false; 39 | return left.ID.GetHashCode() == right.ID.GetHashCode(); 40 | } 41 | 42 | public override bool Equals(object? obj) 43 | { 44 | var TempObj = obj as TestClass; 45 | return this == TempObj; 46 | } 47 | 48 | public override int GetHashCode() 49 | { 50 | return ID.GetHashCode(); 51 | } 52 | 53 | public override string? ToString() => base.ToString(); 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /BigBook.Benchmarks/Tests/StringFormatVsStringBuilder.cs: -------------------------------------------------------------------------------- 1 | using BenchmarkDotNet.Attributes; 2 | using Microsoft.Extensions.ObjectPool; 3 | using System.Text; 4 | 5 | namespace BigBook.Benchmarks.Tests 6 | { 7 | [MemoryDiagnoser] 8 | public class StringFormatVsStringBuilder 9 | { 10 | private ObjectPool Pool { get; set; } 11 | 12 | [GlobalSetup] 13 | public void Setup() 14 | { 15 | Pool = new DefaultObjectPoolProvider().CreateStringBuilderPool(); 16 | } 17 | 18 | [Benchmark] 19 | public void StringBuilder() 20 | { 21 | _ = new StringBuilder().Append("ALTER TABLE [").Append("A").Append("].[").Append("B").Append("] ADD CONSTRAINT [").Append("C").Append("] CHECK (").Append("D").Append(")").ToString(); 22 | } 23 | 24 | [Benchmark] 25 | public void StringBuilderPool() 26 | { 27 | var Builder = Pool.Get(); 28 | _ = Builder.Append("ALTER TABLE [").Append("A").Append("].[").Append("B").Append("] ADD CONSTRAINT [").Append("C").Append("] CHECK (").Append("D").Append(")").ToString(); 29 | Pool.Return(Builder); 30 | } 31 | 32 | [Benchmark(Baseline = true)] 33 | public void StringFormat() 34 | { 35 | _ = string.Format("ALTER TABLE [{0}].[{1}] ADD CONSTRAINT [{2}] CHECK ({3})", "A", "B", "C", "D"); 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /BigBook.Benchmarks/Tests/ValueTypeCreation.cs: -------------------------------------------------------------------------------- 1 | using BenchmarkDotNet.Attributes; 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace BigBook.Benchmarks.Tests 6 | { 7 | [MemoryDiagnoser] 8 | public class ValueTypeCreation 9 | { 10 | private static readonly Dictionary HashLookUp = new Dictionary 11 | { 12 | [typeof(int).GetHashCode()] = 0 13 | }; 14 | 15 | private static readonly Dictionary TypeLookUp = new Dictionary 16 | { 17 | [typeof(int)] = 0 18 | }; 19 | 20 | [Benchmark(Baseline = true)] 21 | public void ActivatorUsage() 22 | { 23 | _ = Activator.CreateInstance(typeof(int)); 24 | } 25 | 26 | [Benchmark] 27 | public void DictionaryHashLookUp() 28 | { 29 | _ = HashLookUp[typeof(int).GetHashCode()]; 30 | } 31 | 32 | [Benchmark] 33 | public void DictionaryTypeLookUp() 34 | { 35 | _ = TypeLookUp[typeof(int)]; 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /BigBook.Example/BigBook.Example.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0;net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /BigBook.Example/Example1.cs: -------------------------------------------------------------------------------- 1 | using BigBook.ExtensionMethods; 2 | 3 | namespace BigBook.Example 4 | { 5 | /// 6 | /// Example 1. This example shows how to use some of the string extensions. 7 | /// 8 | public static class Example1 9 | { 10 | /// 11 | /// String extension example. 12 | /// 13 | public static void StringExtensions() 14 | { 15 | // This is an example of one of the many extensions that are available. This one is used to keep only the characters you want. 16 | // In this case, it will only keep the letters. 17 | var ExampleString = "This is an example string #1".Keep(StringFilter.Alpha); 18 | 19 | Console.WriteLine(ExampleString); 20 | 21 | // In this case, it will only keep the letters and numbers. 22 | ExampleString = "This is an example string #2".Keep(StringFilter.Alpha | StringFilter.Numeric); 23 | 24 | Console.WriteLine(ExampleString); 25 | 26 | // You can also use regular expressions. This one will keep everything. 27 | ExampleString = "This is an example string #3".Keep(@"[\s\d\S]"); 28 | 29 | Console.WriteLine(ExampleString); 30 | 31 | // There are a ton of extra extension methods available. This one will add spaces to the string by splitting on upper case letters. 32 | // This is useful for converting PascalCase to a sentence. 33 | ExampleString = nameof(Example1.StringExtensions).AddSpaces(); 34 | 35 | Console.WriteLine(ExampleString); 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /BigBook.Example/Example2.cs: -------------------------------------------------------------------------------- 1 | namespace BigBook.Example 2 | { 3 | /// 4 | /// Example 2. This example shows how to use the ListMapping class. 5 | /// 6 | public static class Example2 7 | { 8 | /// 9 | /// ListMapping example. 10 | /// 11 | public static void ListMappings() 12 | { 13 | // Now for one of the many data types that are available. This one lets you have lists of items that are grouped by a key. 14 | var BucketFilterExample = new ListMapping(); 15 | BucketFilterExample.Add("Test", new ExampleClass { Name = "Test", Value = 5 }); 16 | BucketFilterExample.Add("Test", new ExampleClass { Name = "Test", Value = 10 }); 17 | BucketFilterExample.Add("Test2", new ExampleClass { Name = "Test2", Value = 15 }); 18 | BucketFilterExample.Add("Test2", new ExampleClass { Name = "Test2", Value = 20 }); 19 | BucketFilterExample.Add("Test3", new ExampleClass { Name = "Test3", Value = 25 }); 20 | BucketFilterExample.Add("Test3", new ExampleClass { Name = "Test3", Value = 30 }); 21 | 22 | // Now we can get the values back out and they will be grouped by the key. 23 | // This also uses the extension method that is available to convert the list to a joined string. 24 | Console.WriteLine("Test1: {0}", BucketFilterExample["Test"].ToString(x => x.Value.ToString(), ", ")); 25 | Console.WriteLine("Test2: {0}", BucketFilterExample["Test2"].ToString(x => x.Value.ToString(), ", ")); 26 | Console.WriteLine("Test3: {0}", BucketFilterExample["Test3"].ToString(x => x.Value.ToString(), ", ")); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /BigBook.Example/Example3.cs: -------------------------------------------------------------------------------- 1 | namespace BigBook.Example 2 | { 3 | /// 4 | /// Example 3. This example shows how to use the LazyAsync class. 5 | /// 6 | public static class Example3 7 | { 8 | /// 9 | /// Asynchronous lazy loading. 10 | /// 11 | public static async Task AsyncLazyLoading() 12 | { 13 | // This is an example of the lazy async class. It will only run the function when the value is requested. 14 | var TestObject = new LazyAsync(async () => 15 | { 16 | await Task.Delay(500).ConfigureAwait(false); 17 | return 5; 18 | }); 19 | // This will take 500ms to run and will return 5. 20 | Console.WriteLine(await TestObject); 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /BigBook.Example/Program.cs: -------------------------------------------------------------------------------- 1 | namespace BigBook.Example 2 | { 3 | internal class ExampleClass 4 | { 5 | public string Name { get; set; } 6 | 7 | public int Value { get; set; } 8 | } 9 | 10 | internal class Program 11 | { 12 | private static async Task Main(string[] args) 13 | { 14 | Example1.StringExtensions(); 15 | Example2.ListMappings(); 16 | await Example3.AsyncLazyLoading(); 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /BigBook.Tests/BTree.cs: -------------------------------------------------------------------------------- 1 | using BigBook.Tests.BaseClasses; 2 | using Xunit; 3 | 4 | namespace BigBook.Tests 5 | { 6 | public class BTreeTests : TestBaseClass> 7 | { 8 | public BTreeTests() 9 | { 10 | TestObject = new BinaryTree(); 11 | } 12 | 13 | [Fact] 14 | public void Creation() 15 | { 16 | var Tree = new BinaryTree 17 | { 18 | 1, 19 | 2, 20 | 0, 21 | -1 22 | }; 23 | Assert.Equal(-1, Tree.MinValue); 24 | Assert.Equal(2, Tree.MaxValue); 25 | } 26 | 27 | [Fact] 28 | public void Random() 29 | { 30 | var Tree = new BinaryTree(); 31 | var Values = new System.Collections.Generic.List(); 32 | var Rand = new System.Random(); 33 | for (var x = 0; x < 10; ++x) 34 | { 35 | var Value = Rand.Next(); 36 | Values.Add(Value); 37 | Tree.Add(Value); 38 | } 39 | for (var x = 0; x < 10; ++x) 40 | { 41 | Assert.Contains(Values[x], Tree); 42 | } 43 | Values.Sort(); 44 | Assert.Equal(Values.ToString(x => x.ToString(), " "), Tree.ToString()); 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /BigBook.Tests/Bag.cs: -------------------------------------------------------------------------------- 1 | using BigBook.Tests.BaseClasses; 2 | using Xunit; 3 | 4 | namespace BigBook.Tests 5 | { 6 | public class BagTests : TestBaseClass> 7 | { 8 | public BagTests() 9 | { 10 | TestObject = new Bag(); 11 | } 12 | 13 | [Fact] 14 | public void RandomTest() 15 | { 16 | var BagObject = new Bag(); 17 | var Rand = new System.Random(); 18 | for (var x = 0; x < 10; ++x) 19 | { 20 | var Value = x.ToString(); 21 | var Count = Rand.Next(1, 10); 22 | for (var y = 0; y < Count; ++y) 23 | { 24 | BagObject.Add(Value); 25 | } 26 | 27 | Assert.Equal(Count, BagObject[Value]); 28 | } 29 | Assert.Equal(10, BagObject.Count); 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /BigBook.Tests/BigBook.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Tests for BigBook 5 | BigBook.Tests 6 | James Craig 7 | net8.0;net9.0 8 | portable 9 | BigBook.Tests 10 | BigBook.Tests 11 | true 12 | IoC 13 | https://github.com/JaCraig/BigBookOfDataTypes 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | win-x64;osx-x64;linux-x64 16 | false 17 | false 18 | false 19 | enable 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | PreserveNewest 32 | 33 | 34 | PreserveNewest 35 | 36 | 37 | PreserveNewest 38 | 39 | 40 | PreserveNewest 41 | 42 | 43 | 44 | 45 | 46 | all 47 | runtime; build; native; contentfiles; analyzers; buildtransitive 48 | 49 | 50 | 51 | 52 | 53 | runtime; build; native; contentfiles; analyzers; buildtransitive 54 | all 55 | 56 | 57 | runtime; build; native; contentfiles; analyzers; buildtransitive 58 | all 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /BigBook.Tests/BloomFilterTests.cs: -------------------------------------------------------------------------------- 1 | using BigBook.Tests.BaseClasses; 2 | using Mecha.xUnit; 3 | using System; 4 | using System.ComponentModel.DataAnnotations; 5 | using Xunit; 6 | 7 | namespace BigBook.Tests 8 | { 9 | public class BloomFilterTests : TestBaseClass> 10 | { 11 | public BloomFilterTests() 12 | { 13 | TestObject = new BloomFilter(1000); 14 | } 15 | 16 | [Property(GenerationCount = 100)] 17 | public void Add(int size, [Required] string value) 18 | { 19 | if (size == int.MinValue) 20 | size = int.MaxValue; 21 | size = Math.Abs(size); 22 | if (size < 10) 23 | size = 10; 24 | else if (size > 1000000) 25 | size = 1000000; 26 | var TestObject = new BloomFilter(size); 27 | TestObject.Add(value); 28 | } 29 | 30 | [Property(GenerationCount = 100)] 31 | public void Contains(int size, [Required] string value) 32 | { 33 | if (size == int.MinValue) 34 | size = int.MaxValue; 35 | size = Math.Abs(size); 36 | if (size < 10) 37 | size = 10; 38 | else if (size > 1000000) 39 | size = 1000000; 40 | var TestObject = new BloomFilter(size); 41 | TestObject.Add(value); 42 | Assert.True(TestObject.Contains(value)); 43 | } 44 | 45 | [Property(GenerationCount = 100)] 46 | public void Creation(int size) 47 | { 48 | if (size == int.MinValue) 49 | size = int.MaxValue; 50 | size = Math.Abs(size); 51 | if (size < 10) 52 | size = 10; 53 | else if (size > 1000000) 54 | size = 1000000; 55 | var TestObject = new BloomFilter(size); 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /BigBook.Tests/Comparison/GenericComparer.cs: -------------------------------------------------------------------------------- 1 | using BigBook.Comparison; 2 | using BigBook.Tests.BaseClasses; 3 | using Xunit; 4 | 5 | namespace BigBook.Tests.Comparison 6 | { 7 | public class GenericComparerTests : TestBaseClass> 8 | { 9 | public GenericComparerTests() 10 | { 11 | TestObject = new GenericComparer(); 12 | } 13 | 14 | [Fact] 15 | public void Compare() 16 | { 17 | var Comparer = new GenericComparer(); 18 | Assert.Equal(0, Comparer.Compare("A", "A")); 19 | Assert.Equal(-1, Comparer.Compare("A", "B")); 20 | Assert.Equal(1, Comparer.Compare("B", "A")); 21 | } 22 | 23 | [Fact] 24 | public void CompareNullNonValueType() 25 | { 26 | var Comparer = new GenericComparer(); 27 | Assert.Equal(0, Comparer.Compare(null, null)); 28 | Assert.Equal(-1, Comparer.Compare(null, "B")); 29 | Assert.Equal(-1, Comparer.Compare("B", null)); 30 | } 31 | 32 | [Fact] 33 | public void CompareValueType() 34 | { 35 | var Comparer = new GenericComparer(); 36 | Assert.Equal(0, Comparer.Compare(0, 0)); 37 | Assert.Equal(-1, Comparer.Compare(0, 1)); 38 | Assert.Equal(1, Comparer.Compare(1, 0)); 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /BigBook.Tests/Comparison/GenericEqualityComparer.cs: -------------------------------------------------------------------------------- 1 | using BigBook.Comparison; 2 | using BigBook.Tests.BaseClasses; 3 | using Xunit; 4 | 5 | namespace BigBook.Tests.Comparison 6 | { 7 | public class GenericEqualityComparerTests : TestBaseClass> 8 | { 9 | public GenericEqualityComparerTests() 10 | { 11 | TestObject = new GenericEqualityComparer(); 12 | } 13 | 14 | [Fact] 15 | public void Compare() 16 | { 17 | var Comparer = new GenericEqualityComparer(); 18 | Assert.True(Comparer.Equals("A", "A")); 19 | Assert.False(Comparer.Equals("A", "B")); 20 | Assert.False(Comparer.Equals("B", "A")); 21 | } 22 | 23 | [Fact] 24 | public void CompareNullNonValueType() 25 | { 26 | var Comparer = new GenericEqualityComparer(); 27 | Assert.True(Comparer.Equals(null, null)); 28 | Assert.False(Comparer.Equals(null, "B")); 29 | Assert.False(Comparer.Equals("B", null)); 30 | } 31 | 32 | [Fact] 33 | public void CompareValueType() 34 | { 35 | var Comparer = new GenericEqualityComparer(); 36 | Assert.True(Comparer.Equals(0, 0)); 37 | Assert.False(Comparer.Equals(0, 1)); 38 | Assert.False(Comparer.Equals(1, 0)); 39 | } 40 | 41 | [Fact] 42 | public void GetHashCodeTest() 43 | { 44 | var Comparer = new GenericEqualityComparer(); 45 | Assert.Equal("A".GetHashCode(), Comparer.GetHashCode("A")); 46 | Assert.Equal("B".GetHashCode(), Comparer.GetHashCode("B")); 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /BigBook.Tests/Comparison/SimpleComparer.cs: -------------------------------------------------------------------------------- 1 | using BigBook.Comparison; 2 | using BigBook.Tests.BaseClasses; 3 | using Xunit; 4 | 5 | namespace BigBook.Tests.Comparison 6 | { 7 | public class SimpleComparerTests : TestBaseClass> 8 | { 9 | public SimpleComparerTests() 10 | { 11 | TestObject = new SimpleComparer((x, y) => string.Compare(x, y, System.StringComparison.Ordinal)); 12 | } 13 | 14 | [Fact] 15 | public void Compare() 16 | { 17 | var Comparer = new SimpleComparer((x, y) => string.Compare(x, y, System.StringComparison.Ordinal)); 18 | Assert.Equal(0, Comparer.Compare("A", "A")); 19 | Assert.Equal(-1, Comparer.Compare("A", "B")); 20 | Assert.Equal(1, Comparer.Compare("B", "A")); 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /BigBook.Tests/Comparison/SimpleEqualityComparer.cs: -------------------------------------------------------------------------------- 1 | using BigBook.Comparison; 2 | using BigBook.Tests.BaseClasses; 3 | using Xunit; 4 | 5 | namespace BigBook.Tests.Comparison 6 | { 7 | public class SimpleEqualityComparerTests : TestBaseClass> 8 | { 9 | public SimpleEqualityComparerTests() 10 | { 11 | TestObject = new SimpleEqualityComparer((x, y) => string.Equals(x, y), x => x?.GetHashCode() ?? 0); 12 | } 13 | 14 | [Fact] 15 | public void Compare() 16 | { 17 | var Comparer = new SimpleEqualityComparer((x, y) => string.Equals(x, y), x => x.GetHashCode()); 18 | Assert.True(Comparer.Equals("A", "A")); 19 | Assert.False(Comparer.Equals("A", "B")); 20 | Assert.False(Comparer.Equals("B", "A")); 21 | } 22 | 23 | [Fact] 24 | public void GetHashCodeTest() 25 | { 26 | var Comparer = new SimpleEqualityComparer((x, y) => string.Equals(x, y), x => x.GetHashCode()); 27 | Assert.Equal("A".GetHashCode(), Comparer.GetHashCode("A")); 28 | Assert.Equal("B".GetHashCode(), Comparer.GetHashCode("B")); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /BigBook.Tests/Data/Testing/Test.txt: -------------------------------------------------------------------------------- 1 | This is a test -------------------------------------------------------------------------------- /BigBook.Tests/Data/Web/RandomCSS.css: -------------------------------------------------------------------------------- 1 | .HeaderRight .Search 2 | { 3 | position:absolute; 4 | right:5px; 5 | margin: 15px auto; 6 | } 7 | 8 | 9 | .HeaderRight .Search a 10 | { 11 | color: #333399; 12 | text-decoration: none; 13 | font-size: .9em; 14 | } 15 | 16 | .HeaderRight .Search a:visited 17 | { 18 | color: #333399; 19 | text-decoration: none; 20 | font-size: .9em; 21 | } 22 | 23 | .HeaderRight .Search a:hover 24 | { 25 | color: #7070CF; 26 | font-size: .9em; 27 | } 28 | 29 | .HeaderRight .Search .SearchBox 30 | { 31 | position:absolute; 32 | right:55px; 33 | top:30px; 34 | width:330px; 35 | /*width:75%;*/ 36 | margin-right:5px; 37 | font-size:.8em; 38 | } 39 | 40 | .HeaderRight .Search .SearchType 41 | { 42 | margin-bottom:2px; 43 | position:absolute; 44 | right:170px; 45 | top:5px; 46 | width:220px; 47 | font: Arial 9pt; 48 | font-weight:bold; 49 | } 50 | 51 | .HeaderRight .Search .Button 52 | { 53 | position:absolute; 54 | top:30px; 55 | right:5px; 56 | /*width:70px;*/ 57 | font-size:.8em; 58 | } 59 | 60 | .HeaderRight .Search .Watermark 61 | { 62 | position:absolute; 63 | color:#C0C0C0; 64 | font-style:italic; 65 | right:55px; 66 | top:30px; 67 | width:330px; 68 | margin-right:5px; 69 | font-size:.8em; 70 | } -------------------------------------------------------------------------------- /BigBook.Tests/Data/Web/RandomJS.js: -------------------------------------------------------------------------------- 1 | function InitCenter() { 2 | try { 3 | var LeftColumn = document.getElementById("LeftColumn"); 4 | var CenterColumn = document.getElementById("CenterColumn"); 5 | var mw = 400; 6 | } catch (err) { alert(err); } 7 | 8 | try { 9 | if (CenterColumn != null) { 10 | var myWidth = 0, myHeight = 0; 11 | if (typeof (window.innerWidth) == 'number') { 12 | //Non-IE 13 | myWidth = window.innerWidth; 14 | myHeight = window.innerHeight; 15 | } 16 | else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) { 17 | //IE 6+ in 'standards compliant mode' 18 | myWidth = document.documentElement.clientWidth; 19 | myHeight = document.documentElement.clientHeight; 20 | } 21 | else if (document.body && (document.body.clientWidth || document.body.clientHeight)) { 22 | //IE 4 compatible 23 | myWidth = document.body.clientWidth; 24 | myHeight = document.body.clientHeight; 25 | } 26 | 27 | var LeftOffset = LeftColumn.offsetWidth; 28 | 29 | if (CenterColumn.offsetLeft + CenterColumn.offsetWidth < LeftOffset + mw) { 30 | CenterColumn.style.right = myWidth - (LeftOffset + mw + 14) + "px"; 31 | } 32 | else { 33 | CenterColumn.style.right = "5px"; 34 | } 35 | 36 | var ccw = CenterColumn.offsetWidth; 37 | 38 | var w = 0; 39 | for (var i = 0; i < CenterColumn.getElementsByTagName("DIV").length; i++) { 40 | var el = CenterColumn.getElementsByTagName("DIV").item(i); 41 | if (el.offsetWidth > w) { w = el.offsetWidth; } 42 | } 43 | var idw = w; 44 | 45 | w = 0; 46 | for (var i = 0; i < CenterColumn.getElementsByTagName("TABLE").length; i++) { 47 | var el = CenterColumn.getElementsByTagName("TABLE").item(i); 48 | if (el.offsetWidth > w) { w = el.offsetWidth; } 49 | } 50 | var itw = w; 51 | 52 | w = 0; 53 | for (var i = 0; i < CenterColumn.getElementsByTagName("IMG").length; i++) { 54 | var el = CenterColumn.getElementsByTagName("IMG").item(i); 55 | if (el.offsetWidth > w) { w = el.offsetWidth; } 56 | } 57 | var iiw = w; 58 | ccw = ccw < idw ? idw : ccw; 59 | ccw = ccw < itw ? itw : ccw; 60 | ccw = ccw < iiw ? iiw : ccw; 61 | ccw = ccw < mw ? mw : ccw; 62 | ccw += 10; 63 | 64 | CenterColumn.style.right = "2px"; 65 | 66 | if (ccw > CenterColumn.offsetWidth) { 67 | var LeftPosition = CenterColumn.offsetLeft; 68 | CenterColumn.style.right = ((myWidth - (LeftPosition + ccw))) + "px"; 69 | } 70 | } 71 | } 72 | catch (err) { 73 | alert(err.description); 74 | } 75 | } -------------------------------------------------------------------------------- /BigBook.Tests/DateSpan.cs: -------------------------------------------------------------------------------- 1 | using BigBook.Tests.BaseClasses; 2 | using System; 3 | using Xunit; 4 | 5 | namespace BigBook.Tests 6 | { 7 | public class DateSpanTests : TestBaseClass 8 | { 9 | public DateSpanTests() 10 | { 11 | TestObject = new BigBook.DateSpan(new DateTime(1999, 1, 1), new DateTime(2009, 1, 1)); 12 | } 13 | 14 | [Fact] 15 | public void CompareTest() 16 | { 17 | var Span1 = new BigBook.DateSpan(new DateTime(1999, 1, 1), new DateTime(2009, 1, 1)); 18 | var Span2 = new BigBook.DateSpan(new DateTime(1999, 1, 1), new DateTime(2009, 1, 1)); 19 | var Span3 = new BigBook.DateSpan(new DateTime(1999, 1, 2), new DateTime(2009, 1, 1)); 20 | 21 | Assert.True(Span1 == Span2); 22 | Assert.False(Span1 == Span3); 23 | } 24 | 25 | [Fact] 26 | public void DifferenceTest() 27 | { 28 | var Span1 = new BigBook.DateSpan(new DateTime(1999, 1, 1), new DateTime(2003, 1, 1)); 29 | Assert.Equal(4, Span1.Years); 30 | Assert.Equal(0, Span1.Months); 31 | Assert.Equal(0, Span1.Days); 32 | Assert.Equal(0, Span1.Hours); 33 | Assert.Equal(0, Span1.Minutes); 34 | Assert.Equal(0, Span1.Seconds); 35 | Assert.Equal(0, Span1.MilliSeconds); 36 | var Span2 = new BigBook.DateSpan(new DateTime(1999, 1, 1, 2, 3, 4), new DateTime(2003, 11, 15, 6, 45, 32)); 37 | Assert.Equal(4, Span2.Years); 38 | Assert.Equal(10, Span2.Months); 39 | Assert.Equal(14, Span2.Days); 40 | Assert.Equal(4, Span2.Hours); 41 | Assert.Equal(42, Span2.Minutes); 42 | Assert.Equal(28, Span2.Seconds); 43 | Assert.Equal(0, Span2.MilliSeconds); 44 | } 45 | 46 | [Fact] 47 | public void IntersectionTest() 48 | { 49 | var Span1 = new BigBook.DateSpan(new DateTime(1999, 1, 1), new DateTime(2003, 1, 1)); 50 | var Span2 = new BigBook.DateSpan(new DateTime(2002, 1, 1), new DateTime(2009, 1, 1)); 51 | var Span3 = Span1.Intersection(Span2); 52 | Assert.Equal(new DateTime(2002, 1, 1), Span3.Start); 53 | Assert.Equal(new DateTime(2003, 1, 1), Span3.End); 54 | } 55 | 56 | [Fact] 57 | public void OverlapTest() 58 | { 59 | var Span1 = new BigBook.DateSpan(new DateTime(1999, 1, 1), new DateTime(2003, 1, 1)); 60 | var Span2 = new BigBook.DateSpan(new DateTime(2002, 1, 1), new DateTime(2009, 1, 1)); 61 | Assert.True(Span1.Overlap(Span2)); 62 | } 63 | 64 | [Fact] 65 | public void UnionTest() 66 | { 67 | var Span1 = new BigBook.DateSpan(new DateTime(1999, 1, 1), new DateTime(2003, 1, 1)); 68 | var Span2 = new BigBook.DateSpan(new DateTime(2002, 1, 1), new DateTime(2009, 1, 1)); 69 | var Span3 = Span1 + Span2; 70 | Assert.Equal(new DateTime(1999, 1, 1), Span3.Start); 71 | Assert.Equal(new DateTime(2009, 1, 1), Span3.End); 72 | } 73 | } 74 | } -------------------------------------------------------------------------------- /BigBook.Tests/ExtensionMethods/ArrayExtensions.cs: -------------------------------------------------------------------------------- 1 | using BigBook.Tests.BaseClasses; 2 | using Xunit; 3 | 4 | namespace BigBook.Tests.ExtensionMethods 5 | { 6 | public class ArrayExtensionsTests : TestBaseClass 7 | { 8 | protected override System.Type ObjectType { get; set; } = typeof(ArrayExtensions); 9 | 10 | [Fact] 11 | public void ClearGenericTest() 12 | { 13 | int[] TestObject = { 1, 2, 3, 4, 5, 6 }; 14 | TestObject = TestObject.Clear(); 15 | foreach (var Item in TestObject) 16 | { 17 | Assert.Equal(0, Item); 18 | } 19 | } 20 | 21 | [Fact] 22 | public void ClearNullTest() 23 | { 24 | int[] TestObject = null; 25 | TestObject = TestObject.Clear(); 26 | Assert.Null(TestObject); 27 | } 28 | 29 | [Fact] 30 | public void ClearTest() 31 | { 32 | var TestObject = new int[] { 1, 2, 3, 4, 5, 6 }; 33 | TestObject = TestObject.Clear(); 34 | foreach (var Item in TestObject) 35 | { 36 | Assert.Equal(0, Item); 37 | } 38 | } 39 | 40 | [Fact] 41 | public void CombineTest() 42 | { 43 | int[] TestObject1 = { 1, 2, 3 }; 44 | int[] TestObject2 = { 4, 5, 6 }; 45 | int[] TestObject3 = { 7, 8, 9 }; 46 | TestObject1 = TestObject1.Concat(TestObject2, TestObject3); 47 | for (var x = 0; x < 8; ++x) 48 | { 49 | Assert.Equal(x + 1, TestObject1[x]); 50 | } 51 | } 52 | 53 | [Fact] 54 | public void ConcatNull2Test() 55 | { 56 | int[] TestObject1 = { 1, 2, 3 }; 57 | TestObject1 = TestObject1.Concat(null); 58 | for (var x = 0; x < 2; ++x) 59 | { 60 | Assert.Equal(x + 1, TestObject1[x]); 61 | } 62 | } 63 | 64 | [Fact] 65 | public void ConcatNullTest() 66 | { 67 | int[] TestObject1 = null; 68 | int[] TestObject2 = { 4, 5, 6 }; 69 | int[] TestObject3 = { 7, 8, 9 }; 70 | TestObject1 = TestObject1.Concat(TestObject2, TestObject3); 71 | for (var x = 3; x < 8; ++x) 72 | { 73 | Assert.Equal(x + 1, TestObject1[x - 3]); 74 | } 75 | } 76 | } 77 | } -------------------------------------------------------------------------------- /BigBook.Tests/ExtensionMethods/ConcurrentDictionaryExtensions.cs: -------------------------------------------------------------------------------- 1 | using BigBook.Tests.BaseClasses; 2 | using System.Collections.Concurrent; 3 | using System.Linq; 4 | using Xunit; 5 | 6 | namespace BigBook.Tests.ExtensionMethods 7 | { 8 | public class ConcurrentDictionaryExtensionsTests : TestBaseClass 9 | { 10 | protected override System.Type ObjectType { get; set; } = typeof(ConcurrentDictionaryExtensions); 11 | 12 | [Fact] 13 | public void CopyToTest() 14 | { 15 | var Test = new ConcurrentDictionary(); 16 | var Test2 = new ConcurrentDictionary(); 17 | Test.AddOrUpdate("Q", 4, (_, __) => 4); 18 | Test.AddOrUpdate("Z", 2, (_, __) => 2); 19 | Test.AddOrUpdate("C", 3, (_, __) => 3); 20 | Test.AddOrUpdate("A", 1, (_, __) => 1); 21 | Test.CopyTo(Test2); 22 | var Value = ""; 23 | var Value2 = 0; 24 | foreach (var Key in Test2.Keys.OrderBy(x => x)) 25 | { 26 | Value += Key; 27 | Value2 += Test2[Key]; 28 | } 29 | Assert.Equal("ACQZ", Value); 30 | Assert.Equal(10, Value2); 31 | } 32 | 33 | [Fact] 34 | public void GetValue() 35 | { 36 | var Test = new ConcurrentDictionary(); 37 | Test.AddOrUpdate("Q", 4, (_, __) => 4); 38 | Test.AddOrUpdate("Z", 2, (_, __) => 4); 39 | Test.AddOrUpdate("C", 3, (_, __) => 4); 40 | Test.AddOrUpdate("A", 1, (_, __) => 4); 41 | Assert.Equal(4, Test.GetValue("Q")); 42 | Assert.Equal(0, Test.GetValue("V")); 43 | Assert.Equal(123, Test.GetValue("B", 123)); 44 | } 45 | 46 | [Fact] 47 | public void SetValue() 48 | { 49 | var Test = new ConcurrentDictionary(); 50 | Test.AddOrUpdate("Q", 4, (_, __) => 4); 51 | Test.AddOrUpdate("Z", 2, (_, __) => 4); 52 | Test.AddOrUpdate("C", 3, (_, __) => 4); 53 | Test.AddOrUpdate("A", 1, (_, __) => 4); 54 | Assert.Equal(4, Test.GetValue("Q")); 55 | Test.SetValue("Q", 40); 56 | Assert.Equal(40, Test.GetValue("Q")); 57 | } 58 | } 59 | } -------------------------------------------------------------------------------- /BigBook.Tests/ExtensionMethods/ExceptionExtensions.cs: -------------------------------------------------------------------------------- 1 | using BigBook.Tests.BaseClasses; 2 | using System; 3 | using Xunit; 4 | 5 | namespace BigBook.Tests.ExtensionMethods 6 | { 7 | public class ExceptionExtensionsTests : TestBaseClass 8 | { 9 | protected override System.Type ObjectType { get; set; } = typeof(ExceptionExtensions); 10 | 11 | [Fact] 12 | public void BasicExceptionOutput() => Assert.Equal($"Exception occurred{Environment.NewLine}Exception: Index was outside the bounds of the array.{Environment.NewLine}Exception Type: System.IndexOutOfRangeException{Environment.NewLine}StackTrace: {Environment.NewLine}Source: {Environment.NewLine}{Environment.NewLine}", new IndexOutOfRangeException().ToString("Exception occurred")); 13 | } 14 | } -------------------------------------------------------------------------------- /BigBook.Tests/ExtensionMethods/IComparableExtensions.cs: -------------------------------------------------------------------------------- 1 | using BigBook.Tests.BaseClasses; 2 | using Xunit; 3 | 4 | namespace BigBook.Tests.ExtensionMethods 5 | { 6 | public class IComparableExtensionsTests : TestBaseClass 7 | { 8 | protected override System.Type ObjectType { get; set; } = typeof(IComparableExtensions); 9 | 10 | [Fact] 11 | public void BetweenTest() 12 | { 13 | const int Value = 1; 14 | Assert.True(Value.Between(0, 2)); 15 | Assert.False(Value.Between(2, 10)); 16 | } 17 | 18 | [Fact] 19 | public void ClampTest() 20 | { 21 | const int Value = 10; 22 | Assert.Equal(9, Value.Clamp(9, 1)); 23 | Assert.Equal(11, Value.Clamp(15, 11)); 24 | Assert.Equal(10, Value.Clamp(11, 1)); 25 | } 26 | 27 | [Fact] 28 | public void MaxTest() 29 | { 30 | const int Value = 4; 31 | Assert.Equal(5, Value.Max(5)); 32 | Assert.Equal(4, Value.Max(1)); 33 | } 34 | 35 | [Fact] 36 | public void MinTest() 37 | { 38 | const int Value = 4; 39 | Assert.Equal(4, Value.Min(5)); 40 | Assert.Equal(1, Value.Min(1)); 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /BigBook.Tests/ExtensionMethods/IDictionaryExtensions.cs: -------------------------------------------------------------------------------- 1 | using BigBook.Tests.BaseClasses; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Xunit; 5 | 6 | namespace BigBook.Tests.ExtensionMethods 7 | { 8 | public class IDictionaryExtensionsTests : TestBaseClass 9 | { 10 | protected override System.Type ObjectType { get; set; } = typeof(IDictionaryExtensions); 11 | 12 | [Fact] 13 | public void CopyToTest() 14 | { 15 | var Test = new Dictionary(); 16 | var Test2 = new Dictionary(); 17 | Test.Add("Q", 4); 18 | Test.Add("Z", 2); 19 | Test.Add("C", 3); 20 | Test.Add("A", 1); 21 | Test.CopyTo(Test2); 22 | var Value = ""; 23 | var Value2 = 0; 24 | foreach (var Key in Test2.Keys.OrderBy(x => x)) 25 | { 26 | Value += Key; 27 | Value2 += Test2[Key]; 28 | } 29 | Assert.Equal("ACQZ", Value); 30 | Assert.Equal(10, Value2); 31 | } 32 | 33 | [Fact] 34 | public void GetValue() 35 | { 36 | var Test = new Dictionary 37 | { 38 | { "Q", 4 }, 39 | { "Z", 2 }, 40 | { "C", 3 }, 41 | { "A", 1 } 42 | }; 43 | Assert.Equal(4, Test.GetValue("Q")); 44 | Assert.Equal(0, Test.GetValue("V")); 45 | Assert.Equal(123, Test.GetValue("B", 123)); 46 | } 47 | 48 | [Fact] 49 | public void SetValue() 50 | { 51 | var Test = new Dictionary 52 | { 53 | { "Q", 4 }, 54 | { "Z", 2 }, 55 | { "C", 3 }, 56 | { "A", 1 } 57 | }; 58 | Assert.Equal(4, Test.GetValue("Q")); 59 | Test.SetValue("Q", 40); 60 | Assert.Equal(40, Test.GetValue("Q")); 61 | } 62 | 63 | [Fact] 64 | public void SortByValueTest() 65 | { 66 | IDictionary Test = new Dictionary 67 | { 68 | { "Q", 4 }, 69 | { "Z", 2 }, 70 | { "C", 3 }, 71 | { "A", 1 } 72 | }; 73 | Test = Test.Sort(x => x.Value); 74 | var Value = ""; 75 | foreach (var Key in Test.Keys) 76 | { 77 | Value += Test[Key].ToString(); 78 | } 79 | 80 | Assert.Equal("1234", Value); 81 | } 82 | 83 | [Fact] 84 | public void SortTest() 85 | { 86 | IDictionary Test = new Dictionary 87 | { 88 | { "Q", 4 }, 89 | { "Z", 2 }, 90 | { "C", 3 }, 91 | { "A", 1 } 92 | }; 93 | Test = Test.Sort(); 94 | var Value = ""; 95 | foreach (var Key in Test.Keys) 96 | { 97 | Value += Key; 98 | } 99 | 100 | Assert.Equal("ACQZ", Value); 101 | } 102 | } 103 | } -------------------------------------------------------------------------------- /BigBook.Tests/ExtensionMethods/MatchCollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | using BigBook.Tests.BaseClasses; 2 | using System.Linq; 3 | using System.Text.RegularExpressions; 4 | using Xunit; 5 | 6 | namespace BigBook.Tests.ExtensionMethods 7 | { 8 | public class MatchCollectionExtensionsTests : TestBaseClass 9 | { 10 | protected override System.Type ObjectType { get; set; } = typeof(MatchCollectionExtensions); 11 | 12 | [Fact] 13 | public void Where() 14 | { 15 | var Regex = new Regex(@"[^\s]"); 16 | Assert.Equal(3, Regex.Matches("This is a test").Where(x => x.Value == "s").Count()); 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /BigBook.Tests/ExtensionMethods/PermutationExtensions.cs: -------------------------------------------------------------------------------- 1 | using BigBook.Tests.BaseClasses; 2 | using Xunit; 3 | 4 | namespace BigBook.Tests.ExtensionMethods 5 | { 6 | /// 7 | /// Permutation extensions 8 | /// 9 | public class PermutationExtensionsTests : TestBaseClass 10 | { 11 | protected override System.Type ObjectType { get; set; } = typeof(PermutationExtensions); 12 | 13 | [Fact] 14 | public void BasicTest() 15 | { 16 | var TestObject = new System.Collections.Generic.List(); 17 | TestObject.AddRange(new string[] { "this", "is", "a", "test" }); 18 | var Results = TestObject.Permute(); 19 | Assert.Equal(24, Results.Keys.Count); 20 | foreach (var Key in Results.Keys) 21 | { 22 | foreach (var Item in Results[Key]) 23 | { 24 | Assert.True(Item == "this" || Item == "is" || Item == "a" || Item == "test"); 25 | } 26 | } 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /BigBook.Tests/ExtensionMethods/PredicateExtensions.cs: -------------------------------------------------------------------------------- 1 | using BigBook.Tests.BaseClasses; 2 | using System; 3 | using Xunit; 4 | 5 | namespace BigBook.Tests.ExtensionMethods 6 | { 7 | /// 8 | /// Predicate extensions 9 | /// 10 | public class PredicateExtensionsTests : TestBaseClass 11 | { 12 | protected override System.Type ObjectType { get; set; } = typeof(PredicateExtensions); 13 | 14 | [Fact] 15 | public void AddToSet() 16 | { 17 | Predicate Even = x => x % 2 == 0; 18 | Even = Even.AddToSet(1, 3, 5); 19 | Assert.True(Even(1)); 20 | Assert.True(Even(3)); 21 | Assert.True(Even(2)); 22 | Assert.True(Even(10)); 23 | Assert.True(Even(5)); 24 | } 25 | 26 | [Fact] 27 | public void CartesianProduct() 28 | { 29 | Predicate Even = x => x % 2 == 0; 30 | Predicate Multiple3 = x => x % 3 == 0; 31 | var CartesianProductResult = Even.CartesianProduct(Multiple3); 32 | Assert.True(CartesianProductResult(6, 12)); 33 | Assert.False(CartesianProductResult(3, 9)); 34 | } 35 | 36 | [Fact] 37 | public void Difference() 38 | { 39 | Predicate Even = x => x % 2 == 0; 40 | Predicate Multiple3 = x => x % 3 == 0; 41 | var Diff = Even.Difference(Multiple3); 42 | Assert.True(Diff(2)); 43 | Assert.True(Diff(4)); 44 | Assert.False(Diff(6)); 45 | } 46 | 47 | [Fact] 48 | public void Intersect() 49 | { 50 | Predicate Even = x => x % 2 == 0; 51 | Predicate Multiple3 = x => x % 3 == 0; 52 | var Inter = Even.Intersect(Multiple3); 53 | Assert.True(Inter(6)); 54 | Assert.True(Inter(12)); 55 | Assert.False(Inter(2)); 56 | Assert.False(Inter(3)); 57 | } 58 | 59 | [Fact] 60 | public void RelativeComplement() 61 | { 62 | Predicate Even = x => x % 2 == 0; 63 | Predicate Multiple3 = x => x % 3 == 0; 64 | var Compliement = Even.RelativeComplement(Multiple3); 65 | Assert.True(Compliement(2)); 66 | Assert.False(Compliement(6)); 67 | } 68 | 69 | [Fact] 70 | public void RemoveFromSet() 71 | { 72 | Predicate Even = x => x % 2 == 0; 73 | Even = Even.RemoveFromSet(2, 4, 6); 74 | Assert.True(Even(10)); 75 | Assert.True(Even(8)); 76 | Assert.False(Even(6)); 77 | Assert.False(Even(4)); 78 | Assert.False(Even(2)); 79 | } 80 | 81 | [Fact] 82 | public void Union() 83 | { 84 | Predicate Even = x => x % 2 == 0; 85 | Predicate Multiple3 = x => x % 3 == 0; 86 | var Test = Even.Union(Multiple3); 87 | Assert.True(Test(2)); 88 | Assert.True(Test(3)); 89 | Assert.True(Test(4)); 90 | Assert.False(Test(5)); 91 | } 92 | } 93 | } -------------------------------------------------------------------------------- /BigBook.Tests/ExtensionMethods/ProcessExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | using System.Linq; 3 | using Xunit; 4 | 5 | namespace BigBook.Tests 6 | { 7 | public class ProcessExtensionsTests 8 | { 9 | [Fact] 10 | public void GetInformation() 11 | { 12 | var Value = Process.GetProcesses().Take(4).GetInformation(); 13 | Assert.NotNull(Value); 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /BigBook.Tests/ExtensionMethods/StreamExtensions.cs: -------------------------------------------------------------------------------- 1 | using BigBook.ExtensionMethods; 2 | using BigBook.Tests.BaseClasses; 3 | using System.IO; 4 | using System.Threading.Tasks; 5 | using Xunit; 6 | 7 | namespace BigBook.Tests.ExtensionMethods 8 | { 9 | public class StreamExtensionsTests : TestBaseClass 10 | { 11 | public StreamExtensionsTests() 12 | { 13 | new DirectoryInfo(@".\Testing").Create(); 14 | } 15 | 16 | protected override System.Type ObjectType { get; set; } = null; 17 | 18 | [Fact] 19 | public void ReadAll() 20 | { 21 | WriteToFile(@".\Testing\Test.txt", "This is a test"); 22 | var File = new System.IO.FileInfo(@".\Testing\Test.txt"); 23 | using var Test = File.OpenRead(); 24 | Assert.Equal("This is a test", Test.ReadAll()); 25 | } 26 | 27 | [Fact] 28 | public async Task ReadAllAsync() 29 | { 30 | WriteToFile(@".\Testing\Test.txt", "This is a test"); 31 | var File = new System.IO.FileInfo(@".\Testing\Test.txt"); 32 | using var Test = File.OpenRead(); 33 | Assert.Equal("This is a test", await Test.ReadAllAsync()); 34 | } 35 | 36 | [Fact] 37 | public void ReadAllBinary() 38 | { 39 | WriteToFile(@".\Testing\Test.txt", "This is a test"); 40 | var File = new System.IO.FileInfo(@".\Testing\Test.txt"); 41 | using var Test = File.OpenRead(); 42 | var Content = Test.ReadAllBinary(); 43 | Assert.Equal("This is a test", System.Text.Encoding.ASCII.GetString(Content, 0, Content.Length)); 44 | } 45 | 46 | [Fact] 47 | public void ReadAllBinary2() 48 | { 49 | using var Test = new System.IO.MemoryStream(); 50 | Test.Write("This is a test".ToByteArray(), 0, "This is a test".Length); 51 | var Content = Test.ReadAllBinary(); 52 | Assert.Equal("This is a test", System.Text.Encoding.ASCII.GetString(Content, 0, Content.Length)); 53 | } 54 | 55 | [Fact] 56 | public async Task ReadAllBinary2Async() 57 | { 58 | using var Test = new System.IO.MemoryStream(); 59 | Test.Write("This is a test".ToByteArray(), 0, "This is a test".Length); 60 | var Content = await Test.ReadAllBinaryAsync(); 61 | Assert.Equal("This is a test", System.Text.Encoding.ASCII.GetString(Content, 0, Content.Length)); 62 | } 63 | 64 | [Fact] 65 | public async Task ReadAllBinaryAsync() 66 | { 67 | WriteToFile(@".\Testing\Test.txt", "This is a test"); 68 | var File = new System.IO.FileInfo(@".\Testing\Test.txt"); 69 | using var Test = File.OpenRead(); 70 | var Content = await Test.ReadAllBinaryAsync(); 71 | Assert.Equal("This is a test", System.Text.Encoding.ASCII.GetString(Content, 0, Content.Length)); 72 | } 73 | } 74 | } -------------------------------------------------------------------------------- /BigBook.Tests/ExtensionMethods/StringBuilderExtensions.cs: -------------------------------------------------------------------------------- 1 | using BigBook.Tests.BaseClasses; 2 | using System.Text; 3 | using Xunit; 4 | 5 | namespace BigBook.Tests.ExtensionMethods 6 | { 7 | /// 8 | /// StringBuilder extensions 9 | /// 10 | /// 11 | public class StringBuilderExtensions : TestBaseClass 12 | { 13 | /// 14 | /// Gets the type of the object. 15 | /// 16 | /// The type of the object. 17 | protected override System.Type ObjectType { get; set; } = null; 18 | 19 | [Fact] 20 | public void Trim() 21 | { 22 | Assert.Equal("Test", new StringBuilder(" Test ").Trim().ToString()); 23 | Assert.Equal("Test", new StringBuilder(" Test").Trim().ToString()); 24 | Assert.Equal("Test", new StringBuilder("Test ").Trim().ToString()); 25 | Assert.Equal("Test", new StringBuilder("Test").Trim().ToString()); 26 | Assert.Equal("", new StringBuilder().Trim().ToString()); 27 | Assert.Null(((StringBuilder)null).Trim()); 28 | } 29 | 30 | [Fact] 31 | public void TrimEnd() 32 | { 33 | Assert.Equal(" Test", new StringBuilder(" Test ").TrimEnd().ToString()); 34 | Assert.Equal("Test", new StringBuilder("Test").TrimEnd().ToString()); 35 | Assert.Equal("", new StringBuilder().TrimEnd().ToString()); 36 | Assert.Null(((StringBuilder)null).TrimEnd()); 37 | } 38 | 39 | /// 40 | /// Trims the start. 41 | /// 42 | [Fact] 43 | public void TrimStart() 44 | { 45 | Assert.Equal("Test ", new StringBuilder(" Test ").TrimStart().ToString()); 46 | Assert.Equal("Test", new StringBuilder("Test").TrimStart().ToString()); 47 | Assert.Equal("", new StringBuilder().TrimStart().ToString()); 48 | Assert.Null(((StringBuilder)null).TrimStart()); 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /BigBook.Tests/ExtensionMethods/TaskExtensionTests.cs: -------------------------------------------------------------------------------- 1 | using BigBook.Tests.BaseClasses; 2 | using System.Threading.Tasks; 3 | using Xunit; 4 | 5 | namespace BigBook.Tests.ExtensionMethods 6 | { 7 | public class TaskExtensionTests : TestBaseClass 8 | { 9 | protected override System.Type ObjectType { get; set; } = typeof(TaskExtensions); 10 | 11 | [Fact] 12 | public void RunSync() 13 | { 14 | Assert.Equal(2, AsyncHelper.RunSync(() => MethodAsync(1))); 15 | } 16 | 17 | private Task MethodAsync(int value) 18 | { 19 | return Task.FromResult(value + 1); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /BigBook.Tests/ExtensionMethods/TimeSpanExtensions.cs: -------------------------------------------------------------------------------- 1 | using BigBook.Tests.BaseClasses; 2 | using System; 3 | using Xunit; 4 | 5 | namespace BigBook.Tests.ExtensionMethods 6 | { 7 | public class TimeSpanExtensionsTests : TestBaseClass 8 | { 9 | protected override System.Type ObjectType { get; set; } = typeof(TimeSpanExtensions); 10 | 11 | [Fact] 12 | public void Average() => Assert.Equal(new TimeSpan(20), new TimeSpan[] { new TimeSpan(10), new TimeSpan(30) }.Average()); 13 | 14 | [Fact] 15 | public void DaysRemainder() => Assert.Equal(0, (new DateTime(2011, 12, 1) - new DateTime(1977, 1, 1)).DaysRemainder()); 16 | 17 | [Fact] 18 | public void Months() => Assert.Equal(11, (new DateTime(2011, 12, 1) - new DateTime(1977, 1, 1)).Months()); 19 | 20 | [Fact] 21 | public void ToStringFull() => Assert.Equal("34 years, 11 months", (new DateTime(2011, 12, 1) - new DateTime(1977, 1, 1)).ToStringFull()); 22 | 23 | [Fact] 24 | public void Years() => Assert.Equal(34, (new DateTime(2011, 12, 1) - new DateTime(1977, 1, 1)).Years()); 25 | } 26 | } -------------------------------------------------------------------------------- /BigBook.Tests/ExtensionMethods/ValueType.cs: -------------------------------------------------------------------------------- 1 | using BigBook.ExtensionMethods; 2 | using System.Text; 3 | using Xunit; 4 | 5 | namespace BigBook.Tests.ExtensionMethods 6 | { 7 | public class ValueTypeTests 8 | { 9 | [Fact] 10 | public void Is() 11 | { 12 | Assert.True('a'.Is(CharIs.Lower)); 13 | Assert.True('A'.Is(CharIs.Upper)); 14 | Assert.True(' '.Is(CharIs.WhiteSpace)); 15 | } 16 | 17 | [Fact] 18 | public void UnicodeTest() 19 | { 20 | const string Value = "\u25EF\u25EF\u25EF"; 21 | Assert.True(Value.ToByteArray(new UnicodeEncoding()).IsUnicode()); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /BigBook.Tests/Fraction.cs: -------------------------------------------------------------------------------- 1 | using BigBook.Tests.BaseClasses; 2 | using Xunit; 3 | 4 | namespace BigBook.Tests 5 | { 6 | public class FractionTests : TestBaseClass 7 | { 8 | public FractionTests() 9 | { 10 | TestObject = new BigBook.Fraction(9, 27); 11 | } 12 | 13 | [Fact] 14 | public void BasicTest() 15 | { 16 | var TestObject = new BigBook.Fraction(9, 27); 17 | var TestObject2 = new BigBook.Fraction(3, 4); 18 | TestObject.Reduce(); 19 | Assert.Equal(3, TestObject.Denominator); 20 | Assert.Equal(1, TestObject.Numerator); 21 | Assert.Equal(new BigBook.Fraction(1, 4), TestObject * TestObject2); 22 | Assert.Equal(new BigBook.Fraction(13, 12), TestObject + TestObject2); 23 | Assert.Equal(new BigBook.Fraction(-5, 12), TestObject - TestObject2); 24 | Assert.Equal(new BigBook.Fraction(4, 9), TestObject / TestObject2); 25 | Assert.Equal(new BigBook.Fraction(-1, 3), -TestObject); 26 | Assert.Equal(new BigBook.Fraction(9, 27), TestObject); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /BigBook.Tests/GlobalSuppressions.cs: -------------------------------------------------------------------------------- 1 | // This file is used by Code Analysis to maintain SuppressMessage 2 | // attributes that are applied to this project. 3 | // Project-level suppressions either have no target or are given 4 | // a specific target and scoped to a namespace, type, member, etc. 5 | 6 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Security", "SCS0005:Weak random generator", Justification = "", Scope = "member", Target = "~M:BigBook.Tests.ListMappingTests.RandomTest")] -------------------------------------------------------------------------------- /BigBook.Tests/GraphTests.cs: -------------------------------------------------------------------------------- 1 | using BigBook.Tests.BaseClasses; 2 | using Xunit; 3 | 4 | namespace BigBook.Tests 5 | { 6 | public class GraphTests : TestBaseClass> 7 | { 8 | public GraphTests() 9 | { 10 | TestObject = new Graph(); 11 | var Vertex1 = TestObject.AddVertex(1); 12 | var Vertex2 = TestObject.AddVertex(2); 13 | var Vertex3 = TestObject.AddVertex(3); 14 | var Edge1 = TestObject.AddEdge(Vertex1, Vertex2); 15 | var Edge2 = TestObject.AddEdge(Vertex1, Vertex3); 16 | var Edge3 = TestObject.AddEdge(Vertex2, Vertex3); 17 | } 18 | 19 | [Fact] 20 | public void Creation() 21 | { 22 | var TestObject = new Graph(); 23 | var Vertex1 = TestObject.AddVertex(1); 24 | var Vertex2 = TestObject.AddVertex(2); 25 | var Vertex3 = TestObject.AddVertex(3); 26 | var Edge1 = TestObject.AddEdge(Vertex1, Vertex2); 27 | var Edge2 = TestObject.AddEdge(Vertex1, Vertex3); 28 | var Edge3 = TestObject.AddEdge(Vertex2, Vertex3); 29 | Assert.Equal(3, TestObject.Vertices.Count); 30 | Assert.Equal(Edge1, Vertex1.OutgoingEdges[0]); 31 | Assert.Equal(Edge2, Vertex1.OutgoingEdges[1]); 32 | Assert.Equal(Edge3, Vertex2.OutgoingEdges[0]); 33 | } 34 | 35 | [Fact] 36 | public void RemoveVertex() 37 | { 38 | var TestObject = new Graph(); 39 | var Vertex1 = TestObject.AddVertex(1); 40 | var Vertex2 = TestObject.AddVertex(2); 41 | var Vertex3 = TestObject.AddVertex(3); 42 | var Edge1 = TestObject.AddEdge(Vertex1, Vertex2); 43 | var Edge2 = TestObject.AddEdge(Vertex1, Vertex3); 44 | var Edge3 = TestObject.AddEdge(Vertex2, Vertex3); 45 | TestObject.RemoveVertex(Vertex3); 46 | Assert.Equal(2, TestObject.Vertices.Count); 47 | Assert.Equal(Edge1, Vertex1.OutgoingEdges[0]); 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /BigBook.Tests/IO/BitReaderTests.cs: -------------------------------------------------------------------------------- 1 | using BigBook.Tests.BaseClasses; 2 | using Xunit; 3 | 4 | namespace BigBook.IO.Tests 5 | { 6 | public class BitReaderTests : TestBaseClass 7 | { 8 | public BitReaderTests() 9 | { 10 | TestObject = new BitReader(new byte[] { 1, 2, 3, 4, 5 }); 11 | } 12 | 13 | [Fact] 14 | public void Creation() 15 | { 16 | using var TestObject = new BitReader(new byte[] { 1, 2, 3, 4, 5 }); 17 | Assert.NotNull(TestObject); 18 | } 19 | 20 | [Fact] 21 | public void ReadBit() 22 | { 23 | using var TestObject = new BitReader(new byte[] { 1, 2, 3, 4, 5 }); 24 | Assert.NotNull(TestObject); 25 | var Value = TestObject.ReadBit(); 26 | Assert.True(Value.HasValue); 27 | Assert.False(Value.Value); 28 | for (var x = 0; x < 6; ++x) 29 | { 30 | Value = TestObject.ReadBit(); 31 | Assert.True(Value.HasValue); 32 | Assert.False(Value.Value); 33 | } 34 | Value = TestObject.ReadBit(); 35 | Assert.True(Value.HasValue); 36 | Assert.True(Value.Value); 37 | } 38 | 39 | [Fact] 40 | public void ReadBitBigEndian() 41 | { 42 | using var TestObject = new BitReader(new byte[] { 1, 2, 3, 4, 5 }); 43 | Assert.NotNull(TestObject); 44 | var Value = TestObject.ReadBit(true); 45 | Assert.True(Value.HasValue); 46 | Assert.True(Value.Value); 47 | for (var x = 0; x < 7; ++x) 48 | { 49 | Value = TestObject.ReadBit(true); 50 | Assert.True(Value.HasValue); 51 | Assert.False(Value.Value); 52 | } 53 | } 54 | 55 | [Fact] 56 | public void Skip() 57 | { 58 | using var TestObject = new BitReader(new byte[] { 1, 2, 3, 4, 5 }); 59 | Assert.NotNull(TestObject); 60 | var Value = TestObject.ReadBit(); 61 | Assert.True(Value.HasValue); 62 | Assert.False(Value.Value); 63 | TestObject.Skip(6); 64 | Value = TestObject.ReadBit(); 65 | Assert.True(Value.HasValue); 66 | Assert.True(Value.Value); 67 | } 68 | 69 | [Fact] 70 | public void SkipBigEndian() 71 | { 72 | using var TestObject = new BitReader(new byte[] { 1, 2, 3, 4, 5 }); 73 | Assert.NotNull(TestObject); 74 | var Value = TestObject.ReadBit(true); 75 | Assert.True(Value.HasValue); 76 | Assert.True(Value.Value); 77 | TestObject.Skip(6); 78 | Value = TestObject.ReadBit(true); 79 | Assert.True(Value.HasValue); 80 | Assert.False(Value.Value); 81 | } 82 | } 83 | } -------------------------------------------------------------------------------- /BigBook.Tests/LazyAsyncTests.cs: -------------------------------------------------------------------------------- 1 | using BigBook.Tests.BaseClasses; 2 | using System.Threading.Tasks; 3 | using Xunit; 4 | 5 | namespace BigBook.Tests 6 | { 7 | public class LazyAsyncTests : TestBaseClass> 8 | { 9 | public LazyAsyncTests() 10 | { 11 | TestObject = new LazyAsync(() => 5); 12 | } 13 | 14 | [Fact] 15 | public async Task AwaitTest() 16 | { 17 | var TestObject = new LazyAsync(() => 5); 18 | Assert.Equal(5, await TestObject); 19 | 20 | TestObject = new LazyAsync(GetValue); 21 | Assert.Equal(50, await TestObject); 22 | } 23 | 24 | private Task GetValue() 25 | { 26 | return Task.FromResult(50); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /BigBook.Tests/ListMapping.cs: -------------------------------------------------------------------------------- 1 | using BigBook.Tests.BaseClasses; 2 | using System.Linq; 3 | using Xunit; 4 | 5 | namespace BigBook.Tests 6 | { 7 | public class ListMappingTests : TestBaseClass> 8 | { 9 | public ListMappingTests() 10 | { 11 | TestObject = new ListMapping 12 | { 13 | { "A", 0 }, 14 | { "A", 1 } 15 | }; 16 | } 17 | 18 | [Fact] 19 | public void ContainsTest() 20 | { 21 | var TestObject = new ListMapping 22 | { 23 | { "A", 0 }, 24 | { "A", 1 } 25 | }; 26 | Assert.True(TestObject.Contains("A", 0)); 27 | Assert.False(TestObject.Contains("A", 2)); 28 | } 29 | 30 | [Fact] 31 | public void RandomTest() 32 | { 33 | var TestObject = new ListMapping(); 34 | var Rand = new System.Random(); 35 | for (var x = 0; x < 10; ++x) 36 | { 37 | var Name = x.ToString(); 38 | for (var y = 0; y < 5; ++y) 39 | { 40 | var Value = Rand.Next(); 41 | TestObject.Add(Name, Value); 42 | Assert.Equal(y + 1, TestObject[Name].Count()); 43 | Assert.Contains(Value, TestObject[Name]); 44 | } 45 | } 46 | Assert.Equal(10, TestObject.Count); 47 | } 48 | 49 | [Fact] 50 | public void RemoveTest() 51 | { 52 | var TestObject = new ListMapping 53 | { 54 | { "A", 0 }, 55 | { "A", 1 } 56 | }; 57 | TestObject.Remove("A", 0); 58 | Assert.Single(TestObject["A"]); 59 | Assert.Equal(1, TestObject["A"].FirstOrDefault()); 60 | } 61 | } 62 | } -------------------------------------------------------------------------------- /BigBook.Tests/ManyToManyIndexTests.cs: -------------------------------------------------------------------------------- 1 | using BigBook.Tests.BaseClasses; 2 | using System.Linq; 3 | using Xunit; 4 | 5 | namespace BigBook.Tests 6 | { 7 | public class ManyToManyIndexTests : TestBaseClass> 8 | { 9 | public ManyToManyIndexTests() 10 | { 11 | TestObject = new ManyToManyIndex(); 12 | } 13 | 14 | [Fact] 15 | public void Add() 16 | { 17 | var TestObject = new ManyToManyIndex(); 18 | TestObject.Add(1, "A", "B"); 19 | Assert.True(TestObject.TryGetValue(1, out var Values)); 20 | Assert.Equal(2, Values.Count()); 21 | Assert.True(TestObject.TryGetValue("A", out var ValuesInt)); 22 | Assert.Single(ValuesInt); 23 | } 24 | 25 | [Fact] 26 | public void Remove() 27 | { 28 | var TestObject = new ManyToManyIndex(); 29 | TestObject.Add(1, "A", "B"); 30 | Assert.True(TestObject.TryGetValue(1, out var Values)); 31 | Assert.Equal(2, Values.Count()); 32 | Assert.True(TestObject.TryGetValue("A", out var ValuesInt)); 33 | Assert.Single(ValuesInt); 34 | TestObject.Remove("B"); 35 | Assert.True(TestObject.TryGetValue(1, out Values)); 36 | Assert.Single(Values); 37 | Assert.True(TestObject.TryGetValue("A", out ValuesInt)); 38 | Assert.Single(ValuesInt); 39 | Assert.False(TestObject.TryGetValue("B", out ValuesInt)); 40 | Assert.Empty(ValuesInt); 41 | TestObject.Remove("A"); 42 | Assert.False(TestObject.TryGetValue(1, out Values)); 43 | Assert.Empty(Values); 44 | Assert.False(TestObject.TryGetValue("A", out ValuesInt)); 45 | Assert.Empty(ValuesInt); 46 | Assert.False(TestObject.TryGetValue("B", out ValuesInt)); 47 | Assert.Empty(ValuesInt); 48 | } 49 | 50 | [Fact] 51 | public void RemoveLeftToRight() 52 | { 53 | var TestObject = new ManyToManyIndex(); 54 | TestObject.Add(1, "A", "B"); 55 | Assert.True(TestObject.TryGetValue(1, out var Values)); 56 | Assert.Equal(2, Values.Count()); 57 | Assert.True(TestObject.TryGetValue("A", out var ValuesInt)); 58 | Assert.Single(ValuesInt); 59 | TestObject.Remove(1); 60 | Assert.False(TestObject.TryGetValue(1, out Values)); 61 | Assert.Empty(Values); 62 | Assert.False(TestObject.TryGetValue("A", out ValuesInt)); 63 | Assert.Empty(ValuesInt); 64 | Assert.False(TestObject.TryGetValue("B", out ValuesInt)); 65 | Assert.Empty(ValuesInt); 66 | } 67 | } 68 | } -------------------------------------------------------------------------------- /BigBook.Tests/Matrix.cs: -------------------------------------------------------------------------------- 1 | using BigBook.Tests.BaseClasses; 2 | using Xunit; 3 | 4 | namespace BigBook.Tests 5 | { 6 | public class MatrixTests : TestBaseClass 7 | { 8 | public MatrixTests() 9 | { 10 | TestObject = new BigBook.Matrix(3, 3, new double[,] { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }); 11 | } 12 | 13 | [Fact] 14 | public void BasicTest() 15 | { 16 | var TestObject = new BigBook.Matrix(3, 3, new double[,] { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }); 17 | var TestObject2 = new BigBook.Matrix(3, 3, new double[,] { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }); 18 | Assert.Equal(4, TestObject[1, 0]); 19 | Assert.Equal(8, (TestObject + TestObject2)[1, 0]); 20 | Assert.Equal(8, (TestObject * 2)[1, 0]); 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /BigBook.Tests/PriorityQueue.cs: -------------------------------------------------------------------------------- 1 | using BigBook.Tests.BaseClasses; 2 | using Xunit; 3 | 4 | namespace BigBook.Tests 5 | { 6 | public class PriorityQueueTests : TestBaseClass> 7 | { 8 | public PriorityQueueTests() 9 | { 10 | TestObject = new PriorityQueue(); 11 | } 12 | 13 | [Fact] 14 | public void PopTest() 15 | { 16 | var TestObject = new PriorityQueue(); 17 | var Rand = new System.Random(); 18 | var Value = 0; 19 | for (var x = 0; x < 10; ++x) 20 | { 21 | Value = Rand.Next(); 22 | TestObject.Add(x, Value); 23 | Assert.Equal(Value, TestObject.Pop()); 24 | } 25 | } 26 | 27 | [Fact] 28 | public void RandomTest() 29 | { 30 | var TestObject = new PriorityQueue(); 31 | var Rand = new System.Random(); 32 | var Value = 0; 33 | for (var x = 0; x < 10; ++x) 34 | { 35 | Value = Rand.Next(); 36 | TestObject.Add(x, Value); 37 | Assert.Equal(Value, TestObject.Peek()); 38 | } 39 | var HighestValue = TestObject.Peek(); 40 | for (var x = 9; x >= 0; --x) 41 | { 42 | Value = Rand.Next(); 43 | TestObject.Add(x, Value); 44 | Assert.Equal(HighestValue, TestObject.Peek()); 45 | } 46 | var Count = 0; 47 | foreach (var Priority in TestObject.Keys) 48 | { 49 | foreach (var Item in TestObject[Priority]) 50 | { 51 | ++Count; 52 | } 53 | } 54 | Assert.Equal(20, Count); 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /BigBook.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following set of attributes. 5 | // Change these attribute values to modify the information associated with an assembly. 6 | [assembly: AssemblyConfiguration("")] 7 | [assembly: AssemblyCompany("")] 8 | [assembly: AssemblyProduct("BigBook.Tests")] 9 | [assembly: AssemblyTrademark("")] 10 | 11 | // Setting ComVisible to false makes the types in this assembly not visible to COM components. If you 12 | // need to access a type in this assembly from COM, set the ComVisible attribute to true on that type. 13 | [assembly: ComVisible(false)] 14 | 15 | // The following GUID is for the ID of the typelib if this project is exposed to COM 16 | [assembly: Guid("c75e2943-501d-40e6-9dcb-8620de9c02e9")] -------------------------------------------------------------------------------- /BigBook.Tests/Reflection/TypeCacheForTests.cs: -------------------------------------------------------------------------------- 1 | using BigBook.Reflection; 2 | using Xunit; 3 | 4 | namespace BigBook.Tests.Reflection 5 | { 6 | public class TypeCacheForTests 7 | { 8 | [Fact] 9 | public void BasicTest() 10 | { 11 | Assert.Single(TypeCacheFor.Constructors); 12 | Assert.Empty(TypeCacheFor.Fields); 13 | Assert.Empty(TypeCacheFor.Interfaces); 14 | Assert.NotEmpty(TypeCacheFor.Methods); 15 | Assert.Empty(TypeCacheFor.Properties); 16 | Assert.NotNull(TypeCacheFor.Type); 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /BigBook.Tests/RingBuffer.cs: -------------------------------------------------------------------------------- 1 | using BigBook; 2 | using BigBook.Tests.BaseClasses; 3 | using System; 4 | using System.Collections; 5 | using System.Linq; 6 | using Xunit; 7 | 8 | namespace BigBook.Tests 9 | { 10 | public class RingBufferTests : TestBaseClass> 11 | { 12 | public RingBufferTests() 13 | { 14 | TestObject = null; 15 | ObjectType = null; 16 | } 17 | 18 | [Fact] 19 | public void RandomTest() 20 | { 21 | var TestObject = new RingBuffer(10); 22 | var Rand = new System.Random(); 23 | var Value = 0; 24 | for (var x = 0; x < 10; ++x) 25 | { 26 | Value = Rand.Next(); 27 | TestObject.Add(Value); 28 | Assert.Single(TestObject); 29 | Assert.Equal(Value, TestObject.Remove()); 30 | } 31 | Assert.Empty((IEnumerable)TestObject); 32 | var Values = new System.Collections.Generic.List(); 33 | for (var x = 0; x < 10; ++x) 34 | { 35 | Values.Add(Rand.Next()); 36 | } 37 | TestObject.Add(Values); 38 | Assert.Equal(Values.ToArray(), TestObject.ToArray()); 39 | 40 | for (var x = 0; x < 10; ++x) 41 | { 42 | Assert.Throws(() => TestObject.Add(Rand.Next())); 43 | Assert.Equal(10, TestObject.Count); 44 | } 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /BigBook.Tests/Set.cs: -------------------------------------------------------------------------------- 1 | using BigBook.Tests.BaseClasses; 2 | using Xunit; 3 | 4 | namespace BigBook.Tests 5 | { 6 | public class SetTests : TestBaseClass> 7 | { 8 | public SetTests() 9 | { 10 | TestObject = new Set(); 11 | } 12 | 13 | [Fact] 14 | public void BasicTest() 15 | { 16 | var TestObject = new Set(); 17 | var TestObject2 = new Set(); 18 | for (var x = 0; x < 10; ++x) 19 | { 20 | TestObject.Add(x); 21 | } 22 | 23 | for (var x = 9; x >= 0; --x) 24 | { 25 | TestObject2.Add(x); 26 | } 27 | 28 | Assert.True(TestObject.IsSubset(TestObject2)); 29 | Assert.True(TestObject.Contains(TestObject2)); 30 | Assert.True(TestObject.Intersect(TestObject2)); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /BigBook.Tests/Table.cs: -------------------------------------------------------------------------------- 1 | using BigBook.Tests.BaseClasses; 2 | using Xunit; 3 | 4 | namespace BigBook.Tests 5 | { 6 | public class TableTests : TestBaseClass 7 | { 8 | public TableTests() 9 | { 10 | TestObject = new Table("Column1", "Column2", "Column3"); 11 | } 12 | 13 | [Fact] 14 | public void CreationTest() 15 | { 16 | var Table = new BigBook.Table("Column1", "Column2", "Column3"); 17 | Assert.Equal(3, Table.ColumnNames.Length); 18 | Assert.Equal("Column1", Table.ColumnNames[0]); 19 | Assert.Equal("Column2", Table.ColumnNames[1]); 20 | Assert.Equal("Column3", Table.ColumnNames[2]); 21 | } 22 | 23 | [Fact] 24 | public void RowCreationTest() 25 | { 26 | var Table = new BigBook.Table("Column1", "Column2", "Column3"); 27 | Table.AddRow(1, "A", 9.2f) 28 | .AddRow(2, "B", 8.2f) 29 | .AddRow(3, "C", 7.2f); 30 | Assert.Equal(3, Table.Rows.Count); 31 | Assert.Equal(1, Table[0][0]); 32 | Assert.Equal("A", Table[0][1]); 33 | Assert.Equal(9.2f, Table[0][2]); 34 | Assert.Equal(2, Table[1][0]); 35 | Assert.Equal("B", Table[1][1]); 36 | Assert.Equal(8.2f, Table[1][2]); 37 | Assert.Equal(3, Table[2][0]); 38 | Assert.Equal("C", Table[2][1]); 39 | Assert.Equal(7.2f, Table[2][2]); 40 | Assert.Equal("Column1", Table[0].ColumnNames[0]); 41 | Assert.Equal("Column2", Table[0].ColumnNames[1]); 42 | Assert.Equal("Column3", Table[0].ColumnNames[2]); 43 | Assert.Equal(1, Table[0]["Column1"]); 44 | Assert.Equal("A", Table[0]["Column2"]); 45 | Assert.Equal(9.2f, Table[0]["Column3"]); 46 | Assert.Equal(2, Table[1]["Column1"]); 47 | Assert.Equal("B", Table[1]["Column2"]); 48 | Assert.Equal(8.2f, Table[1]["Column3"]); 49 | Assert.Equal(3, Table[2]["Column1"]); 50 | Assert.Equal("C", Table[2]["Column2"]); 51 | Assert.Equal(7.2f, Table[2]["Column3"]); 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /BigBook.Tests/TagDictionary.cs: -------------------------------------------------------------------------------- 1 | using BigBook; 2 | using BigBook.Tests.BaseClasses; 3 | using System.Linq; 4 | using Xunit; 5 | 6 | namespace BigBook.Tests 7 | { 8 | public class TagDictionaryTests : TestBaseClass> 9 | { 10 | public TagDictionaryTests() 11 | { 12 | TestObject = new TagDictionary(); 13 | } 14 | 15 | [Fact] 16 | public void BasicTest() 17 | { 18 | var TestObject = new TagDictionary(); 19 | 10.Times(x => TestObject.Add("Object" + x, (x + 1).Times(y => "Key" + y).ToArray())); 20 | 11.Times(x => Assert.Equal(10 - x, TestObject["Key" + x].Count())); 21 | Assert.Equal(10, TestObject["Key0"].Count()); 22 | TestObject.Remove("Key0"); 23 | Assert.Empty(TestObject["Key0"]); 24 | 11.Times(x => Assert.Empty(TestObject["Key" + x])); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /BigBook.Tests/TaskQueueTests.cs: -------------------------------------------------------------------------------- 1 | using BigBook.Tests.BaseClasses; 2 | using System.Linq; 3 | using System.Text; 4 | using System.Threading; 5 | using Xunit; 6 | 7 | namespace BigBook.Tests 8 | { 9 | public class TaskQueueTests : TestBaseClass> 10 | { 11 | public TaskQueueTests() 12 | { 13 | var Results = new double[100]; 14 | TestObject = null; 15 | this.ObjectType = null; 16 | } 17 | 18 | private readonly double EPSILON = 0.0001d; 19 | 20 | [Fact] 21 | public void MoreComplexTasks() 22 | { 23 | var Results = new double[100]; 24 | var TestObject = new TaskQueue(4, x => { Results[x] = 2 * F(1); return true; }); 25 | for (var x = 0; x < 100; ++x) 26 | { 27 | Assert.True(TestObject.Enqueue(x)); 28 | } 29 | while (!TestObject.IsComplete) 30 | { 31 | Thread.Sleep(100); 32 | } 33 | 34 | Assert.True(Results.All(x => System.Math.Abs(x - 3.14159d) < EPSILON)); 35 | } 36 | 37 | [Fact] 38 | public void SimpleTasks() 39 | { 40 | var Builder = new StringBuilder(); 41 | int[] Temp = { 0, 0, 1, 2, 3 }; 42 | var LockObject = new object(); 43 | var TestObject = new TaskQueue(4, x => 44 | { 45 | lock (LockObject) 46 | { 47 | Builder.Append(x); 48 | return true; 49 | } 50 | }); 51 | for (var x = 0; x < Temp.Length; ++x) 52 | { 53 | Assert.True(TestObject.Enqueue(Temp[x])); 54 | } 55 | while (!TestObject.IsComplete) 56 | { 57 | Thread.Sleep(100); 58 | } 59 | 60 | var OrderedString = new string(Builder.ToString().OrderBy(x => x).ToArray()); 61 | Assert.Equal("00123", OrderedString); 62 | } 63 | 64 | private double F(int i) 65 | { 66 | if (i == 1000) 67 | { 68 | return 1; 69 | } 70 | 71 | return 1 + (i / ((2.0 * i) + 1) * F(i + 1)); 72 | } 73 | } 74 | } -------------------------------------------------------------------------------- /BigBook.Tests/TrieTests.cs: -------------------------------------------------------------------------------- 1 | using BigBook.Tests.BaseClasses; 2 | using System; 3 | using System.Linq; 4 | using Xunit; 5 | 6 | namespace BigBook.Tests 7 | { 8 | public class TrieTests : TestBaseClass 9 | { 10 | public TrieTests() 11 | { 12 | TestObject = new StringTrie(); 13 | } 14 | 15 | [Fact] 16 | public void FindAll() 17 | { 18 | const string TestString = "The quick brown fox jumps over the lazy dog"; 19 | var TestObject = new StringTrie(); 20 | TestObject.Add("jumps", "dog") 21 | .Build(); 22 | 23 | var Results = TestObject.FindAll(TestString).ToArray(); 24 | Assert.Equal(2, Results.Length); 25 | Assert.Equal("jumps", Results[0]); 26 | Assert.Equal("dog", Results[1]); 27 | } 28 | 29 | [Fact] 30 | public void FindAllSpan() 31 | { 32 | const string TestString = "The quick brown fox jumps over the lazy dog"; 33 | var TestObject = new StringTrie(); 34 | TestObject.Add("jumps", "dog") 35 | .Build(); 36 | 37 | var Results = TestObject.FindAll(TestString.AsSpan()).ToArray(); 38 | Assert.Equal(2, Results.Length); 39 | Assert.Equal("jumps", Results[0]); 40 | Assert.Equal("dog", Results[1]); 41 | } 42 | 43 | [Fact] 44 | public void FindAny() 45 | { 46 | const string TestString = "The quick brown fox jumps over the lazy dog"; 47 | var TestObject = new StringTrie(); 48 | TestObject.Add("jumps", "dog", "brown") 49 | .Build(); 50 | 51 | var Results = TestObject.FindAny(TestString).ToArray(); 52 | Assert.Equal("brown", new string(Results)); 53 | } 54 | 55 | [Fact] 56 | public void FindLonger() 57 | { 58 | const string TestString = "The quick brown fox jumps over the lazy dog"; 59 | var TestObject = new StringTrie(); 60 | TestObject.Add("brown", "brown fox") 61 | .Build(); 62 | 63 | var Results = TestObject.FindAny(TestString); 64 | var Results2 = TestObject.FindAll(TestString).ToArray(); 65 | Assert.Equal("brown", Results); 66 | Assert.Equal("brown fox", Results2[1]); 67 | Assert.Equal("brown", Results2[0]); 68 | } 69 | } 70 | } -------------------------------------------------------------------------------- /BigBook.Tests/Vector3.cs: -------------------------------------------------------------------------------- 1 | using BigBook.Tests.BaseClasses; 2 | using Xunit; 3 | 4 | namespace BigBook.Tests 5 | { 6 | public class Vector3Tests : TestBaseClass 7 | { 8 | public Vector3Tests() 9 | { 10 | TestObject = new BigBook.Vector3(2.5, 4.1, 1.3); 11 | } 12 | 13 | [Fact] 14 | public void BasicTest() 15 | { 16 | var TestObject = new BigBook.Vector3(2.5, 4.1, 1.3); 17 | Assert.InRange(TestObject.Magnitude, 4.97, 4.98); 18 | TestObject.Normalize(); 19 | Assert.InRange(TestObject.X, .5, .6); 20 | Assert.InRange(TestObject.Y, .82, .83); 21 | Assert.InRange(TestObject.Z, .26, .27); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /BigBook.Tests/xunit.runner.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://xunit.net/schema/current/xunit.runner.schema.json", 3 | "parallelizeTestCollections": true 4 | } -------------------------------------------------------------------------------- /BigBook.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.6.33815.320 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{7CBC4576-531F-4D1E-A5A4-9DA17AED676F}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{4423A719-917F-4908-9586-67B0C8CF2EFE}" 9 | ProjectSection(SolutionItems) = preProject 10 | .editorconfig = .editorconfig 11 | EndProjectSection 12 | EndProject 13 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{8D8A6F73-03CC-4CDC-876A-240A613228E1}" 14 | EndProject 15 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BigBook.Benchmarks", "BigBook.Benchmarks\BigBook.Benchmarks.csproj", "{E6803AA6-ACB3-48F6-9798-7686499772BD}" 16 | EndProject 17 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestSize", "TestSize\TestSize.csproj", "{195CD080-F7E7-4E98-8D06-2C1FB2E019CD}" 18 | EndProject 19 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BigBook.Example", "BigBook.Example\BigBook.Example.csproj", "{DDEB74D1-A4CE-4C36-BCCE-E16F6864322D}" 20 | EndProject 21 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BigBook", "BigBook\BigBook.csproj", "{FF57E3BB-8B10-4999-AD1C-E78F808C1435}" 22 | EndProject 23 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BigBook.Tests", "BigBook.Tests\BigBook.Tests.csproj", "{33AD29AB-E75B-4816-921B-DBF429EB8989}" 24 | EndProject 25 | Global 26 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 27 | Debug|Any CPU = Debug|Any CPU 28 | Release|Any CPU = Release|Any CPU 29 | EndGlobalSection 30 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 31 | {E6803AA6-ACB3-48F6-9798-7686499772BD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 32 | {E6803AA6-ACB3-48F6-9798-7686499772BD}.Debug|Any CPU.Build.0 = Debug|Any CPU 33 | {E6803AA6-ACB3-48F6-9798-7686499772BD}.Release|Any CPU.ActiveCfg = Release|Any CPU 34 | {E6803AA6-ACB3-48F6-9798-7686499772BD}.Release|Any CPU.Build.0 = Release|Any CPU 35 | {195CD080-F7E7-4E98-8D06-2C1FB2E019CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 36 | {195CD080-F7E7-4E98-8D06-2C1FB2E019CD}.Debug|Any CPU.Build.0 = Debug|Any CPU 37 | {195CD080-F7E7-4E98-8D06-2C1FB2E019CD}.Release|Any CPU.ActiveCfg = Release|Any CPU 38 | {195CD080-F7E7-4E98-8D06-2C1FB2E019CD}.Release|Any CPU.Build.0 = Release|Any CPU 39 | {DDEB74D1-A4CE-4C36-BCCE-E16F6864322D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 40 | {DDEB74D1-A4CE-4C36-BCCE-E16F6864322D}.Debug|Any CPU.Build.0 = Debug|Any CPU 41 | {DDEB74D1-A4CE-4C36-BCCE-E16F6864322D}.Release|Any CPU.ActiveCfg = Release|Any CPU 42 | {DDEB74D1-A4CE-4C36-BCCE-E16F6864322D}.Release|Any CPU.Build.0 = Release|Any CPU 43 | {FF57E3BB-8B10-4999-AD1C-E78F808C1435}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 44 | {FF57E3BB-8B10-4999-AD1C-E78F808C1435}.Debug|Any CPU.Build.0 = Debug|Any CPU 45 | {FF57E3BB-8B10-4999-AD1C-E78F808C1435}.Release|Any CPU.ActiveCfg = Release|Any CPU 46 | {FF57E3BB-8B10-4999-AD1C-E78F808C1435}.Release|Any CPU.Build.0 = Release|Any CPU 47 | {33AD29AB-E75B-4816-921B-DBF429EB8989}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 48 | {33AD29AB-E75B-4816-921B-DBF429EB8989}.Debug|Any CPU.Build.0 = Debug|Any CPU 49 | {33AD29AB-E75B-4816-921B-DBF429EB8989}.Release|Any CPU.ActiveCfg = Release|Any CPU 50 | {33AD29AB-E75B-4816-921B-DBF429EB8989}.Release|Any CPU.Build.0 = Release|Any CPU 51 | EndGlobalSection 52 | GlobalSection(SolutionProperties) = preSolution 53 | HideSolutionNode = FALSE 54 | EndGlobalSection 55 | GlobalSection(NestedProjects) = preSolution 56 | {E6803AA6-ACB3-48F6-9798-7686499772BD} = {8D8A6F73-03CC-4CDC-876A-240A613228E1} 57 | {195CD080-F7E7-4E98-8D06-2C1FB2E019CD} = {8D8A6F73-03CC-4CDC-876A-240A613228E1} 58 | {FF57E3BB-8B10-4999-AD1C-E78F808C1435} = {7CBC4576-531F-4D1E-A5A4-9DA17AED676F} 59 | {33AD29AB-E75B-4816-921B-DBF429EB8989} = {8D8A6F73-03CC-4CDC-876A-240A613228E1} 60 | EndGlobalSection 61 | GlobalSection(ExtensibilityGlobals) = postSolution 62 | SolutionGuid = {2AFEF04D-34B1-4B23-BDE3-5A2C6825F727} 63 | EndGlobalSection 64 | EndGlobal 65 | -------------------------------------------------------------------------------- /BigBook/AsyncHelper.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 James Craig 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | using System; 18 | using System.Threading; 19 | using System.Threading.Tasks; 20 | 21 | namespace BigBook 22 | { 23 | /// 24 | /// Async helper. 25 | /// 26 | public static class AsyncHelper 27 | { 28 | /// 29 | /// The task factory 30 | /// 31 | private static readonly TaskFactory TaskFactory = new TaskFactory(CancellationToken.None, TaskCreationOptions.None, TaskContinuationOptions.None, TaskScheduler.Default); 32 | 33 | /// 34 | /// Runs the Func synchronously. 35 | /// 36 | /// The type of the result. 37 | /// The function. 38 | /// The result. 39 | public static TResult RunSync(Func> func) 40 | { 41 | if (func is null) 42 | return default; 43 | return TaskFactory.StartNew(func).Unwrap().GetAwaiter().GetResult(); 44 | } 45 | 46 | /// 47 | /// Runs the synchronously. 48 | /// 49 | /// The function. 50 | public static void RunSync(this Func func) 51 | { 52 | if (func is null) 53 | return; 54 | TaskFactory.StartNew(func).Unwrap().GetAwaiter().GetResult(); 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /BigBook/CanisterModules/BigBookModule.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 James Craig 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | using BigBook.Registration; 18 | using Canister.Interfaces; 19 | using Microsoft.Extensions.DependencyInjection; 20 | 21 | namespace BigBook.CanisterModules 22 | { 23 | /// 24 | /// Big book module 25 | /// 26 | /// 27 | public class BigBookModule : IModule 28 | { 29 | /// 30 | /// Order to run it in 31 | /// 32 | public int Order { get; } = 1; 33 | 34 | /// 35 | /// Loads the module 36 | /// 37 | /// Bootstrapper to register with 38 | public void Load(IServiceCollection? bootstrapper) => bootstrapper?.RegisterBigBookOfDataTypes(); 39 | } 40 | } -------------------------------------------------------------------------------- /BigBook/Comparison/GenericComparer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 James Craig 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | using System; 18 | using System.Collections.Generic; 19 | 20 | namespace BigBook.Comparison 21 | { 22 | /// 23 | /// Generic IComparable class 24 | /// 25 | /// Data type 26 | public class GenericComparer : IComparer where TData : IComparable 27 | { 28 | /// 29 | /// Gets the comparer. 30 | /// 31 | /// The comparer. 32 | public static GenericComparer Comparer { get; } = new GenericComparer(); 33 | 34 | /// 35 | /// Compares the two objects 36 | /// 37 | /// Object 1 38 | /// Object 2 39 | /// 0 if they're equal, any other value they are not 40 | public int Compare(TData x, TData y) 41 | { 42 | var TypeInfo = typeof(TData); 43 | if (!TypeInfo.IsValueType 44 | || (TypeInfo.IsGenericType 45 | && TypeInfo.GetGenericTypeDefinition().IsAssignableFrom(typeof(Nullable<>)))) 46 | { 47 | if (Equals(x, default(TData)!)) 48 | { 49 | return Equals(y, default(TData)!) ? 0 : -1; 50 | } 51 | 52 | if (Equals(y, default(TData)!)) 53 | { 54 | return -1; 55 | } 56 | } 57 | if (x.GetType() != y.GetType()) 58 | { 59 | return -1; 60 | } 61 | 62 | if (x is IComparable TempComparable) 63 | { 64 | return TempComparable.CompareTo(y); 65 | } 66 | 67 | return x.CompareTo(y); 68 | } 69 | } 70 | } -------------------------------------------------------------------------------- /BigBook/Comparison/GenericEqualityComparer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 James Craig 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | using System; 18 | using System.Collections; 19 | using System.Collections.Generic; 20 | 21 | namespace BigBook.Comparison 22 | { 23 | /// 24 | /// Generic equality comparer 25 | /// 26 | /// Data type 27 | public class GenericEqualityComparer : IEqualityComparer 28 | { 29 | /// 30 | /// Gets the comparer. 31 | /// 32 | /// The comparer. 33 | public static GenericEqualityComparer Comparer { get; } = new GenericEqualityComparer(); 34 | 35 | /// 36 | /// Determines if the two items are equal 37 | /// 38 | /// Object 1 39 | /// Object 2 40 | /// True if they are, false otherwise 41 | public bool Equals(TData x, TData y) 42 | { 43 | var TypeInfo = typeof(TData); 44 | if (!TypeInfo.IsValueType 45 | || (TypeInfo.IsGenericType 46 | && TypeInfo.GetGenericTypeDefinition().IsAssignableFrom(typeof(Nullable<>)))) 47 | { 48 | if (object.Equals(x, default(TData)!)) 49 | { 50 | return object.Equals(y, default(TData)!); 51 | } 52 | 53 | if (object.Equals(y, default(TData)!)) 54 | { 55 | return false; 56 | } 57 | } 58 | if (x?.GetType() != y?.GetType()) 59 | { 60 | return false; 61 | } 62 | 63 | if (x is IEnumerable IEnumerablex && y is IEnumerable IEnumerabley) 64 | { 65 | var Comparer = GenericEqualityComparer.Comparer; 66 | var XEnumerator = IEnumerablex.GetEnumerator(); 67 | var YEnumerator = IEnumerabley.GetEnumerator(); 68 | while (true) 69 | { 70 | var XFinished = !XEnumerator.MoveNext(); 71 | var YFinished = !YEnumerator.MoveNext(); 72 | if (XFinished || YFinished) 73 | { 74 | return XFinished && YFinished; 75 | } 76 | 77 | if (!Comparer.Equals(XEnumerator.Current, YEnumerator.Current)) 78 | { 79 | return false; 80 | } 81 | } 82 | } 83 | if (x is IEqualityComparer TempEquality) 84 | { 85 | return TempEquality.Equals(y); 86 | } 87 | 88 | if (x is IComparable TempComparable) 89 | { 90 | return TempComparable.CompareTo(y) == 0; 91 | } 92 | 93 | if (x is IComparable TempComparable2) 94 | { 95 | return TempComparable2.CompareTo(y) == 0; 96 | } 97 | 98 | return x?.Equals(y) ?? false; 99 | } 100 | 101 | /// 102 | /// Get hash code 103 | /// 104 | /// Object to get the hash code of 105 | /// The object's hash code 106 | public int GetHashCode(TData obj) => obj?.GetHashCode() ?? -1; 107 | } 108 | } -------------------------------------------------------------------------------- /BigBook/Comparison/SimpleComparer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 James Craig 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | using System; 18 | using System.Collections.Generic; 19 | 20 | namespace BigBook.Comparison 21 | { 22 | /// 23 | /// Simple IComparable class 24 | /// 25 | /// Data type 26 | public class SimpleComparer : IComparer where TData : IComparable 27 | { 28 | /// 29 | /// Initializes a new instance of the class. 30 | /// 31 | /// The comparison function. 32 | public SimpleComparer(Func comparisonFunction) 33 | { 34 | ComparisonFunction = comparisonFunction; 35 | } 36 | 37 | /// 38 | /// Gets or sets the comparison function. 39 | /// 40 | /// The comparison function. 41 | protected Func ComparisonFunction { get; set; } 42 | 43 | /// 44 | /// Compares the two objects 45 | /// 46 | /// Object 1 47 | /// Object 2 48 | /// 0 if they're equal, any other value they are not 49 | public int Compare(TData x, TData y) => ComparisonFunction(x, y); 50 | } 51 | } -------------------------------------------------------------------------------- /BigBook/Comparison/SimpleEqualityComparer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 James Craig 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | using System; 18 | using System.Collections.Generic; 19 | 20 | namespace BigBook.Comparison 21 | { 22 | /// 23 | /// Simple equality comparer 24 | /// 25 | /// Data type 26 | public class SimpleEqualityComparer : IEqualityComparer 27 | { 28 | /// 29 | /// Initializes a new instance of the class. 30 | /// 31 | /// The comparison function. 32 | /// The hash function. 33 | public SimpleEqualityComparer(Func comparisonFunction, Func hashFunction) 34 | { 35 | ComparisonFunction = comparisonFunction; 36 | HashFunction = hashFunction; 37 | } 38 | 39 | /// 40 | /// Gets or sets the comparison function. 41 | /// 42 | /// The comparison function. 43 | protected Func ComparisonFunction { get; set; } 44 | 45 | /// 46 | /// Gets or sets the hash function. 47 | /// 48 | /// The hash function. 49 | protected Func HashFunction { get; set; } 50 | 51 | /// 52 | /// Determines if the two items are equal 53 | /// 54 | /// Object 1 55 | /// Object 2 56 | /// True if they are, false otherwise 57 | public bool Equals(TData x, TData y) => ComparisonFunction(x, y); 58 | 59 | /// 60 | /// Get hash code 61 | /// 62 | /// Object to get the hash code of 63 | /// The object's hash code 64 | public int GetHashCode(TData obj) => HashFunction(obj); 65 | } 66 | } -------------------------------------------------------------------------------- /BigBook/DynamoUtils/Change.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 James Craig 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | using System; 18 | using System.Collections.Generic; 19 | 20 | namespace BigBook 21 | { 22 | /// 23 | /// Change class 24 | /// 25 | /// 26 | public struct Change : IEquatable 27 | { 28 | /// 29 | /// Constructor 30 | /// 31 | /// Original value 32 | /// New value 33 | public Change(object? originalValue, object? newValue) 34 | { 35 | OriginalValue = originalValue; 36 | NewValue = newValue; 37 | } 38 | 39 | /// 40 | /// New value 41 | /// 42 | public object? NewValue { get; } 43 | 44 | /// 45 | /// Original value 46 | /// 47 | public object? OriginalValue { get; } 48 | 49 | /// 50 | /// Implements the operator !=. 51 | /// 52 | /// The left. 53 | /// The right. 54 | /// The result of the operator. 55 | public static bool operator !=(Change left, Change right) 56 | { 57 | return !(left == right); 58 | } 59 | 60 | /// 61 | /// Implements the operator ==. 62 | /// 63 | /// The left. 64 | /// The right. 65 | /// The result of the operator. 66 | public static bool operator ==(Change left, Change right) 67 | { 68 | return left.Equals(right); 69 | } 70 | 71 | /// 72 | /// Indicates whether this instance and a specified object are equal. 73 | /// 74 | /// The object to compare with the current instance. 75 | /// 76 | /// if and this instance are the same type and 77 | /// represent the same value; otherwise, . 78 | /// 79 | public override bool Equals(object? obj) => obj is Change change && Equals(change); 80 | 81 | /// 82 | /// Indicates whether the current object is equal to another object of the same type. 83 | /// 84 | /// An object to compare with this object. 85 | /// 86 | /// if the current object is equal to the 87 | /// parameter; otherwise, . 88 | /// 89 | public bool Equals(Change other) 90 | { 91 | return EqualityComparer.Default.Equals(NewValue, other.NewValue) 92 | && EqualityComparer.Default.Equals(OriginalValue, other.OriginalValue); 93 | } 94 | 95 | /// 96 | /// Returns a hash code for this instance. 97 | /// 98 | /// 99 | /// A hash code for this instance, suitable for use in hashing algorithms and data 100 | /// structures like a hash table. 101 | /// 102 | public override int GetHashCode() => HashCode.Combine(NewValue, OriginalValue); 103 | } 104 | } -------------------------------------------------------------------------------- /BigBook/DynamoUtils/DynamoTypes.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 James Craig 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | using BigBook.DynamoUtils.Interfaces; 18 | using System.Collections.Generic; 19 | 20 | namespace BigBook.DynamoUtils 21 | { 22 | /// 23 | /// Dynamo type information 24 | /// 25 | internal class DynamoTypes 26 | { 27 | /// 28 | /// Initializes a new instance of the class. 29 | /// 30 | public DynamoTypes() 31 | { 32 | Types = new Dictionary(); 33 | LockObject = new object(); 34 | } 35 | 36 | /// 37 | /// The lock object 38 | /// 39 | private readonly object LockObject; 40 | 41 | /// 42 | /// Gets or sets the types. 43 | /// 44 | /// The types. 45 | private Dictionary Types { get; } 46 | 47 | /// 48 | /// Setups the type. 49 | /// 50 | /// The @object. 51 | public void SetupType(Dynamo @object) 52 | { 53 | var objectType = @object.GetType(); 54 | var Key = objectType.GetHashCode(); 55 | if (Types.ContainsKey(Key) || objectType == typeof(Dynamo)) 56 | return; 57 | lock (LockObject) 58 | { 59 | var TempObject = (typeof(DynamoProperties<>).MakeGenericType(objectType).Create() as IDynamoProperties)!; 60 | TempObject.SetupValues(); 61 | Types.Add(Key, TempObject); 62 | } 63 | } 64 | 65 | /// 66 | /// Tries the get value. 67 | /// 68 | /// The object. 69 | /// Name of the property. 70 | /// The value. 71 | /// True if the value is returned, false otherwise. 72 | public bool TryGetValue(Dynamo @object, string propertyName, out object? value) 73 | { 74 | var objectType = @object.GetType(); 75 | var Key = objectType.GetHashCode(); 76 | if (!Types.ContainsKey(Key)) 77 | { 78 | value = null; 79 | return false; 80 | } 81 | var ReturnValue = Types[Key].TryGetValue(@object, propertyName, out var TempValue); 82 | value = TempValue; 83 | return ReturnValue; 84 | } 85 | 86 | /// 87 | /// Tries the set value. 88 | /// 89 | /// The object. 90 | /// Name of the property. 91 | /// The value. 92 | /// The old value. 93 | /// True if it is set, false otherwise. 94 | public bool TrySetValue(Dynamo @object, string propertyName, object? value, out object? oldValue) 95 | { 96 | var objectType = @object.GetType(); 97 | var Key = objectType.GetHashCode(); 98 | if (!Types.ContainsKey(Key)) 99 | { 100 | oldValue = null; 101 | return false; 102 | } 103 | var ReturnValue = Types[Key].TrySetValue(@object, propertyName, value, out var TempValue); 104 | oldValue = TempValue; 105 | return ReturnValue; 106 | } 107 | } 108 | } -------------------------------------------------------------------------------- /BigBook/DynamoUtils/Interfaces/IDynamoProperties.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 James Craig 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | namespace BigBook.DynamoUtils.Interfaces 18 | { 19 | /// 20 | /// Dynamo alt properties interface 21 | /// 22 | internal interface IDynamoProperties 23 | { 24 | /// 25 | /// Setups the values. 26 | /// 27 | void SetupValues(); 28 | 29 | /// 30 | /// Tries the get value. 31 | /// 32 | /// The object. 33 | /// Name of the property. 34 | /// The value. 35 | /// True if the value is returned, false otherwise. 36 | bool TryGetValue(Dynamo @object, string propertyName, out object? value); 37 | 38 | /// 39 | /// Tries the set value. 40 | /// 41 | /// The object. 42 | /// Name of the property. 43 | /// The value. 44 | /// The old value. 45 | /// True if it is set, false otherwise. 46 | bool TrySetValue(Dynamo @object, string propertyName, object? value, out object? oldValue); 47 | } 48 | } -------------------------------------------------------------------------------- /BigBook/EventArgs/EventArgs.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 James Craig 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | namespace BigBook.EventArgs 18 | { 19 | /// 20 | /// Base event args for the events used in the system 21 | /// 22 | public class BaseEventArgs : System.EventArgs 23 | { 24 | /// 25 | /// Content of the event 26 | /// 27 | public object? Content { get; set; } 28 | 29 | /// 30 | /// Should the event be stopped? 31 | /// 32 | public bool Stop { get; set; } 33 | } 34 | 35 | /// 36 | /// Changed event args 37 | /// 38 | public class ChangedEventArgs : BaseEventArgs 39 | { 40 | } 41 | 42 | /// 43 | /// Deleted event args 44 | /// 45 | public class DeletedEventArgs : BaseEventArgs 46 | { 47 | } 48 | 49 | /// 50 | /// Deleting event args 51 | /// 52 | public class DeletingEventArgs : BaseEventArgs 53 | { 54 | } 55 | 56 | /// 57 | /// Loaded event args 58 | /// 59 | public class LoadedEventArgs : BaseEventArgs 60 | { 61 | } 62 | 63 | /// 64 | /// Loading event args 65 | /// 66 | public class LoadingEventArgs : BaseEventArgs 67 | { 68 | } 69 | 70 | /// 71 | /// On end event args 72 | /// 73 | public class OnEndEventArgs : BaseEventArgs 74 | { 75 | } 76 | 77 | /// 78 | /// On error event args 79 | /// 80 | public class OnErrorEventArgs : BaseEventArgs 81 | { 82 | } 83 | 84 | /// 85 | /// On start event args 86 | /// 87 | public class OnStartEventArgs : BaseEventArgs 88 | { 89 | } 90 | 91 | /// 92 | /// Saved event args 93 | /// 94 | public class SavedEventArgs : BaseEventArgs 95 | { 96 | } 97 | 98 | /// 99 | /// Saving event args 100 | /// 101 | public class SavingEventArgs : BaseEventArgs 102 | { 103 | } 104 | } -------------------------------------------------------------------------------- /BigBook/ExtensionMethods/ArrayExtensions.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 James Craig 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | using System; 18 | using System.ComponentModel; 19 | using System.Linq; 20 | 21 | namespace BigBook 22 | { 23 | /// 24 | /// Array extensions 25 | /// 26 | [EditorBrowsable(EditorBrowsableState.Never)] 27 | public static class ArrayExtensions 28 | { 29 | /// 30 | /// Clears the array completely 31 | /// 32 | /// Array to clear 33 | /// The final array 34 | public static Array? Clear(this Array array) 35 | { 36 | if (array is null) 37 | return null; 38 | 39 | Array.Clear(array, 0, array.Length); 40 | return array; 41 | } 42 | 43 | /// 44 | /// Clears the array completely 45 | /// 46 | /// Array type 47 | /// Array to clear 48 | /// The final array 49 | public static TArrayType[]? Clear(this TArrayType[] array) 50 | { 51 | if (array is null) 52 | { 53 | return null; 54 | } 55 | 56 | Array.Clear(array, 0, array.Length); 57 | return array; 58 | } 59 | 60 | /// 61 | /// Combines two arrays and returns a new array containing both values 62 | /// 63 | /// Type of the data in the array 64 | /// Array 1 65 | /// Arrays to concat onto the first item 66 | /// A new array containing both arrays' values 67 | public static TArrayType[] Concat(this TArrayType[] array1, params TArrayType[][] additions) 68 | { 69 | array1 ??= Array.Empty(); 70 | additions ??= Array.Empty(); 71 | var Result = new TArrayType[array1.Length + additions.Sum(x => x?.Length ?? 0)]; 72 | var Offset = array1.Length; 73 | Array.Copy(array1, 0, Result, 0, array1.Length); 74 | for (int x = 0; x < additions.Length; ++x) 75 | { 76 | var item = additions[x]; 77 | if (item is null) 78 | continue; 79 | Array.Copy(item, 0, Result, Offset, item.Length); 80 | Offset += item.Length; 81 | } 82 | return Result; 83 | } 84 | } 85 | } -------------------------------------------------------------------------------- /BigBook/ExtensionMethods/ConcurrentDictionaryExtensions.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 James Craig 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | using System.Collections.Concurrent; 18 | using System.ComponentModel; 19 | 20 | namespace BigBook 21 | { 22 | /// 23 | /// ConcurrentDictionary extensions 24 | /// 25 | [EditorBrowsable(EditorBrowsableState.Never)] 26 | public static class ConcurrentDictionaryExtensions 27 | { 28 | /// 29 | /// Copies the dictionary to another dictionary. 30 | /// 31 | /// The type of the key. 32 | /// The type of the value. 33 | /// The dictionary. 34 | /// The target dictionary. 35 | /// This 36 | public static ConcurrentDictionary CopyTo(this ConcurrentDictionary dictionary, ConcurrentDictionary target) 37 | { 38 | dictionary ??= new ConcurrentDictionary(); 39 | if (target is null) 40 | return dictionary; 41 | foreach (var x in dictionary) 42 | { 43 | target.SetValue(x.Key, x.Value); 44 | } 45 | return dictionary; 46 | } 47 | 48 | /// 49 | /// Gets the value from a dictionary or the default value if it isn't found 50 | /// 51 | /// Key type 52 | /// Value type 53 | /// Dictionary to get the value from 54 | /// Key to look for 55 | /// Default value if the key is not found 56 | /// 57 | /// The value associated with the key or the default value if the key is not found 58 | /// 59 | public static TValue GetValue(this ConcurrentDictionary dictionary, TKey key, TValue defaultValue = default) 60 | { 61 | if (dictionary is null || key is null) 62 | { 63 | return defaultValue; 64 | } 65 | 66 | return dictionary.TryGetValue(key, out var ReturnValue) ? ReturnValue : defaultValue; 67 | } 68 | 69 | /// 70 | /// Sets the value in a dictionary 71 | /// 72 | /// Key type 73 | /// Value type 74 | /// Dictionary to set the value in 75 | /// Key to look for 76 | /// Value to add 77 | /// The dictionary 78 | public static ConcurrentDictionary SetValue(this ConcurrentDictionary dictionary, TKey key, TValue value) 79 | { 80 | if (dictionary is null || key is null) 81 | { 82 | return new ConcurrentDictionary(); 83 | } 84 | 85 | dictionary.AddOrUpdate(key, value, (_, __) => value); 86 | return dictionary; 87 | } 88 | } 89 | } -------------------------------------------------------------------------------- /BigBook/ExtensionMethods/ExceptionExtensions.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 James Craig 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | using System; 18 | using System.ComponentModel; 19 | using System.Text; 20 | 21 | namespace BigBook 22 | { 23 | /// 24 | /// Class for housing exception specific extensions 25 | /// 26 | [EditorBrowsable(EditorBrowsableState.Never)] 27 | public static class ExceptionExtensions 28 | { 29 | /// 30 | /// Converts the exception to a string and appends the specified prefix/suffix (used for logging) 31 | /// 32 | /// Exception to convert 33 | /// Prefix 34 | /// Suffix 35 | /// The exception as a string 36 | public static string ToString(this Exception exception, string prefix, string suffix = "") 37 | { 38 | if (exception is null) 39 | { 40 | return string.Empty; 41 | } 42 | 43 | var Builder = new StringBuilder(); 44 | Builder.AppendLine(prefix); 45 | Builder.AppendLineFormat("Exception: {0}", exception.Message) 46 | .AppendLineFormat("Exception Type: {0}", exception.GetType().FullName); 47 | if (!(exception.Data is null)) 48 | { 49 | for (int x = 0, exceptionDataCount = exception.Data.Count; x < exceptionDataCount; x++) 50 | { 51 | var Object = exception.Data[x]; 52 | Builder.AppendLineFormat("Data: {0}:{1}", Object, exception.Data[Object]); 53 | } 54 | } 55 | Builder.AppendLineFormat("StackTrace: {0}", exception.StackTrace) 56 | .AppendLineFormat("Source: {0}", exception.Source); 57 | if (!(exception.InnerException is null)) 58 | { 59 | Builder.Append(exception.InnerException.ToString(prefix, suffix)); 60 | } 61 | 62 | Builder.AppendLine(suffix); 63 | return Builder.ToString(); 64 | } 65 | } 66 | } -------------------------------------------------------------------------------- /BigBook/ExtensionMethods/IComparableExtensions.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 James Craig 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | using BigBook.Comparison; 18 | using System; 19 | using System.Collections.Generic; 20 | using System.ComponentModel; 21 | 22 | namespace BigBook 23 | { 24 | /// 25 | /// IComparable extensions 26 | /// 27 | [EditorBrowsable(EditorBrowsableState.Never)] 28 | public static class IComparableExtensions 29 | { 30 | /// 31 | /// Checks if an item is between two values 32 | /// 33 | /// Type of the value 34 | /// Value to check 35 | /// Minimum value 36 | /// Maximum value 37 | /// Comparer used to compare the values (defaults to GenericComparer)" 38 | /// True if it is between the values, false otherwise 39 | public static bool Between(this T value, T min, T max, IComparer? comparer = null) 40 | where T : IComparable 41 | { 42 | comparer ??= GenericComparer.Comparer; 43 | return comparer.Compare(max, value) >= 0 && comparer.Compare(value, min) >= 0; 44 | } 45 | 46 | /// 47 | /// Clamps a value between two values 48 | /// 49 | /// 50 | /// Value sent in 51 | /// Max value it can be (inclusive) 52 | /// Min value it can be (inclusive) 53 | /// Comparer to use (defaults to GenericComparer) 54 | /// The value set between Min and Max 55 | public static T Clamp(this T value, T max, T min, IComparer? comparer = null) 56 | where T : IComparable 57 | { 58 | comparer ??= GenericComparer.Comparer; 59 | if (comparer.Compare(max, value) < 0) 60 | { 61 | return max; 62 | } 63 | 64 | if (comparer.Compare(value, min) < 0) 65 | { 66 | return min; 67 | } 68 | 69 | return value; 70 | } 71 | 72 | /// 73 | /// Returns the maximum value between the two 74 | /// 75 | /// 76 | /// Input A 77 | /// Input B 78 | /// Comparer to use (defaults to GenericComparer) 79 | /// The maximum value 80 | public static T Max(this T inputA, T inputB, IComparer? comparer = null) 81 | where T : IComparable 82 | { 83 | comparer ??= GenericComparer.Comparer; 84 | return comparer.Compare(inputA, inputB) < 0 ? inputB : inputA; 85 | } 86 | 87 | /// 88 | /// Returns the minimum value between the two 89 | /// 90 | /// 91 | /// Input A 92 | /// Input B 93 | /// Comparer to use (defaults to GenericComparer) 94 | /// The minimum value 95 | public static T Min(this T inputA, T inputB, IComparer? comparer = null) 96 | where T : IComparable 97 | { 98 | comparer ??= GenericComparer.Comparer; 99 | return comparer.Compare(inputA, inputB) > 0 ? inputB : inputA; 100 | } 101 | } 102 | } -------------------------------------------------------------------------------- /BigBook/ExtensionMethods/MatchCollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 James Craig 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | using System; 18 | using System.Collections.Generic; 19 | using System.ComponentModel; 20 | using System.Text.RegularExpressions; 21 | 22 | namespace BigBook 23 | { 24 | /// 25 | /// MatchCollection extensions 26 | /// 27 | [EditorBrowsable(EditorBrowsableState.Never)] 28 | public static class MatchCollectionExtensions 29 | { 30 | /// 31 | /// Gets a list of items that satisfy the predicate from the collection 32 | /// 33 | /// Collection to search through 34 | /// Predicate that the items must satisfy 35 | /// The matches that satisfy the predicate 36 | public static IEnumerable Where(this MatchCollection collection, Predicate predicate) 37 | { 38 | if (predicate is null || collection is null) 39 | { 40 | yield break; 41 | } 42 | 43 | for (int x = 0, collectionCount = collection.Count; x < collectionCount; x++) 44 | { 45 | var Item = collection[x]; 46 | if (predicate(Item)) 47 | { 48 | yield return Item; 49 | } 50 | } 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /BigBook/ExtensionMethods/PermutationExtensions.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 James Craig 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | using System.Collections.Generic; 18 | using System.ComponentModel; 19 | using System.Linq; 20 | 21 | namespace BigBook 22 | { 23 | /// 24 | /// Permutation extensions 25 | /// 26 | [EditorBrowsable(EditorBrowsableState.Never)] 27 | public static class PermutationExtensions 28 | { 29 | /// 30 | /// Finds all permutations of the items within the list 31 | /// 32 | /// Object type in the list 33 | /// Input list 34 | /// The list of permutations 35 | public static ListMapping Permute(this IEnumerable input) 36 | { 37 | if (input is null) 38 | { 39 | return new ListMapping(); 40 | } 41 | 42 | var Current = new List(); 43 | Current.AddRange(input); 44 | var ReturnValue = new ListMapping(); 45 | var Max = (input.Count() - 1).Factorial(); 46 | var CurrentValue = 0; 47 | for (var x = 0; x < input.Count(); ++x) 48 | { 49 | var z = 0; 50 | while (z < Max) 51 | { 52 | var y = input.Count() - 1; 53 | while (y > 1) 54 | { 55 | var TempHolder = Current[y - 1]; 56 | Current[y - 1] = Current[y]; 57 | Current[y] = TempHolder; 58 | --y; 59 | for (int i = 0, CurrentCount = Current.Count; i < CurrentCount; i++) 60 | { 61 | var Item = Current[i]; 62 | ReturnValue.Add(CurrentValue, Item); 63 | } 64 | 65 | ++z; 66 | ++CurrentValue; 67 | if (z == Max) 68 | { 69 | break; 70 | } 71 | } 72 | } 73 | if (x + 1 != input.Count()) 74 | { 75 | Current.Clear(); 76 | Current.AddRange(input); 77 | var TempHolder2 = Current[0]; 78 | Current[0] = Current[x + 1]; 79 | Current[x + 1] = TempHolder2; 80 | } 81 | } 82 | return ReturnValue; 83 | } 84 | } 85 | } -------------------------------------------------------------------------------- /BigBook/ExtensionMethods/StackTraceExtensions.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 James Craig 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | using System; 18 | using System.Collections.Generic; 19 | using System.ComponentModel; 20 | using System.Diagnostics; 21 | using System.Linq; 22 | using System.Reflection; 23 | 24 | namespace BigBook 25 | { 26 | /// 27 | /// Extension methods related to the stack trace 28 | /// 29 | [EditorBrowsable(EditorBrowsableState.Never)] 30 | public static class StackTraceExtensions 31 | { 32 | /// 33 | /// Gets the methods involved in the stack trace 34 | /// 35 | /// Stack trace to get methods from 36 | /// Excludes methods from the specified assemblies 37 | /// A list of methods involved in the stack trace 38 | public static IEnumerable GetMethods(this StackTrace stack, params Assembly[] excludedAssemblies) 39 | { 40 | if (stack is null) 41 | { 42 | return Array.Empty(); 43 | } 44 | 45 | excludedAssemblies ??= Array.Empty(); 46 | return stack.GetFrames().GetMethods(excludedAssemblies); 47 | } 48 | 49 | /// 50 | /// Gets the methods involved in the individual frames 51 | /// 52 | /// Frames to get the methods from 53 | /// Excludes methods from the specified assemblies 54 | /// The list of methods involved 55 | public static IEnumerable GetMethods(this IEnumerable frames, params Assembly[] excludedAssemblies) 56 | { 57 | if (frames is null) 58 | { 59 | return Array.Empty(); 60 | } 61 | var Methods = new List(); 62 | 63 | foreach (var Frame in frames) 64 | { 65 | Methods.AddIf(x => !(x.DeclaringType is null) 66 | && !excludedAssemblies.Contains(x.DeclaringType.Assembly) 67 | && !x.DeclaringType.Assembly.FullName.StartsWith("System", StringComparison.Ordinal) 68 | && !x.DeclaringType.Assembly.FullName.StartsWith("mscorlib", StringComparison.Ordinal) 69 | && !x.DeclaringType.Assembly.FullName.StartsWith("WebDev.WebHost40", StringComparison.Ordinal), 70 | Frame.GetMethod()); 71 | } 72 | return Methods; 73 | } 74 | } 75 | } -------------------------------------------------------------------------------- /BigBook/ExtensionMethods/TaskExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel; 3 | using System.Threading.Tasks; 4 | 5 | namespace BigBook 6 | { 7 | /// 8 | /// Task extension methods 9 | /// 10 | [EditorBrowsable(EditorBrowsableState.Never)] 11 | public static class TaskExtensions 12 | { 13 | /// 14 | /// Runs the Func synchronously. 15 | /// 16 | /// The type of the result. 17 | /// The function. 18 | /// The result. 19 | public static TResult RunSync(this Func> func) => AsyncHelper.RunSync(func); 20 | 21 | /// 22 | /// Runs the synchronously. 23 | /// 24 | /// The function. 25 | public static void RunSync(this Func func) => AsyncHelper.RunSync(func); 26 | } 27 | } -------------------------------------------------------------------------------- /BigBook/ExtensionMethods/TimeSpanExtensions.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 James Craig 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | using System; 18 | using System.Collections.Generic; 19 | using System.ComponentModel; 20 | using System.Linq; 21 | 22 | namespace BigBook 23 | { 24 | /// 25 | /// TimeSpan extension methods 26 | /// 27 | [EditorBrowsable(EditorBrowsableState.Never)] 28 | public static class TimeSpanExtensions 29 | { 30 | /// 31 | /// Averages a list of TimeSpans 32 | /// 33 | /// List of TimeSpans 34 | /// The average value 35 | public static TimeSpan Average(this IEnumerable list) 36 | { 37 | list ??= Array.Empty(); 38 | return list.Any() ? new TimeSpan((long)list.Average(x => x.Ticks)) : new TimeSpan(0); 39 | } 40 | 41 | /// 42 | /// Days in the TimeSpan minus the months and years 43 | /// 44 | /// TimeSpan to get the days from 45 | /// The number of days minus the months and years that the TimeSpan has 46 | public static int DaysRemainder(this TimeSpan span) => (DateTime.MinValue + span).Day - 1; 47 | 48 | /// 49 | /// Months in the TimeSpan 50 | /// 51 | /// TimeSpan to get the months from 52 | /// The number of months that the TimeSpan has 53 | public static int Months(this TimeSpan span) => (DateTime.MinValue + span).Month - 1; 54 | 55 | /// 56 | /// Converts the input to a string in this format: (Years) years, (Months) months, 57 | /// (DaysRemainder) days, (Hours) hours, (Minutes) minutes, (Seconds) seconds 58 | /// 59 | /// input TimeSpan 60 | /// The TimeSpan as a string 61 | public static string ToStringFull(this TimeSpan input) 62 | { 63 | var Result = ""; 64 | var Splitter = ""; 65 | if (input.Years() > 0) 66 | { Result += input.Years() + " year" + (input.Years() > 1 ? "s" : ""); Splitter = ", "; } 67 | if (input.Months() > 0) 68 | { Result += Splitter + input.Months() + " month" + (input.Months() > 1 ? "s" : ""); Splitter = ", "; } 69 | if (input.DaysRemainder() > 0) 70 | { Result += Splitter + input.DaysRemainder() + " day" + (input.DaysRemainder() > 1 ? "s" : ""); Splitter = ", "; } 71 | if (input.Hours > 0) 72 | { Result += Splitter + input.Hours + " hour" + (input.Hours > 1 ? "s" : ""); Splitter = ", "; } 73 | if (input.Minutes > 0) 74 | { Result += Splitter + input.Minutes + " minute" + (input.Minutes > 1 ? "s" : ""); Splitter = ", "; } 75 | if (input.Seconds > 0) 76 | { 77 | Result += Splitter + input.Seconds + " second" + (input.Seconds > 1 ? "s" : ""); 78 | } 79 | return Result; 80 | } 81 | 82 | /// 83 | /// Years in the TimeSpan 84 | /// 85 | /// TimeSpan to get the years from 86 | /// The number of years that the TimeSpan has 87 | public static int Years(this TimeSpan span) => (DateTime.MinValue + span).Year - 1; 88 | } 89 | } -------------------------------------------------------------------------------- /BigBook/ExtensionMethods/Utils/DefaultValueLookup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace BigBook.ExtensionMethods.Utils 5 | { 6 | /// 7 | /// Default value lookup 8 | /// 9 | public static class DefaultValueLookup 10 | { 11 | /// 12 | /// The values 13 | /// 14 | public static Dictionary Values = new Dictionary 15 | { 16 | [typeof(byte).GetHashCode()] = default(byte), 17 | [typeof(sbyte).GetHashCode()] = default(sbyte), 18 | [typeof(short).GetHashCode()] = default(short), 19 | [typeof(int).GetHashCode()] = default(int), 20 | [typeof(long).GetHashCode()] = default(long), 21 | [typeof(ushort).GetHashCode()] = default(ushort), 22 | [typeof(uint).GetHashCode()] = default(uint), 23 | [typeof(ulong).GetHashCode()] = default(ulong), 24 | [typeof(double).GetHashCode()] = default(double), 25 | [typeof(float).GetHashCode()] = default(float), 26 | [typeof(decimal).GetHashCode()] = default(decimal), 27 | [typeof(bool).GetHashCode()] = default(bool), 28 | [typeof(char).GetHashCode()] = default(char), 29 | 30 | [typeof(byte?).GetHashCode()] = default(byte?), 31 | [typeof(sbyte?).GetHashCode()] = default(sbyte?), 32 | [typeof(short?).GetHashCode()] = default(short?), 33 | [typeof(int?).GetHashCode()] = default(int?), 34 | [typeof(long?).GetHashCode()] = default(long?), 35 | [typeof(ushort?).GetHashCode()] = default(ushort?), 36 | [typeof(uint?).GetHashCode()] = default(uint?), 37 | [typeof(ulong?).GetHashCode()] = default(ulong?), 38 | [typeof(double?).GetHashCode()] = default(double?), 39 | [typeof(float?).GetHashCode()] = default(float?), 40 | [typeof(decimal?).GetHashCode()] = default(decimal?), 41 | [typeof(bool?).GetHashCode()] = default(bool?), 42 | [typeof(char?).GetHashCode()] = default(char?), 43 | 44 | [typeof(string).GetHashCode()] = default(string), 45 | [typeof(Guid).GetHashCode()] = default(Guid), 46 | [typeof(DateTime).GetHashCode()] = default(DateTime), 47 | [typeof(DateTimeOffset).GetHashCode()] = default(DateTimeOffset), 48 | [typeof(TimeSpan).GetHashCode()] = default(TimeSpan), 49 | [typeof(Guid?).GetHashCode()] = default(Guid?), 50 | [typeof(DateTime?).GetHashCode()] = default(DateTime?), 51 | [typeof(DateTimeOffset?).GetHashCode()] = default(DateTimeOffset?), 52 | [typeof(TimeSpan?).GetHashCode()] = default(TimeSpan?), 53 | [typeof(byte[]).GetHashCode()] = default(byte[]), 54 | }; 55 | } 56 | } -------------------------------------------------------------------------------- /BigBook/Formatters/Interfaces/IStringFormatter.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 James Craig 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | namespace BigBook.Formatters.Interfaces 18 | { 19 | /// 20 | /// String formatter 21 | /// 22 | public interface IStringFormatter 23 | { 24 | /// 25 | /// Formats the string based on the pattern 26 | /// 27 | /// Input string 28 | /// Format pattern 29 | /// The formatted string 30 | string Format(string? input, string formatPattern); 31 | } 32 | } -------------------------------------------------------------------------------- /BigBook/GlobalSuppressions.cs: -------------------------------------------------------------------------------- 1 | // This file is used by Code Analysis to maintain SuppressMessage 2 | // attributes that are applied to this project. 3 | // Project-level suppressions either have no target or are given 4 | // a specific target and scoped to a namespace, type, member, etc. 5 | 6 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "", Scope = "member", Target = "~M:BigBook.Dynamo.GetSchema~System.Xml.Schema.XmlSchema")] 7 | 8 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2211:Non-constant fields should not be visible", Justification = "", Scope = "member", Target = "~F:BigBook.ExtensionMethods.Utils.DefaultValueLookup.Values")] -------------------------------------------------------------------------------- /BigBook/IO/Converters/BigEndianBitConverter.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 James Craig 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | using BigBook.IO.Converters.BaseClasses; 18 | 19 | namespace BigBook.IO.Converters 20 | { 21 | /// 22 | /// Big endian bit converter 23 | /// 24 | /// 25 | public class BigEndianBitConverter : EndianBitConverterBase 26 | { 27 | /// 28 | /// Gets a value indicating whether this instance is little endian. 29 | /// 30 | /// true if this instance is little endian; otherwise, false. 31 | public override bool IsLittleEndian { get; } 32 | 33 | /// 34 | /// Copies the bytes implementation. 35 | /// 36 | /// The value. 37 | /// The bytes. 38 | /// The buffer. 39 | /// The index. 40 | protected override void CopyBytesImpl(long value, int bytes, byte[] buffer, int index) 41 | { 42 | if (buffer is null) 43 | return; 44 | var endOffset = index + bytes - 1; 45 | for (var i = 0; i < bytes; i++) 46 | { 47 | buffer[endOffset - i] = unchecked((byte)(value & 0xff)); 48 | value >>= 8; 49 | } 50 | } 51 | 52 | /// 53 | /// Converts a byte array to a long. 54 | /// 55 | /// The value. 56 | /// The start index. 57 | /// The bytes to convert. 58 | /// The resulting long. 59 | protected override long FromBytes(byte[] value, int startIndex, int bytesToConvert) 60 | { 61 | if (value is null) 62 | return 0; 63 | long ret = 0; 64 | for (var i = 0; i < bytesToConvert; i++) 65 | { 66 | ret = unchecked((ret << 8) | value[startIndex + i]); 67 | } 68 | 69 | return ret; 70 | } 71 | } 72 | } -------------------------------------------------------------------------------- /BigBook/IO/Converters/LittleEndianBitConverter.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 James Craig 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | using BigBook.IO.Converters.BaseClasses; 18 | 19 | namespace BigBook.IO.Converters 20 | { 21 | /// 22 | /// Little endian bit converter 23 | /// 24 | /// 25 | public class LittleEndianBitConverter : EndianBitConverterBase 26 | { 27 | /// 28 | /// Gets a value indicating whether this instance is little endian. 29 | /// 30 | /// true if this instance is little endian; otherwise, false. 31 | public override bool IsLittleEndian { get; } = true; 32 | 33 | /// 34 | /// Copies the bytes implementation. 35 | /// 36 | /// The value. 37 | /// The bytes. 38 | /// The buffer. 39 | /// The index. 40 | protected override void CopyBytesImpl(long value, int bytes, byte[] buffer, int index) 41 | { 42 | if (buffer is null) 43 | return; 44 | for (var i = 0; i < bytes; i++) 45 | { 46 | buffer[i + index] = unchecked((byte)(value & 0xff)); 47 | value >>= 8; 48 | } 49 | } 50 | 51 | /// 52 | /// Converts a byte array to a long. 53 | /// 54 | /// The value. 55 | /// The start index. 56 | /// The bytes to convert. 57 | /// The resulting long. 58 | protected override long FromBytes(byte[] value, int startIndex, int bytesToConvert) 59 | { 60 | if (value is null) 61 | return 0; 62 | long ret = 0; 63 | for (var i = 0; i < bytesToConvert; i++) 64 | { 65 | ret = unchecked((ret << 8) | value[startIndex + bytesToConvert - 1 - i]); 66 | } 67 | 68 | return ret; 69 | } 70 | } 71 | } -------------------------------------------------------------------------------- /BigBook/IO/Converters/Structs/IntFloatUnion.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 James Craig 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | using System; 18 | using System.Runtime.InteropServices; 19 | 20 | namespace BigBook.IO.Converters.Structs 21 | { 22 | /// 23 | /// Int/float union struct. 24 | /// 25 | [StructLayout(LayoutKind.Explicit)] 26 | public struct IntFloatUnion : IEquatable 27 | { 28 | /// 29 | /// The integer value 30 | /// 31 | [FieldOffset(0)] 32 | public readonly int IntegerValue; 33 | 34 | /// 35 | /// The float value 36 | /// 37 | [FieldOffset(0)] 38 | public readonly float FloatValue; 39 | 40 | /// 41 | /// Initializes a new instance of the struct. 42 | /// 43 | /// The integer value. 44 | public IntFloatUnion(int integerValue) 45 | { 46 | FloatValue = 0; 47 | IntegerValue = integerValue; 48 | } 49 | 50 | /// 51 | /// Initializes a new instance of the struct. 52 | /// 53 | /// The float value. 54 | public IntFloatUnion(float floatValue) 55 | { 56 | IntegerValue = 0; 57 | FloatValue = floatValue; 58 | } 59 | 60 | /// 61 | /// Determines whether the specified , is equal to this instance. 62 | /// 63 | /// The to compare with this instance. 64 | /// 65 | /// true if the specified is equal to this instance; 66 | /// otherwise, false. 67 | /// 68 | public override bool Equals(object obj) => obj is IntFloatUnion intFloatUnion && Equals(intFloatUnion); 69 | 70 | /// 71 | /// Indicates whether the current object is equal to another object of the same type. 72 | /// 73 | /// An object to compare with this object. 74 | /// 75 | /// true if the current object is equal to the other 76 | /// parameter; otherwise, false. 77 | /// 78 | public bool Equals(IntFloatUnion other) => IntegerValue == other.IntegerValue; 79 | 80 | /// 81 | /// Returns a hash code for this instance. 82 | /// 83 | /// 84 | /// A hash code for this instance, suitable for use in hashing algorithms and data 85 | /// structures like a hash table. 86 | /// 87 | public override int GetHashCode() => -1352667302 + IntegerValue.GetHashCode(); 88 | 89 | /// 90 | /// Implements the operator ==. 91 | /// 92 | /// The union1. 93 | /// The union2. 94 | /// The result of the operator. 95 | public static bool operator ==(IntFloatUnion union1, IntFloatUnion union2) 96 | { 97 | return union1.Equals(union2); 98 | } 99 | 100 | /// 101 | /// Implements the operator !=. 102 | /// 103 | /// The union1. 104 | /// The union2. 105 | /// The result of the operator. 106 | public static bool operator !=(IntFloatUnion union1, IntFloatUnion union2) 107 | { 108 | return !(union1 == union2); 109 | } 110 | } 111 | } -------------------------------------------------------------------------------- /BigBook/LazyAsync.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 James Craig 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | using System; 18 | using System.Runtime.CompilerServices; 19 | using System.Threading.Tasks; 20 | 21 | namespace BigBook 22 | { 23 | /// 24 | /// Lazy class that handles asyc 25 | /// 26 | /// The return type 27 | /// 28 | public class LazyAsync : Lazy> 29 | { 30 | /// 31 | /// Initializes a new instance of the class. 32 | /// 33 | /// The function. 34 | public LazyAsync(Func func) 35 | : base(() => Task.FromResult(func())) 36 | { 37 | } 38 | 39 | /// 40 | /// Initializes a new instance of the class. 41 | /// 42 | /// The function. 43 | public LazyAsync(Func> func) 44 | : base(func) 45 | { 46 | } 47 | 48 | /// 49 | /// Gets the awaiter. 50 | /// 51 | /// The awaiter. 52 | public TaskAwaiter GetAwaiter() 53 | { 54 | return Value.GetAwaiter(); 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /BigBook/Patterns/BaseClasses/SafeDisposableBaseClass.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 James Craig 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | using System; 18 | 19 | namespace BigBook.Patterns.BaseClasses 20 | { 21 | /// 22 | /// Base class used for disposable objects 23 | /// 24 | public abstract class SafeDisposableBaseClass : IDisposable 25 | { 26 | /// 27 | /// Construct 28 | /// 29 | protected SafeDisposableBaseClass() 30 | { 31 | } 32 | 33 | /// 34 | /// Dispose function 35 | /// 36 | public void Dispose() 37 | { 38 | Dispose(true); 39 | GC.SuppressFinalize(this); 40 | } 41 | 42 | /// 43 | /// Function to override in order to dispose objects 44 | /// 45 | /// 46 | /// If true, managed and unmanaged objects should be disposed. Otherwise unmanaged objects only. 47 | /// 48 | protected abstract void Dispose(bool Managed); 49 | 50 | /// 51 | /// Destructor 52 | /// 53 | ~SafeDisposableBaseClass() 54 | { 55 | Dispose(false); 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /BigBook/Patterns/BaseClasses/Singleton.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 James Craig 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | using System; 18 | 19 | namespace BigBook.Patterns.BaseClasses 20 | { 21 | /// 22 | /// Base class used for singletons 23 | /// 24 | /// The class type 25 | public abstract class Singleton 26 | where T : class 27 | { 28 | /// 29 | /// Constructor 30 | /// 31 | protected Singleton() 32 | { 33 | } 34 | 35 | /// 36 | /// Gets the instance of the singleton 37 | /// 38 | public static T Instance 39 | { 40 | get 41 | { 42 | if (_Instance is null) 43 | { 44 | lock (Temp) 45 | { 46 | if (_Instance is null) 47 | { 48 | var Constructor = Array.Find(typeof(T).GetConstructors(), x => !x.IsPublic 49 | && !x.IsStatic 50 | && x.GetParameters().Length == 0); 51 | if (Constructor?.IsAssembly != false) 52 | { 53 | throw new InvalidOperationException("Constructor is not private or protected for type " + typeof(T).Name); 54 | } 55 | 56 | _Instance = (T)Constructor.Invoke(null); 57 | } 58 | } 59 | } 60 | return _Instance; 61 | } 62 | } 63 | 64 | /// 65 | /// The temporary lock object 66 | /// 67 | private static readonly object Temp = 1; 68 | 69 | /// 70 | /// The instance 71 | /// 72 | private static T? _Instance; 73 | } 74 | } -------------------------------------------------------------------------------- /BigBook/Patterns/BaseClasses/StringEnumBaseClass.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 James Craig 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | namespace BigBook.Patterns.BaseClasses 18 | { 19 | /// 20 | /// String enum base class 21 | /// 22 | /// The type of the class. 23 | public abstract class StringEnumBaseClass 24 | where TClass : StringEnumBaseClass, new() 25 | { 26 | /// 27 | /// Initializes a new instance of the class. 28 | /// 29 | /// The name. 30 | protected StringEnumBaseClass(string name) 31 | { 32 | Name = name; 33 | } 34 | 35 | /// 36 | /// Gets or sets the name. 37 | /// 38 | /// The name. 39 | protected string Name { get; set; } 40 | 41 | /// 42 | /// Performs an implicit conversion from to . 43 | /// 44 | /// Type of the enum. 45 | /// The result of the conversion. 46 | public static implicit operator string(StringEnumBaseClass? enumType) 47 | { 48 | return enumType?.ToString() ?? string.Empty; 49 | } 50 | 51 | /// 52 | /// Performs an implicit conversion from to . 53 | /// 54 | /// Type of the enum. 55 | /// The result of the conversion. 56 | public static implicit operator StringEnumBaseClass(string? enumType) 57 | { 58 | return new TClass { Name = enumType ?? string.Empty }; 59 | } 60 | 61 | /// 62 | /// Converts to the enum from a string. 63 | /// 64 | /// Type of the enum. 65 | /// The enum value 66 | public static StringEnumBaseClass ToStringEnumBaseClass(string enumType) => enumType; 67 | 68 | /// 69 | /// Returns a that represents this instance. 70 | /// 71 | /// A that represents this instance. 72 | public override string ToString() => Name; 73 | } 74 | } -------------------------------------------------------------------------------- /BigBook/Patterns/Factory.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 James Craig 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | using System; 18 | using System.Collections.Generic; 19 | 20 | namespace BigBook.Patterns 21 | { 22 | /// 23 | /// Factory class 24 | /// 25 | /// The "message" type 26 | /// The class type that you want created 27 | public class Factory 28 | { 29 | /// 30 | /// Constructor 31 | /// 32 | public Factory() 33 | { 34 | Constructors = new Dictionary>(); 35 | } 36 | 37 | /// 38 | /// List of constructors/initializers 39 | /// 40 | protected Dictionary> Constructors { get; } 41 | 42 | /// 43 | /// Creates an instance associated with the key 44 | /// 45 | /// Registered item 46 | /// The type returned by the initializer 47 | public TClass Create(TKey key) => Constructors.GetValue(key, () => default!)(); 48 | 49 | /// 50 | /// Determines if a key has been registered 51 | /// 52 | /// Key to check 53 | /// True if it exists, false otherwise 54 | public bool Exists(TKey key) => Constructors.ContainsKey(key); 55 | 56 | /// 57 | /// Registers an item 58 | /// 59 | /// Item to register 60 | /// The object to be returned 61 | /// This 62 | public Factory Register(TKey key, TClass result) => Register(key, () => result); 63 | 64 | /// 65 | /// Registers an item 66 | /// 67 | /// Item to register 68 | /// The function to call when creating the item 69 | /// This 70 | public Factory Register(TKey key, Func constructor) 71 | { 72 | Constructors.SetValue(key, constructor); 73 | return this; 74 | } 75 | } 76 | } -------------------------------------------------------------------------------- /BigBook/Patterns/IFluentInterface.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 James Craig 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | using System; 18 | using System.ComponentModel; 19 | 20 | namespace BigBook.Patterns 21 | { 22 | /// 23 | /// Helps in fluent interface design to hide ToString, Equals, and GetHashCode 24 | /// 25 | public interface IFluentInterface 26 | { 27 | /// 28 | /// Hides equals 29 | /// 30 | /// 31 | /// 32 | [EditorBrowsable(EditorBrowsableState.Never)] 33 | bool Equals(object obj); 34 | 35 | /// 36 | /// Hides GetHashCode 37 | /// 38 | /// 39 | [EditorBrowsable(EditorBrowsableState.Never)] 40 | int GetHashCode(); 41 | 42 | /// 43 | /// Hides GetType 44 | /// 45 | /// 46 | [EditorBrowsable(EditorBrowsableState.Never)] 47 | Type GetType(); 48 | 49 | /// 50 | /// Hides ToString 51 | /// 52 | /// 53 | [EditorBrowsable(EditorBrowsableState.Never)] 54 | string ToString(); 55 | } 56 | } -------------------------------------------------------------------------------- /BigBook/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Resources; 3 | using System.Runtime.CompilerServices; 4 | using System.Runtime.InteropServices; 5 | 6 | // General Information about an assembly is controlled through the following set of attributes. 7 | // Change these attribute values to modify the information associated with an assembly. 8 | [assembly: AssemblyConfiguration("")] 9 | [assembly: AssemblyCompany("")] 10 | [assembly: AssemblyProduct("BigBook")] 11 | [assembly: AssemblyTrademark("")] 12 | 13 | // Setting ComVisible to false makes the types in this assembly not visible to COM components. If 14 | // you need to access a type in this assembly from COM, set the ComVisible attribute to true on that type. 15 | [assembly: ComVisible(false)] 16 | 17 | // The following GUID is for the ID of the typelib if this project is exposed to COM 18 | [assembly: Guid("ba2b2595-cd55-4639-9e5d-be4bdacca1ab")] 19 | [assembly: NeutralResourcesLanguage("en-US")] 20 | [assembly: InternalsVisibleToAttribute("BigBook.Tests")] 21 | [assembly: InternalsVisibleToAttribute("BigBook.Benchmarks")] -------------------------------------------------------------------------------- /BigBook/Queryable/BaseClasses/QueryProviderBase.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 James Craig 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | using Fast.Activator; 18 | using System.Linq; 19 | using System.Linq.Expressions; 20 | using System.Reflection; 21 | 22 | namespace BigBook.Queryable.BaseClasses 23 | { 24 | /// 25 | /// Query provider base class 26 | /// 27 | /// 28 | public abstract class QueryProviderBase : IQueryProvider 29 | { 30 | /// 31 | /// Initializes a new instance of the class. 32 | /// 33 | protected QueryProviderBase() 34 | { 35 | } 36 | 37 | /// 38 | /// Constructs an object that can evaluate the 39 | /// query represented by a specified expression tree. 40 | /// 41 | /// 42 | /// The type of the elements of the that is returned. 43 | /// 44 | /// An expression tree that represents a LINQ query. 45 | /// 46 | /// An that can evaluate the query represented by 47 | /// the specified expression tree. 48 | /// 49 | public IQueryable CreateQuery(Expression expression) => new Query(this, expression); 50 | 51 | /// 52 | /// Constructs an object that can evaluate the query 53 | /// represented by a specified expression tree. 54 | /// 55 | /// An expression tree that represents a LINQ query. 56 | /// 57 | /// An that can evaluate the query represented by the 58 | /// specified expression tree. 59 | /// 60 | public IQueryable? CreateQuery(Expression expression) 61 | { 62 | if (expression is null) 63 | return null; 64 | var ElementType = expression.Type.GetIEnumerableElementType(); 65 | 66 | try 67 | { 68 | return (IQueryable)FastActivator.CreateInstance(typeof(Query<>).MakeGenericType(ElementType), new object[] { this, expression }); 69 | } 70 | catch (TargetInvocationException Err) 71 | { 72 | throw Err.InnerException; 73 | } 74 | } 75 | 76 | /// 77 | /// Executes the specified expression. 78 | /// 79 | /// The type of the element. 80 | /// The expression. 81 | /// The value that results from executing the specified query. 82 | public TElement Execute(Expression expression) => (TElement)Execute(expression)!; 83 | 84 | /// 85 | /// Executes the query represented by a specified expression tree. 86 | /// 87 | /// An expression tree that represents a LINQ query. 88 | /// The value that results from executing the specified query. 89 | public abstract object? Execute(Expression expression); 90 | 91 | /// 92 | /// Gets the query text. 93 | /// 94 | /// The expression. 95 | /// The query as a string 96 | public abstract string GetQueryText(Expression expression); 97 | } 98 | } -------------------------------------------------------------------------------- /BigBook/Reflection/TypeCacheFor.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 James Craig 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | using System; 18 | using System.Reflection; 19 | 20 | namespace BigBook.Reflection 21 | { 22 | /// 23 | /// Type cache info 24 | /// 25 | /// Type to cache. 26 | public static class TypeCacheFor 27 | { 28 | /// 29 | /// The constructors 30 | /// 31 | public static readonly ConstructorInfo[] Constructors = typeof(T).GetConstructors(); 32 | 33 | /// 34 | /// The fields 35 | /// 36 | public static readonly FieldInfo[] Fields = typeof(T).GetFields(); 37 | 38 | /// 39 | /// The interfaces 40 | /// 41 | public static readonly Type[] Interfaces = typeof(T).GetInterfaces(); 42 | 43 | /// 44 | /// The methods 45 | /// 46 | public static readonly MethodInfo[] Methods = typeof(T).GetMethods(); 47 | 48 | /// 49 | /// The properties 50 | /// 51 | public static readonly PropertyInfo[] Properties = typeof(T).GetProperties(BindingFlags.FlattenHierarchy | BindingFlags.Instance | BindingFlags.Public); 52 | 53 | /// 54 | /// The type 55 | /// 56 | public static readonly Type Type = typeof(T); 57 | } 58 | } -------------------------------------------------------------------------------- /BigBook/Registration/CanisterExtensions.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 James Craig 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | using Aspectus.ExtensionMethods; 18 | using BigBook.Comparison; 19 | using BigBook.DynamoUtils; 20 | using Canister.Interfaces; 21 | using Microsoft.Extensions.DependencyInjection; 22 | using Microsoft.Extensions.ObjectPool; 23 | using ObjectCartographer.ExtensionMethods; 24 | 25 | namespace BigBook.Registration 26 | { 27 | /// 28 | /// Canister registration extension 29 | /// 30 | public static class BigBookCanisterExtensions 31 | { 32 | /// 33 | /// Registers the big book of data types. 34 | /// 35 | /// The bootstrapper. 36 | /// The bootstrapper 37 | public static ICanisterConfiguration? RegisterBigBookOfDataTypes(this ICanisterConfiguration? bootstrapper) => bootstrapper?.AddAssembly(typeof(BigBookCanisterExtensions).Assembly); 38 | 39 | /// 40 | /// Registers the big book of data types with the specified service collection. 41 | /// 42 | /// The service collection to register the data types with. 43 | /// The service collection with the registered data types. 44 | public static IServiceCollection? RegisterBigBookOfDataTypes(this IServiceCollection? services) 45 | { 46 | if (services.Exists()) 47 | return services; 48 | var ObjectPoolProvider = new DefaultObjectPoolProvider(); 49 | return services?.AddSingleton(typeof(GenericComparer<>)) 50 | .AddSingleton(typeof(GenericEqualityComparer<>)) 51 | .AddSingleton(new DynamoTypes()) 52 | .AddSingleton(ObjectPoolProvider.CreateStringBuilderPool()) 53 | .RegisterAspectus() 54 | .RegisterObjectCartographer(); 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Code of Conduct 2 | 3 | This project has a very simple code of conduct. Specifically we use the DBAD code of conduct, which includes the following rules: 4 | 5 | 1. DON'T BE A DICK 6 | 7 | # Who Determines If This Rule Is Broken 8 | 9 | I do. 10 | 11 | # What Are The Consequences? 12 | 13 | I probably ban you. 14 | -------------------------------------------------------------------------------- /Icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaCraig/BigBookOfDataTypes/67c63523c77b2e09ef25baf21394946c944bdae1/Icon.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Big Book of Data Types 2 | 3 | [![.NET Publish](https://github.com/JaCraig/BigBookOfDataTypes/actions/workflows/dotnet-publish.yml/badge.svg)](https://github.com/JaCraig/BigBookOfDataTypes/actions/workflows/dotnet-publish.yml) 4 | 5 | Big Book of Data Types is a set of classes and extension methods to help with data. This includes classes for caching, data comparison, data conversion, data mapping, string formatting, as well as various data types that are missing from .Net. 6 | 7 | ## Setting Up the Library 8 | 9 | Depending on the features you use in Big Book of Data Types, you may need to register it with your ServiceCollection as the Dynamo class requires it in order to hook itself up. In order for this to work, you must do the following at startup: 10 | 11 | ```csharp 12 | services.RegisterBigBookOfDataTypes(); 13 | ``` 14 | 15 | or 16 | 17 | ```csharp 18 | services.AddCanisterModules(); 19 | ``` 20 | 21 | As the library supports [Canister Modules](https://github.com/JaCraig/Canister). The RegisterBigBookOfDataTypes function is an extension method on your app's ServiceCollection. When this is done, the Dynamo class is ready to use. If you are not using that class, you should be able to go without registration. 22 | 23 | ## Basic usage 24 | 25 | Most of the library is simply data types that can be used fairly easily. These include: 26 | 27 | 1. Bag 28 | 2. BinaryTree 29 | 3. DateSpan 30 | 4. Fraction 31 | 5. ListMapping 32 | 6. Matrix 33 | 7. ObservableList 34 | 8. PriorityQueue 35 | 9. RingBuffer 36 | 10. Set 37 | 11. Table 38 | 12. TagDictionary 39 | 13. TaskQueue 40 | 14. Vector3 41 | 42 | Similarly the extension methods for various types can be found by adding: 43 | 44 | ```csharp 45 | using BigBook; 46 | ``` 47 | 48 | To your list of usings. From there a number of extension methods should be available for arrays, IEnumerable, string, ConcurrentBag, ConcurrentDictionary, DateTime, Exception, ICollection, IComparable, IDictionary, MatchCollection, Process, Stream, TimeSpan, etc. There are a couple hundred extension methods and I suggest you just take a look at them to see what they do. Another portion of the library that might be of some interest and yet not completely intuitive is the Dynamo class. 49 | 50 | Dynamo is a true dynamic type for .Net. ExpandoObject is generally great for basic work that requires a dynamic, however it is not easy to convert to other data types. For instance you can't do this: 51 | 52 | ```csharp 53 | dynamic MyDynamicValue=new ExpandoObject(); 54 | SomeClass FinalObject=MyDynamicValue; 55 | ``` 56 | 57 | Dynamo, on the other hand, has no issues with this: 58 | 59 | ```csharp 60 | dynamic MyDynamicValue=new Dynamo(); 61 | SomeClass FinalObject=MyDynamicValue; 62 | ``` 63 | 64 | The class handles conversion to and from class types, can convert properties from one type to another, and comes with a set of built in functionality. The class implements INotifyPropertyChanged, has a built in change log, and is thread safe. It can also be added as a base class for other classes to add this functionality automatically. 65 | 66 | ## Installation 67 | 68 | The library is available via Nuget with the package name "BigBook". To install it run the following command in the Package Manager Console: 69 | 70 | Install-Package BigBook 71 | 72 | ## Build Process 73 | 74 | In order to build the library you will require the following: 75 | 76 | 1. Visual Studio 2022 77 | 78 | Other than that, just clone the project and you should be able to load the solution and build without too much effort. 79 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Supported Versions 4 | 5 | | Version | Supported | 6 | | -------- | ------------------ | 7 | | latest | :white_check_mark: | 8 | | < latest | :x: | 9 | -------------------------------------------------------------------------------- /TestSize/Program.cs: -------------------------------------------------------------------------------- 1 | using BigBook; 2 | using BigBook.Registration; 3 | using Microsoft.Extensions.DependencyInjection; 4 | 5 | namespace TestSize 6 | { 7 | internal class Program 8 | { 9 | private static void Main(string[] args) 10 | { 11 | new ServiceCollection().AddCanisterModules(configure => configure.RegisterBigBookOfDataTypes()); 12 | for (var x = 0; x < 100000; ++x) 13 | { 14 | dynamic Item = new Dynamo(new { A = "This is a test" }); 15 | TestClass TestClass = Item; 16 | } 17 | } 18 | 19 | private interface ITestInterface : ITestInterface2 20 | { 21 | } 22 | 23 | private interface ITestInterface2 24 | { 25 | string A { get; set; } 26 | } 27 | 28 | private abstract class TestAbstract : ITestInterface 29 | { 30 | public abstract string A { get; set; } 31 | 32 | public string B { get; set; } 33 | } 34 | 35 | private class TestClass : TestAbstract 36 | { 37 | public override string A { get; set; } 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /TestSize/TestSize.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0;net9.0 6 | 7 | 8 | 9 | full 10 | true 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /docfx_project/.gitignore: -------------------------------------------------------------------------------- 1 | ############### 2 | # folder # 3 | ############### 4 | /**/DROP/ 5 | /**/TEMP/ 6 | /**/packages/ 7 | /**/bin/ 8 | /**/obj/ 9 | 10 | -------------------------------------------------------------------------------- /docfx_project/api/.gitignore: -------------------------------------------------------------------------------- 1 | ############### 2 | # temp file # 3 | ############### 4 | *.yml 5 | .manifest 6 | -------------------------------------------------------------------------------- /docfx_project/api/index.md: -------------------------------------------------------------------------------- 1 | # Welcome 2 | Welcome to the API browser. -------------------------------------------------------------------------------- /docfx_project/articles/example2.md: -------------------------------------------------------------------------------- 1 | # Code 2 | [!code-csharp[](../../BigBook.Example/Example2.cs)] 3 | 4 | # Output 5 | 6 | ``` 7 | Test1: 5, 10 8 | Test2: 15, 20 9 | Test3: 25, 30 10 | ``` -------------------------------------------------------------------------------- /docfx_project/articles/example3.md: -------------------------------------------------------------------------------- 1 | # Code 2 | [!code-csharp[](../../BigBook.Example/Example3.cs)] 3 | 4 | # Output 5 | 6 | ``` 7 | 5 8 | ``` -------------------------------------------------------------------------------- /docfx_project/articles/intro.md: -------------------------------------------------------------------------------- 1 | # Code 2 | [!code-csharp[](../../BigBook.Example/Example1.cs)] 3 | 4 | # Output 5 | 6 | ``` 7 | Thisisanexamplestring 8 | Thisisanexamplestring2 9 | This is an example string #3 10 | String Extensions 11 | ``` -------------------------------------------------------------------------------- /docfx_project/articles/toc.yml: -------------------------------------------------------------------------------- 1 | - name: String Extension Methods Example 2 | href: intro.md 3 | - name: ListMapping Example 4 | href: example2.md 5 | - name: LazyAsync Example 6 | href: example3.md -------------------------------------------------------------------------------- /docfx_project/docfx.json: -------------------------------------------------------------------------------- 1 | { 2 | "metadata": [ 3 | { 4 | "src": [ 5 | { 6 | "files": ["BigBook/BigBook.csproj"], 7 | "src": "../" 8 | } 9 | ], 10 | "dest": "api", 11 | "properties": { 12 | "TargetFramework": "net8.0" 13 | }, 14 | "includePrivateMembers": false, 15 | "disableGitFeatures": false, 16 | "disableDefaultFilter": false, 17 | "noRestore": false, 18 | "namespaceLayout": "flattened", 19 | "memberLayout": "samePage", 20 | "allowCompilationErrors": false 21 | } 22 | ], 23 | "build": { 24 | "globalMetadata": { 25 | "_appTitle": "Big Book of DataTypes API Reference", 26 | "_appName": "BigBook", 27 | "_appLogoPath": "images/icon.png", 28 | "_appFooter": "Open in Github", 29 | "_copyrightFooter": "© James Craig. All rights reserved.", 30 | "_enableSearch": true, 31 | "_disableSideFilter": false, 32 | "_enableNewTab": true, 33 | "_disableContribution": false, 34 | "_disableBreadcrumb": false 35 | }, 36 | "content": [ 37 | { 38 | "files": [ 39 | "api/**.yml", 40 | "api/index.md" 41 | ] 42 | }, 43 | { 44 | "files": [ 45 | "articles/**.md", 46 | "articles/**/toc.yml", 47 | "toc.yml", 48 | "*.md" 49 | ] 50 | } 51 | ], 52 | "resource": [ 53 | { 54 | "files": [ 55 | "images/**" 56 | ] 57 | } 58 | ], 59 | "output": "_site", 60 | "globalMetadataFiles": [], 61 | "fileMetadataFiles": [], 62 | "template": [ 63 | "default", 64 | "modern", 65 | "./templates/mytemplate" 66 | ], 67 | "postProcessors": [], 68 | "keepFileLink": false, 69 | "disableGitFeatures": false 70 | } 71 | } -------------------------------------------------------------------------------- /docfx_project/images/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaCraig/BigBookOfDataTypes/67c63523c77b2e09ef25baf21394946c944bdae1/docfx_project/images/icon.png -------------------------------------------------------------------------------- /docfx_project/index.md: -------------------------------------------------------------------------------- 1 | [!INCLUDE [README.md](../README.md)] -------------------------------------------------------------------------------- /docfx_project/templates/mytemplate/public/main.css: -------------------------------------------------------------------------------- 1 | img#logo { 2 | height: 35px; 3 | padding-right: 10px; 4 | } -------------------------------------------------------------------------------- /docfx_project/toc.yml: -------------------------------------------------------------------------------- 1 | - name: Example 2 | href: articles/ 3 | - name: Api Documentation 4 | href: api/ 5 | homepage: api/index.md 6 | -------------------------------------------------------------------------------- /setup.bat: -------------------------------------------------------------------------------- 1 | dotnet new tool-manifest 2 | dotnet tool install Husky 3 | dotnet tool install Versionize 4 | dotnet tool update -g docfx 5 | docfx init --quiet 6 | dotnet husky install --------------------------------------------------------------------------------