StringPlaceholder 2.0.2

dotnet add package StringPlaceholder --version 2.0.2                
NuGet\Install-Package StringPlaceholder -Version 2.0.2                
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="StringPlaceholder" Version="2.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add StringPlaceholder --version 2.0.2                
#r "nuget: StringPlaceholder, 2.0.2"                
#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.
// Install StringPlaceholder as a Cake Addin
#addin nuget:?package=StringPlaceholder&version=2.0.2

// Install StringPlaceholder as a Cake Tool
#tool nuget:?package=StringPlaceholder&version=2.0.2                

Deploy Nuget com testes

String Placeholder 2.0.0

https://www.nuget.org/packages/StringPlaceholder/

dotnet add package StringPlaceholder

Description

Nuget package to loop through text by a specific especify pattern. Replacing the found part with the return

Easy use example

///Create your methods that return string
string TestOne()
{
    return "TestOne!";
}
string TestTwo()
{
    return "TestTwo!";
}

/// Create a pattern to find your placeholder in string
var pattern = @"\%(.*?)\%";

/// The string to perform the task.
var text = "Hello, word %TEST1%, %TEST2%";

/// Create PlaceholderCreator instance
var stringPlaceholder = new PlaceholderCreator();

/// Create StringExecutor List with keys and the methods to be called.
var listaExecutors = new List<StringExecutor>()
{
  	///KEY, STRING METHOD
    new StringExecutor("TEST1", TestOne),
    new StringExecutor("TEST2", TestTwo),
};

/// Call Creator method
var result = stringPlaceholder.Creator(text, listaExecutors, pattern);

///Result: "Hello, word TestOne!, TestTwo!"

Placeholders with params


///Create your methods that return string and accept array of string as params
string TestOne(string[] objParams)
{
    return "TestOne! " + objParams[0];
}
string TestTwo(string[] objParams)
{
    var result = string.Join(", ", objParams);
    return "TestTwo! " + result;
}

/// The string to perform the task.
var text = "Hello, word [TEST1(http://google.com.br)], [TEST2(teste1,teste2, abacate)]";

/// Create PlaceholderCreator instance
var stringPlaceholder = new PlaceholderCreator();

/// Create StringExecutor List with keys and the methods to be called.
var listaExecutors = new List<StringExecutor>()
{
    new StringExecutor("TEST1",  TestOne, "teste", new List<string>()
    {
        "arg1",
        "arg2"
    }),
    new StringExecutor("TEST2",  TestTwo),
};
/// Call Creator method
var result = stringPlaceholder.Creator(text, listaExecutors);

///Assert that return variable is builded with placeholders
Assert.Contains("TestOne! http://google.com.br", result);
Assert.Contains("TestTwo! teste1, teste2, abacate", result);

Result: 
    true
    true

Fluent simple example

///Create your methods that return string
string TestOne()
{
    return "TestOne!";
}
string TestTwo()
{
    return "TestTwo!";
}

/// Create a pattern to find your placeholder in string
var pattern = @"\%(.*?)\%";

/// The string to perform the task.
var inputText = "Hello, word %TEST1%, %TEST2%";

/// Create ExecutorCreator instance
var executorCreator = new ExecutorCreator();

/// call create method
///finalize with build method to build the placeholders
///get string with palceholders
var result = executorCreator.Create()
    .Add(new StringExecutor("TEST1", TestOne))
    .Add(new StringExecutor("TEST2", TestTwo))
.Build(pattern, inputText);
.Result();

///Assert that return variable is builded with placeholders
Assert.Contains("TestOne!", result);
Assert.Contains("TestTwo!", result);

Result: 
    true
    true

Fluent example with callback on build

///Create your methods that return string
string TestOne()
{
    return "TestOne!";
}
string TestTwo()
{
    return "TestTwo!";
}

/// Create a pattern to find your placeholder in string
var pattern = @"\%(.*?)\%";

/// The string to perform the task.
var inputText = "Hello, word %TEST1%, %TEST2%";

/// Create ExecutorCreator instance
var executorCreator = new ExecutorCreator();

/// call create method
executorCreator.Create()
    .Add(new StringExecutor("TEST1", TestOne))
    .Add(new StringExecutor("TEST2", TestTwo))
//finalize with build method to build the placeholders and return into callback
.Build(pattern, inputText, (result) =>
{
    ///Assert that result variable is builded with placeholders
    Assert.Contains("TestOne!", result);
    Assert.Contains("TestTwo!", result);
});

Result: 
    true
    true

Api Usages

StringPlaceholder can create the OpenApi description foreach placeholder you create.

/// Create a pattern to find your placeholder in string
var pattern = @"\%(.*?)\%";

/// The string to perform the task.
var inputText = "Hello, word %TEST1%, %TEST2%";

var result = new ExecutorCreator().Create()
.Add(new StringExecutor("TEST1", TestOne))
.Add(new StringExecutor("TEST2", TestTwo))
.Build(pattern, inputText);


///create a list of OpenApiDescription object with the schema

key string
Args IEnumerable<string>
MultipleParams bool
Description string

var openApiDescription = result.GetOpenApiDescription();

Assert.True(openApiDescription.Count() == 2);

string TestOne()
{
return "TestOne!";
}
string TestTwo()
{
return "TestTwo!";
}

Result: 
    true

Projects using placeholder

brutalzinn/gerador-de-dados

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net7.0

    • 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
2.0.2 309 4/7/2023
2.0.1 217 3/28/2023
2.0.0 267 2/7/2023
1.0.7 364 11/20/2022
1.0.6 348 11/20/2022
1.0.5 339 11/20/2022
1.0.4 340 11/20/2022
1.0.3 339 11/20/2022
1.0.2 337 11/18/2022
1.0.1 335 11/16/2022
1.0.0 347 11/15/2022

2.0.0.2