DotNetDupe 3.0.0
dotnet add package DotNetDupe --version 3.0.0
NuGet\Install-Package DotNetDupe -Version 3.0.0
<PackageReference Include="DotNetDupe" Version="3.0.0" />
<PackageVersion Include="DotNetDupe" Version="3.0.0" />
<PackageReference Include="DotNetDupe" />
paket add DotNetDupe --version 3.0.0
#r "nuget: DotNetDupe, 3.0.0"
#:package DotNetDupe@3.0.0
#addin nuget:?package=DotNetDupe&version=3.0.0
#tool nuget:?package=DotNetDupe&version=3.0.0
DotNetDupe ๐
Ever admired the elegance and developer-friendliness of .NET APIs? ๐ค While the C++ Standard Template Library (STL) is powerful, its learning curve can be steep. This project, DotNetDupe, bridges that gap! ๐
Inspired by the clear and concise API design of C# .NET, DotNetDupe is a C++ library that brings a familiar, streamlined development experience to your C++ projects. โจ
Major Update (v3.0.0): DotNetDupe is now fully cross-platform! ๐ We've introduced official support for Linux (tested via Ubuntu on WSL) alongside Windows, applied C++ Core Coding Guidelines for better reliability, and introduced the SmartPointer utility for unified resource management.
We're starting with a foundational set of classes in the System and IO namespaces, offering a glimpse into the library's potential. Your contributions are highly welcome to expand its functionality! ๐ค
A fun fact: While I personally crafted core components like Char, String, and Path (along with their tests), a significant portion of the remaining code was generated with the help of Gemini Code Assist. ๐ค This project serves as a unique playground for exploring how generative AI can accelerate development from scratch. ๐
DotNetDupe aims to simplify C++ development by providing C#-like interfaces for common tasks, making your code more concise, intuitive, and a joy to write. ๐
Table of Contents ๐
- DotNetDupe ๐
- Table of Contents ๐
- Project Overview ๐ก
- Features โจ
- Getting Started ๐
- Cross-Platform Support ๐
- WSL Setup Guide (Windows) ๐ง
- Building and Running with NuGet in WSL ๐ง๐ฆ
- Usage ๐ป
- STL vs DotNetDupe Comparison โ๏ธ
- API Reference ๐
- Project Status ๐ง
- Contributions ๐
- CI/CD Pipeline ๐
- License ๐
- Generated Content ๐ค
- Contact ๐ง
Project Overview ๐ก
The core objective of DotNetDupe is to bridge the gap between the power and performance of C++ and the ease of use and productivity offered by C# APIs. By providing C#-like interfaces for common programming tasks, DotNetDupe aims to:
- Simplify C++ Development: Reduce the boilerplate and complexity often associated with STL, making C++ more approachable for developers accustomed to higher-level languages.
- Enhance Readability: Promote cleaner and more readable code by adopting well-known C# API patterns.
- Boost Productivity: Accelerate development cycles by offering intuitive and efficient tools for common operations.
Features โจ
- C#-like API Design: Intuitive and familiar interfaces for common programming constructs.
- Exception Handling: Robust exception classes mimicking .NET's exception hierarchy.
- String Manipulation: Powerful
Stringclass with comprehensive methods for text processing. - Path Utilities: Convenient functions for file system path operations.
- Time and Time Zone Support: Core classes like
DateTimeOffset,TimeSpan,TimeZone, andTimeZoneInfofor accurate time management. - Type System Enhancements: (Add more specific features as they are implemented, e.g.,
Objectbase class,IComparable,IClonableetc.)
Getting Started ๐
Prerequisites ๐
- C++17 compatible compiler (e.g., MSVC, GCC, Clang)
- CMake (for building, if applicable)
- (Any other dependencies, e.g., Google Test for running tests)
Installation โฌ๏ธ
Clone the repository:
git clone https://github.com/your-username/DotNetDupe.git cd DotNetDupeBuild the solution and generate NuGet package: Open a Developer Command Prompt for Visual Studio and navigate to the project root.
msbuild DotNetDupe.sln /p:Configuration=Release /p:Platform=x64 nuget pack DotNetDupe.nuspec -OutputDirectory nuget_packagesThis will build the DotNetDupe library and automatically create a NuGet package (DotNetDupe.3.0.0.nupkg) in the nuget_packages directory at the solution root.
Add local NuGet package source: To use the locally generated NuGet package, add the
nuget_packagesdirectory as a local NuGet source:nuget sources Add -Name "DotNetDupeLocal" -Source "D:\Personal\Projects\C++\DotNetDupe\nuget_packages"(Replace
D:\Personal\Projects\C++\DotNetDupewith your actual solution root path.)Install the NuGet package in your project: In your C++ project, you can now install the
DotNetDupepackage using the NuGet Package Manager or the command line:nuget install DotNetDupe -OutputDirectory <YourProjectDirectory> -Source DotNetDupeLocal(Replace
<YourProjectDirectory>with the path to your project where you want to install the package.)Integrate into your project: Once installed, ensure your project's
.vcxprojfile is configured to link against theDotNetDupe.liband include its headers. The NuGet package's.targetsfile should handle most of this automatically.
Cross-Platform Support ๐
DotNetDupe is designed for high portability and officially supports Windows (via MSVC/MSBuild) and Linux (via GCC/Clang/CMake).
Building and Testing
| Platform | Build System | Build Command | Test Command |
|---|---|---|---|
| Windows | MSBuild | msbuild DotNetDupe.sln /p:Configuration=Release |
.\bin\x64\Release\DotNetDupeTests.exe |
| Linux / WSL | CMake | cmake -S . -B build && cmake --build build |
cd build && ctest |
Integration via NuGet
DotNetDupe is distributed as a multi-platform NuGet package. It contains native binaries for:
win-x64(DotNetDupe.dll)linux-x64(libDotNetDupe.so)
When you add the NuGet package to your project, the appropriate binary is automatically selected based on your target platform.
Note for Linux Users
On Linux, NuGet packages are typically managed via dotnet CLI or integrated into CMake projects using tools like vcpkg or by manually extracting the shared library (.so) and headers from the .nupkg (which is a ZIP file).
Example manual extraction:
unzip DotNetDupe.nupkg -d dotnetdupe_lib
# Use dotnetdupe_lib/include for headers
# Use dotnetdupe_lib/runtimes/linux-x64/native/libDotNetDupe.so for linking
WSL Setup Guide (Windows) ๐ง
For Windows developers who want to build and test for Linux locally, we recommend using the Windows Subsystem for Linux (WSL).
1. Install WSL
If you haven't already, install Ubuntu via PowerShell:
wsl --install -d Ubuntu
2. Environment Provisioning
Inside your WSL terminal, install the C++ build chain:
sudo apt-get update
sudo apt-get install -y build-essential cmake
3. Build & Test in WSL
Navigate to your project root (e.g., /mnt/d/Projects/DotNetDupe) and run:
# Create build directory
mkdir -p build-wsl && cd build-wsl
# Configure and Build
cmake .. -DCMAKE_BUILD_TYPE=Release
cmake --build .
# Run Tests
ctest --output-on-failure
4. Running WSL Commands from PowerShell
You can also build and test for Linux directly from a Windows PowerShell terminal without manually entering the WSL shell:
# Create build directory
wsl -d Ubuntu -- bash -c "mkdir -p build-wsl"
# Configure
wsl -d Ubuntu -- bash -c "cd build-wsl && cmake .. -DCMAKE_BUILD_TYPE=Release"
# Build
wsl -d Ubuntu -- bash -c "cd build-wsl && cmake --build ."
# Run Tests (via CTest)
wsl -d Ubuntu -- bash -c "cd build-wsl && ctest"
# Run Tests (direct execution)
wsl -d Ubuntu -- bash -c "cd build-wsl && ./DotNetDupeTests"
# Run Demo Application
wsl -d Ubuntu -- bash -c "cd build-wsl && ./DotNetDupeDemo"
Building and Running with NuGet in WSL ๐ง๐ฆ
This section describes how to use the pre-compiled NuGet package to build and run the DotNetDupeDemo application in a WSL environment.
1. Extract the NuGet Package
The .nupkg file is a ZIP archive. Extract it to a local directory (e.g., DotNetDupe_NuGet) using PowerShell:
Expand-Archive -Path "nuget_packages\DotNetDupe.3.0.0.nupkg" -DestinationPath "DotNetDupe_NuGet" -Force
2. Configure and Build in WSL
Use CMake with the USE_NUGET option enabled and point NUGET_PATH to the extracted directory. WSL automatically handles the path mapping for Windows drives.
# Configure
wsl cmake -S . -B build-wsl -DUSE_NUGET=ON -DNUGET_PATH="./DotNetDupe_NuGet"
# Build the Demo Application
wsl cmake --build build-wsl --target DotNetDupeDemo
3. Execute in WSL
Run the demo application directly from PowerShell via wsl:
wsl ./build-wsl/DotNetDupeDemo
Usage ๐ป
Here are some quick examples of how to use DotNetDupe:
#include <iostream>
#include "DotNetDupe/String.h"
#include "DotNetDupe/Path.h"
#include "DotNetDupe/BasicException.h"
#include "DotNetDupe/TimeZoneInfo.h"
int main() {
// String Example
DotNetDupe::System::String greeting = _T("Hello");
DotNetDupe::System::String name = _T("World");
DotNetDupe::System::String message = greeting + _T(", ") + name + _T("!");
std::wcout << message << std::endl; // Output: Hello, World!
// Path Example
DotNetDupe::System::String fullPath = DotNetDupe::System::IO::Path::Combine({_T("C:\\"), _T("Users"), _T("document.txt")});
std::wcout << L"Combined Path: " << fullPath << std::endl;
// TimeZone Example
DotNetDupe::System::TimeZoneInfo localTz = DotNetDupe::System::TimeZoneInfo::Local();
std::wcout << L"Local TimeZone: " << localTz.GetDisplayName() << std::endl;
// Exception Example
try {
throw DotNetDupe::System::BasicException<TCHAR>(_T("Something went wrong!"));
} catch (const DotNetDupe::System::BasicException<TCHAR>& e) {
std::wcout << L"Caught exception: " << e.What() << std::endl;
}
return 0;
}
STL vs DotNetDupe Comparison โ๏ธ
DotNetDupe is designed to be more intuitive and less verbose than the standard C++ STL.
- General Comparison Guide: Covers Strings, Collections, Timing, etc.
- Threading Comparison Guide: Detailed comparison of thread synchronization primitives.
Sample Client and Test Code ๐งช
The repository includes DotNetDupeDemo (a sample console application) and DotNetDupeTests (unit tests) projects. These projects demonstrate how to integrate and use the DotNetDupe library. You can refer to their .vcxproj files for examples of how to configure your own projects to consume the DotNetDupe NuGet package.
API Reference ๐
For detailed information on the available classes, methods, and their usage, please refer to the comprehensive API documentation for each class.
Namespace: DotNetDupe::System
Classes
| Class | Description |
|---|---|
| Array<T> | Provides methods for creating, manipulating, searching, and sorting arrays. |
| BitConverter | Converts base data types to an array of bytes, and an array of bytes to base data types. |
| Buffer | Manipulates arrays of primitive types. |
| Char | Represents a character. |
| Console | Provides methods for reading from and writing to the standard input, output, and error streams. |
| Convert | Provides methods for converting a base data type to another base data type. |
| DaylightTime | Defines the period of daylight saving time. |
| DateTimeOffset | Represents a point in time, typically expressed as a date and time of day relative to UTC. |
| Environment | Provides information about the current environment and platform. |
| Guid | Represents a globally unique identifier (GUID). |
| Object | Supports all classes in the .NET class hierarchy and provides low-level services to derived classes. |
| OperatingSystem | Represents information about an operating system, such as the version and platform identifier. |
| Random | Represents a pseudo-random number generator. |
| SmartPointer<T> | A unified smart pointer supporting both unique and shared ownership. |
| String | Represents text as a sequence of character code units. |
| TimeProvider | Provides an abstraction for time. |
| TimeSpan | Represents a time interval. |
| TimeZone | Represents a time zone. |
| TimeZoneInfo | Represents any time zone in the world. |
| Uri | Provides an object representation of a uniform resource identifier (URI) and easy access to the parts of the URI. |
| UriBuilder | Provides a convenient way to modify the contents of a Uri instance. |
| UriComponents | Specifies the parts of a URI. |
| UriFormat | Controls how URI information is escaped. |
| UriParser | Parses a new URI scheme. |
| GenericUriParser | A customizable parser for a hierarchical URI. |
| Version | Represents the version number of an assembly, operating system, or the common language runtime. |
Exceptions
| Exception | Description |
|---|---|
| Exception | Represents errors that occur during application execution. |
| SystemException | The base class for all predefined exceptions in the System namespace. |
| ArgumentException | Represents errors that occur during argument processing. |
| ArgumentNullException | The exception that is thrown when a null reference is passed to a method that does not accept it as a valid argument. |
| ArgumentOutOfRangeException | Represents errors that occur when an argument is outside the allowable range of values. |
| ArithmeticException | Represents errors in an arithmetic operation. |
| FormatException | The exception that is thrown when the format of an argument is invalid. |
| NotImplementedException | The exception that is thrown when a requested method or operation is not implemented. |
| OverflowException | The exception that is thrown when an arithmetic, casting, or conversion operation in a checked context results in an overflow. |
Interfaces
| Interface | Description |
|---|---|
| IClonable | Defines a general-purpose mechanism for creating a new object that is a copy of the current object. |
| IComparable | Defines a method that a value type or class implements to compare itself with another object of the same type. |
| IComparable<T> | Defines a method that a value type or class implements to compare itself with another object of the same type. |
| IFormatProvider<T> | Provides a mechanism for retrieving a formatting service for a specified type. |
Namespace: DotNetDupe::System::Collections::Generic
Classes
| Class | Description |
|---|---|
| Dictionary<TKey, TValue> | Represents a collection of keys and values. |
| List<T> | Represents a strongly typed list of objects that can be accessed by index. |
Namespace: DotNetDupe::System::Diagnostics
Classes
| Class | Description |
|---|---|
| Stopwatch | Provides a set of methods and properties that you can use to accurately measure elapsed time. |
Namespace: DotNetDupe::System::Text
Classes
| Class | Description |
|---|---|
| StringBuilder | Represents a mutable string of characters. |
| TextEncoding | Represents a character encoding. |
Namespace: DotNetDupe::System::IO
Classes
| Class | Description |
|---|---|
| Path | A class for path-related operations. |
| File | Provides static methods for the creation, copying, deletion, moving, and opening of a single file. |
| FileStream | Provides a Stream for a file, supporting both synchronous and asynchronous read and write operations. |
| Stream | Provides a generic view of a sequence of bytes. |
| TextReader | Represents a reader that can read a sequential series of characters. |
| TextWriter | Represents a writer that can write a sequential series of characters. |
| StringReader | Implements a TextReader that reads from a string. |
| StringWriter | Implements a TextWriter for writing information to a string. |
Exceptions
| Exception | Description |
|---|---|
| IOException | The exception that is thrown when an I/O error occurs. |
Interfaces
| Interface | Description |
|---|---|
| IDisposable | Provides a mechanism for releasing unmanaged resources. |
Namespace: DotNetDupe::System::Threading
Classes
| Class | Description |
|---|---|
| Thread | Creates and controls a thread, sets its priority, and gets its status. |
| WaitHandle | Abstract base class for synchronization objects. |
| EventWaitHandle | Represents a thread synchronization event. |
| ManualResetEvent | Notifies one or more waiting threads that an event has occurred. |
| AutoResetEvent | Notifies a waiting thread that an event has occurred. |
| Mutex | A synchronization primitive that can also be used for inter-process synchronization. |
| Semaphore | Limits the number of threads that can access a resource or pool of resources concurrently. |
| SemaphoreSlim | A lightweight alternative to Semaphore. |
| CriticalSection | A wrapper around a recursive mutex for critical sections. |
| Interlocked | Provides atomic operations for variables that are shared by multiple threads. |
| Lock<T> | RAII mechanism for synchronization objects. |
Exceptions
| Exception | Description |
|---|---|
| ThreadStateException | The exception that is thrown when a Thread is in an invalid ThreadState for the method call. |
| ThreadInterruptedException | The exception that is thrown when a Thread is interrupted while it is in a waiting state. |
| SynchronizationLockException | The exception that is thrown when a method requires the caller to own the lock on a given Monitor, and the method is invoked by a caller that does not own that lock. |
| AbandonedMutexException | The exception that is thrown when one thread acquires a Mutex object that another thread has abandoned by exiting without releasing it. |
| WaitHandleCannotBeOpenedException | The exception that is thrown when an attempt is made to open a system mutex, semaphore, or event wait handle that does not exist. |
| SemaphoreFullException | The exception that is thrown when the Release method is called on a semaphore whose count is already at the maximum. |
Project Status ๐ง
DotNetDupe is currently under active development. We are continuously working on expanding the API coverage and improving stability.
Contributions ๐
Contributions to the DotNetDupe project are highly welcome! Whether it's bug reports, feature requests, code contributions, or documentation improvements, your help is invaluable. Please refer to GitHub's general contributing guidelines for more information on how to get started.
CI/CD Pipeline ๐
This repository uses GitHub Actions to automate the build, test, and release process.
Workflow Details
- Build & Test: Every push to
mainand all pull requests trigger a full build (Debug & Release) and execution of all unit tests. - NuGet Release: Pushing a tag (e.g.,
v1.0.0) triggers the creation and publishing of the NuGet package to nuget.org.
How to Release
- Update the version in
DotNetDupe.nuspec. - Commit and push the changes.
- Create and push a new tag:
Note: Requiresgit tag v1.0.0 git push origin v1.0.0NUGET_API_KEYto be set in GitHub repository secrets.
License ๐
This project is licensed under the MIT License. See the LICENSE file for details.
Generated Content ๐ค
This project is a unique blend of manual craftsmanship and AI-powered development. While the initial core components were meticulously crafted by hand, the majority of the remaining code, including many classes, methods, and their corresponding unit tests, were generated with the assistance of Gemini, a large language model. This approach highlights the potential of generative AI in accelerating software development from scratch.
Contact ๐ง
For questions or support, please open an issue on the GitHub repository or contact sudheeshps@gmail.com.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| native | native is compatible. |
This package has no dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Major release: cross platform support added - tested using Ubuntu on WSL, C++ core coding guidelines applied, introduced SmartPointer