DotNetDupe 3.0.0

dotnet add package DotNetDupe --version 3.0.0
                    
NuGet\Install-Package DotNetDupe -Version 3.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DotNetDupe" Version="3.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DotNetDupe" Version="3.0.0" />
                    
Directory.Packages.props
<PackageReference Include="DotNetDupe" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DotNetDupe --version 3.0.0
                    
#r "nuget: DotNetDupe, 3.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package DotNetDupe@3.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DotNetDupe&version=3.0.0
                    
Install as a Cake Addin
#tool nuget:?package=DotNetDupe&version=3.0.0
                    
Install as a Cake Tool

DotNetDupe ๐Ÿš€

License Build Status

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 ๐Ÿ“š

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 String class 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, and TimeZoneInfo for accurate time management.
  • Type System Enhancements: (Add more specific features as they are implemented, e.g., Object base class, IComparable, IClonable etc.)

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 โฌ‡๏ธ

  1. Clone the repository:

    git clone https://github.com/your-username/DotNetDupe.git
    cd DotNetDupe
    
  2. Build 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_packages
    

    This 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.

  3. Add local NuGet package source: To use the locally generated NuGet package, add the nuget_packages directory as a local NuGet source:

    nuget sources Add -Name "DotNetDupeLocal" -Source "D:\Personal\Projects\C++\DotNetDupe\nuget_packages"
    

    (Replace D:\Personal\Projects\C++\DotNetDupe with your actual solution root path.)

  4. Install the NuGet package in your project: In your C++ project, you can now install the DotNetDupe package 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.)

  5. Integrate into your project: Once installed, ensure your project's .vcxproj file is configured to link against the DotNetDupe.lib and include its headers. The NuGet package's .targets file 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.

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 main and 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

  1. Update the version in DotNetDupe.nuspec.
  2. Commit and push the changes.
  3. Create and push a new tag:
    git tag v1.0.0
    git push origin v1.0.0
    
    Note: Requires NUGET_API_KEY to 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 Compatible and additional computed target framework versions.
native native is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.

Version Downloads Last Updated
3.0.0 83 5/31/2026
2.1.0 87 5/21/2026
2.0.0 85 5/20/2026
1.0.0 141 5/9/2026

Major release: cross platform support added - tested using Ubuntu on WSL, C++ core coding guidelines applied, introduced SmartPointer