add draft
This commit is contained in:
27
.devcontainer/devcontainer.json
Normal file
27
.devcontainer/devcontainer.json
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
|
||||||
|
// README at: https://github.com/devcontainers/templates/tree/main/src/dotnet
|
||||||
|
{
|
||||||
|
"name": "C# (.NET)",
|
||||||
|
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
|
||||||
|
"image": "mcr.microsoft.com/devcontainers/dotnet:0-6.0"
|
||||||
|
|
||||||
|
// Features to add to the dev container. More info: https://containers.dev/features.
|
||||||
|
// "features": {},
|
||||||
|
|
||||||
|
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
||||||
|
// "forwardPorts": [5000, 5001],
|
||||||
|
// "portsAttributes": {
|
||||||
|
// "5001": {
|
||||||
|
// "protocol": "https"
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// Use 'postCreateCommand' to run commands after the container is created.
|
||||||
|
// "postCreateCommand": "dotnet restore",
|
||||||
|
|
||||||
|
// Configure tool-specific properties.
|
||||||
|
// "customizations": {},
|
||||||
|
|
||||||
|
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
|
||||||
|
// "remoteUser": "root"
|
||||||
|
}
|
||||||
484
.gitignore
vendored
Normal file
484
.gitignore
vendored
Normal file
@@ -0,0 +1,484 @@
|
|||||||
|
## Ignore Visual Studio temporary files, build results, and
|
||||||
|
## files generated by popular Visual Studio add-ons.
|
||||||
|
##
|
||||||
|
## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
|
||||||
|
|
||||||
|
# User-specific files
|
||||||
|
*.rsuser
|
||||||
|
*.suo
|
||||||
|
*.user
|
||||||
|
*.userosscache
|
||||||
|
*.sln.docstates
|
||||||
|
|
||||||
|
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||||
|
*.userprefs
|
||||||
|
|
||||||
|
# Mono auto generated files
|
||||||
|
mono_crash.*
|
||||||
|
|
||||||
|
# Build results
|
||||||
|
[Dd]ebug/
|
||||||
|
[Dd]ebugPublic/
|
||||||
|
[Rr]elease/
|
||||||
|
[Rr]eleases/
|
||||||
|
x64/
|
||||||
|
x86/
|
||||||
|
[Ww][Ii][Nn]32/
|
||||||
|
[Aa][Rr][Mm]/
|
||||||
|
[Aa][Rr][Mm]64/
|
||||||
|
bld/
|
||||||
|
[Bb]in/
|
||||||
|
[Oo]bj/
|
||||||
|
[Ll]og/
|
||||||
|
[Ll]ogs/
|
||||||
|
|
||||||
|
# Visual Studio 2015/2017 cache/options directory
|
||||||
|
.vs/
|
||||||
|
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||||
|
#wwwroot/
|
||||||
|
|
||||||
|
# Visual Studio 2017 auto generated files
|
||||||
|
Generated\ Files/
|
||||||
|
|
||||||
|
# MSTest test Results
|
||||||
|
[Tt]est[Rr]esult*/
|
||||||
|
[Bb]uild[Ll]og.*
|
||||||
|
|
||||||
|
# NUnit
|
||||||
|
*.VisualState.xml
|
||||||
|
TestResult.xml
|
||||||
|
nunit-*.xml
|
||||||
|
|
||||||
|
# Build Results of an ATL Project
|
||||||
|
[Dd]ebugPS/
|
||||||
|
[Rr]eleasePS/
|
||||||
|
dlldata.c
|
||||||
|
|
||||||
|
# Benchmark Results
|
||||||
|
BenchmarkDotNet.Artifacts/
|
||||||
|
|
||||||
|
# .NET
|
||||||
|
project.lock.json
|
||||||
|
project.fragment.lock.json
|
||||||
|
artifacts/
|
||||||
|
|
||||||
|
# Tye
|
||||||
|
.tye/
|
||||||
|
|
||||||
|
# ASP.NET Scaffolding
|
||||||
|
ScaffoldingReadMe.txt
|
||||||
|
|
||||||
|
# StyleCop
|
||||||
|
StyleCopReport.xml
|
||||||
|
|
||||||
|
# Files built by Visual Studio
|
||||||
|
*_i.c
|
||||||
|
*_p.c
|
||||||
|
*_h.h
|
||||||
|
*.ilk
|
||||||
|
*.meta
|
||||||
|
*.obj
|
||||||
|
*.iobj
|
||||||
|
*.pch
|
||||||
|
*.pdb
|
||||||
|
*.ipdb
|
||||||
|
*.pgc
|
||||||
|
*.pgd
|
||||||
|
*.rsp
|
||||||
|
*.sbr
|
||||||
|
*.tlb
|
||||||
|
*.tli
|
||||||
|
*.tlh
|
||||||
|
*.tmp
|
||||||
|
*.tmp_proj
|
||||||
|
*_wpftmp.csproj
|
||||||
|
*.log
|
||||||
|
*.tlog
|
||||||
|
*.vspscc
|
||||||
|
*.vssscc
|
||||||
|
.builds
|
||||||
|
*.pidb
|
||||||
|
*.svclog
|
||||||
|
*.scc
|
||||||
|
|
||||||
|
# Chutzpah Test files
|
||||||
|
_Chutzpah*
|
||||||
|
|
||||||
|
# Visual C++ cache files
|
||||||
|
ipch/
|
||||||
|
*.aps
|
||||||
|
*.ncb
|
||||||
|
*.opendb
|
||||||
|
*.opensdf
|
||||||
|
*.sdf
|
||||||
|
*.cachefile
|
||||||
|
*.VC.db
|
||||||
|
*.VC.VC.opendb
|
||||||
|
|
||||||
|
# Visual Studio profiler
|
||||||
|
*.psess
|
||||||
|
*.vsp
|
||||||
|
*.vspx
|
||||||
|
*.sap
|
||||||
|
|
||||||
|
# Visual Studio Trace Files
|
||||||
|
*.e2e
|
||||||
|
|
||||||
|
# TFS 2012 Local Workspace
|
||||||
|
$tf/
|
||||||
|
|
||||||
|
# Guidance Automation Toolkit
|
||||||
|
*.gpState
|
||||||
|
|
||||||
|
# ReSharper is a .NET coding add-in
|
||||||
|
_ReSharper*/
|
||||||
|
*.[Rr]e[Ss]harper
|
||||||
|
*.DotSettings.user
|
||||||
|
|
||||||
|
# TeamCity is a build add-in
|
||||||
|
_TeamCity*
|
||||||
|
|
||||||
|
# DotCover is a Code Coverage Tool
|
||||||
|
*.dotCover
|
||||||
|
|
||||||
|
# AxoCover is a Code Coverage Tool
|
||||||
|
.axoCover/*
|
||||||
|
!.axoCover/settings.json
|
||||||
|
|
||||||
|
# Coverlet is a free, cross platform Code Coverage Tool
|
||||||
|
coverage*.json
|
||||||
|
coverage*.xml
|
||||||
|
coverage*.info
|
||||||
|
|
||||||
|
# Visual Studio code coverage results
|
||||||
|
*.coverage
|
||||||
|
*.coveragexml
|
||||||
|
|
||||||
|
# NCrunch
|
||||||
|
_NCrunch_*
|
||||||
|
.*crunch*.local.xml
|
||||||
|
nCrunchTemp_*
|
||||||
|
|
||||||
|
# MightyMoose
|
||||||
|
*.mm.*
|
||||||
|
AutoTest.Net/
|
||||||
|
|
||||||
|
# Web workbench (sass)
|
||||||
|
.sass-cache/
|
||||||
|
|
||||||
|
# Installshield output folder
|
||||||
|
[Ee]xpress/
|
||||||
|
|
||||||
|
# DocProject is a documentation generator add-in
|
||||||
|
DocProject/buildhelp/
|
||||||
|
DocProject/Help/*.HxT
|
||||||
|
DocProject/Help/*.HxC
|
||||||
|
DocProject/Help/*.hhc
|
||||||
|
DocProject/Help/*.hhk
|
||||||
|
DocProject/Help/*.hhp
|
||||||
|
DocProject/Help/Html2
|
||||||
|
DocProject/Help/html
|
||||||
|
|
||||||
|
# Click-Once directory
|
||||||
|
publish/
|
||||||
|
|
||||||
|
# Publish Web Output
|
||||||
|
*.[Pp]ublish.xml
|
||||||
|
*.azurePubxml
|
||||||
|
# Note: Comment the next line if you want to checkin your web deploy settings,
|
||||||
|
# but database connection strings (with potential passwords) will be unencrypted
|
||||||
|
*.pubxml
|
||||||
|
*.publishproj
|
||||||
|
|
||||||
|
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
||||||
|
# checkin your Azure Web App publish settings, but sensitive information contained
|
||||||
|
# in these scripts will be unencrypted
|
||||||
|
PublishScripts/
|
||||||
|
|
||||||
|
# NuGet Packages
|
||||||
|
*.nupkg
|
||||||
|
# NuGet Symbol Packages
|
||||||
|
*.snupkg
|
||||||
|
# The packages folder can be ignored because of Package Restore
|
||||||
|
**/[Pp]ackages/*
|
||||||
|
# except build/, which is used as an MSBuild target.
|
||||||
|
!**/[Pp]ackages/build/
|
||||||
|
# Uncomment if necessary however generally it will be regenerated when needed
|
||||||
|
#!**/[Pp]ackages/repositories.config
|
||||||
|
# NuGet v3's project.json files produces more ignorable files
|
||||||
|
*.nuget.props
|
||||||
|
*.nuget.targets
|
||||||
|
|
||||||
|
# Microsoft Azure Build Output
|
||||||
|
csx/
|
||||||
|
*.build.csdef
|
||||||
|
|
||||||
|
# Microsoft Azure Emulator
|
||||||
|
ecf/
|
||||||
|
rcf/
|
||||||
|
|
||||||
|
# Windows Store app package directories and files
|
||||||
|
AppPackages/
|
||||||
|
BundleArtifacts/
|
||||||
|
Package.StoreAssociation.xml
|
||||||
|
_pkginfo.txt
|
||||||
|
*.appx
|
||||||
|
*.appxbundle
|
||||||
|
*.appxupload
|
||||||
|
|
||||||
|
# Visual Studio cache files
|
||||||
|
# files ending in .cache can be ignored
|
||||||
|
*.[Cc]ache
|
||||||
|
# but keep track of directories ending in .cache
|
||||||
|
!?*.[Cc]ache/
|
||||||
|
|
||||||
|
# Others
|
||||||
|
ClientBin/
|
||||||
|
~$*
|
||||||
|
*~
|
||||||
|
*.dbmdl
|
||||||
|
*.dbproj.schemaview
|
||||||
|
*.jfm
|
||||||
|
*.pfx
|
||||||
|
*.publishsettings
|
||||||
|
orleans.codegen.cs
|
||||||
|
|
||||||
|
# Including strong name files can present a security risk
|
||||||
|
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
|
||||||
|
#*.snk
|
||||||
|
|
||||||
|
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
||||||
|
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
||||||
|
#bower_components/
|
||||||
|
|
||||||
|
# RIA/Silverlight projects
|
||||||
|
Generated_Code/
|
||||||
|
|
||||||
|
# Backup & report files from converting an old project file
|
||||||
|
# to a newer Visual Studio version. Backup files are not needed,
|
||||||
|
# because we have git ;-)
|
||||||
|
_UpgradeReport_Files/
|
||||||
|
Backup*/
|
||||||
|
UpgradeLog*.XML
|
||||||
|
UpgradeLog*.htm
|
||||||
|
ServiceFabricBackup/
|
||||||
|
*.rptproj.bak
|
||||||
|
|
||||||
|
# SQL Server files
|
||||||
|
*.mdf
|
||||||
|
*.ldf
|
||||||
|
*.ndf
|
||||||
|
|
||||||
|
# Business Intelligence projects
|
||||||
|
*.rdl.data
|
||||||
|
*.bim.layout
|
||||||
|
*.bim_*.settings
|
||||||
|
*.rptproj.rsuser
|
||||||
|
*- [Bb]ackup.rdl
|
||||||
|
*- [Bb]ackup ([0-9]).rdl
|
||||||
|
*- [Bb]ackup ([0-9][0-9]).rdl
|
||||||
|
|
||||||
|
# Microsoft Fakes
|
||||||
|
FakesAssemblies/
|
||||||
|
|
||||||
|
# GhostDoc plugin setting file
|
||||||
|
*.GhostDoc.xml
|
||||||
|
|
||||||
|
# Node.js Tools for Visual Studio
|
||||||
|
.ntvs_analysis.dat
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# Visual Studio 6 build log
|
||||||
|
*.plg
|
||||||
|
|
||||||
|
# Visual Studio 6 workspace options file
|
||||||
|
*.opt
|
||||||
|
|
||||||
|
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
|
||||||
|
*.vbw
|
||||||
|
|
||||||
|
# Visual Studio 6 auto-generated project file (contains which files were open etc.)
|
||||||
|
*.vbp
|
||||||
|
|
||||||
|
# Visual Studio 6 workspace and project file (working project files containing files to include in project)
|
||||||
|
*.dsw
|
||||||
|
*.dsp
|
||||||
|
|
||||||
|
# Visual Studio 6 technical files
|
||||||
|
*.ncb
|
||||||
|
*.aps
|
||||||
|
|
||||||
|
# Visual Studio LightSwitch build output
|
||||||
|
**/*.HTMLClient/GeneratedArtifacts
|
||||||
|
**/*.DesktopClient/GeneratedArtifacts
|
||||||
|
**/*.DesktopClient/ModelManifest.xml
|
||||||
|
**/*.Server/GeneratedArtifacts
|
||||||
|
**/*.Server/ModelManifest.xml
|
||||||
|
_Pvt_Extensions
|
||||||
|
|
||||||
|
# Paket dependency manager
|
||||||
|
.paket/paket.exe
|
||||||
|
paket-files/
|
||||||
|
|
||||||
|
# FAKE - F# Make
|
||||||
|
.fake/
|
||||||
|
|
||||||
|
# CodeRush personal settings
|
||||||
|
.cr/personal
|
||||||
|
|
||||||
|
# Python Tools for Visual Studio (PTVS)
|
||||||
|
__pycache__/
|
||||||
|
*.pyc
|
||||||
|
|
||||||
|
# Cake - Uncomment if you are using it
|
||||||
|
# tools/**
|
||||||
|
# !tools/packages.config
|
||||||
|
|
||||||
|
# Tabs Studio
|
||||||
|
*.tss
|
||||||
|
|
||||||
|
# Telerik's JustMock configuration file
|
||||||
|
*.jmconfig
|
||||||
|
|
||||||
|
# BizTalk build output
|
||||||
|
*.btp.cs
|
||||||
|
*.btm.cs
|
||||||
|
*.odx.cs
|
||||||
|
*.xsd.cs
|
||||||
|
|
||||||
|
# OpenCover UI analysis results
|
||||||
|
OpenCover/
|
||||||
|
|
||||||
|
# Azure Stream Analytics local run output
|
||||||
|
ASALocalRun/
|
||||||
|
|
||||||
|
# MSBuild Binary and Structured Log
|
||||||
|
*.binlog
|
||||||
|
|
||||||
|
# NVidia Nsight GPU debugger configuration file
|
||||||
|
*.nvuser
|
||||||
|
|
||||||
|
# MFractors (Xamarin productivity tool) working folder
|
||||||
|
.mfractor/
|
||||||
|
|
||||||
|
# Local History for Visual Studio
|
||||||
|
.localhistory/
|
||||||
|
|
||||||
|
# Visual Studio History (VSHistory) files
|
||||||
|
.vshistory/
|
||||||
|
|
||||||
|
# BeatPulse healthcheck temp database
|
||||||
|
healthchecksdb
|
||||||
|
|
||||||
|
# Backup folder for Package Reference Convert tool in Visual Studio 2017
|
||||||
|
MigrationBackup/
|
||||||
|
|
||||||
|
# Ionide (cross platform F# VS Code tools) working folder
|
||||||
|
.ionide/
|
||||||
|
|
||||||
|
# Fody - auto-generated XML schema
|
||||||
|
FodyWeavers.xsd
|
||||||
|
|
||||||
|
# VS Code files for those working on multiple tools
|
||||||
|
.vscode/*
|
||||||
|
!.vscode/settings.json
|
||||||
|
!.vscode/tasks.json
|
||||||
|
!.vscode/launch.json
|
||||||
|
!.vscode/extensions.json
|
||||||
|
*.code-workspace
|
||||||
|
|
||||||
|
# Local History for Visual Studio Code
|
||||||
|
.history/
|
||||||
|
|
||||||
|
# Windows Installer files from build outputs
|
||||||
|
*.cab
|
||||||
|
*.msi
|
||||||
|
*.msix
|
||||||
|
*.msm
|
||||||
|
*.msp
|
||||||
|
|
||||||
|
# JetBrains Rider
|
||||||
|
*.sln.iml
|
||||||
|
|
||||||
|
##
|
||||||
|
## Visual studio for Mac
|
||||||
|
##
|
||||||
|
|
||||||
|
|
||||||
|
# globs
|
||||||
|
Makefile.in
|
||||||
|
*.userprefs
|
||||||
|
*.usertasks
|
||||||
|
config.make
|
||||||
|
config.status
|
||||||
|
aclocal.m4
|
||||||
|
install-sh
|
||||||
|
autom4te.cache/
|
||||||
|
*.tar.gz
|
||||||
|
tarballs/
|
||||||
|
test-results/
|
||||||
|
|
||||||
|
# Mac bundle stuff
|
||||||
|
*.dmg
|
||||||
|
*.app
|
||||||
|
|
||||||
|
# content below from: https://github.com/github/gitignore/blob/master/Global/macOS.gitignore
|
||||||
|
# General
|
||||||
|
.DS_Store
|
||||||
|
.AppleDouble
|
||||||
|
.LSOverride
|
||||||
|
|
||||||
|
# Icon must end with two \r
|
||||||
|
Icon
|
||||||
|
|
||||||
|
|
||||||
|
# Thumbnails
|
||||||
|
._*
|
||||||
|
|
||||||
|
# Files that might appear in the root of a volume
|
||||||
|
.DocumentRevisions-V100
|
||||||
|
.fseventsd
|
||||||
|
.Spotlight-V100
|
||||||
|
.TemporaryItems
|
||||||
|
.Trashes
|
||||||
|
.VolumeIcon.icns
|
||||||
|
.com.apple.timemachine.donotpresent
|
||||||
|
|
||||||
|
# Directories potentially created on remote AFP share
|
||||||
|
.AppleDB
|
||||||
|
.AppleDesktop
|
||||||
|
Network Trash Folder
|
||||||
|
Temporary Items
|
||||||
|
.apdisk
|
||||||
|
|
||||||
|
# content below from: https://github.com/github/gitignore/blob/master/Global/Windows.gitignore
|
||||||
|
# Windows thumbnail cache files
|
||||||
|
Thumbs.db
|
||||||
|
ehthumbs.db
|
||||||
|
ehthumbs_vista.db
|
||||||
|
|
||||||
|
# Dump file
|
||||||
|
*.stackdump
|
||||||
|
|
||||||
|
# Folder config file
|
||||||
|
[Dd]esktop.ini
|
||||||
|
|
||||||
|
# Recycle Bin used on file shares
|
||||||
|
$RECYCLE.BIN/
|
||||||
|
|
||||||
|
# Windows Installer files
|
||||||
|
*.cab
|
||||||
|
*.msi
|
||||||
|
*.msix
|
||||||
|
*.msm
|
||||||
|
*.msp
|
||||||
|
|
||||||
|
# Windows shortcuts
|
||||||
|
*.lnk
|
||||||
|
|
||||||
|
|
||||||
|
app/
|
||||||
|
example/
|
||||||
|
testapp/
|
||||||
|
testgen/
|
||||||
|
tmp/
|
||||||
233
ResourceString.Net.Contract/Class1.cs
Normal file
233
ResourceString.Net.Contract/Class1.cs
Normal file
@@ -0,0 +1,233 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Resources;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
|
namespace ResourceString.Net.Contract
|
||||||
|
{
|
||||||
|
public interface IResourceString
|
||||||
|
{
|
||||||
|
|
||||||
|
string Value { get; }
|
||||||
|
|
||||||
|
string GetValue(CultureInfo cultureInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
public class LiteralString : IResourceString
|
||||||
|
{
|
||||||
|
private Lazy<string> m_Value;
|
||||||
|
|
||||||
|
public string Value => m_Value.Value;
|
||||||
|
|
||||||
|
public static IResourceString Empty {get;} = Factory(string.Empty);
|
||||||
|
public static IResourceString Factory(string source)
|
||||||
|
{
|
||||||
|
return new LiteralString(() => source);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LiteralString(Func<string> factory)
|
||||||
|
{
|
||||||
|
m_Value = new Lazy<string>(
|
||||||
|
() => factory?.Invoke() ?? string.Empty,
|
||||||
|
LazyThreadSafetyMode.PublicationOnly
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetValue(CultureInfo _) => Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ResourceManagerString : IResourceString
|
||||||
|
{
|
||||||
|
private readonly CultureInfo m_Culture;
|
||||||
|
|
||||||
|
public string Id { get; }
|
||||||
|
|
||||||
|
public ResourceManager Manager { get; }
|
||||||
|
|
||||||
|
public string Value => GetValue(m_Culture);
|
||||||
|
|
||||||
|
public ResourceManagerString(
|
||||||
|
string id,
|
||||||
|
ResourceManager manager,
|
||||||
|
CultureInfo cultureInfo)
|
||||||
|
{
|
||||||
|
Id = id ?? string.Empty;
|
||||||
|
Manager = manager ?? throw new ArgumentNullException(nameof(manager));
|
||||||
|
m_Culture = cultureInfo ?? CultureInfo.CurrentCulture;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetValue(CultureInfo cultureInfo)
|
||||||
|
{
|
||||||
|
return Manager.GetString(Id, cultureInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class FormattableResourceString : IResourceString
|
||||||
|
{
|
||||||
|
public IResourceString Format { get; }
|
||||||
|
|
||||||
|
public IEnumerable<IResourceString> Parameters { get; }
|
||||||
|
|
||||||
|
public string Value => GetValue(CultureInfo.CurrentCulture);
|
||||||
|
|
||||||
|
public FormattableResourceString(
|
||||||
|
IResourceString format,
|
||||||
|
params IResourceString[] parameters)
|
||||||
|
{
|
||||||
|
Format = format ?? new JoinedResourceString(
|
||||||
|
LiteralString.Factory(","),
|
||||||
|
parameters.Select(((p, idx) => LiteralString.Factory("{" + idx + "}"))).ToArray()
|
||||||
|
);
|
||||||
|
|
||||||
|
Parameters = parameters;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetValue(CultureInfo cultureInfo)
|
||||||
|
{
|
||||||
|
var format = Format.GetValue(cultureInfo);
|
||||||
|
var parameterStrings = Parameters.Select(p => p.GetValue(cultureInfo));
|
||||||
|
return string.Format(format, parameterStrings.ToArray());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class JoinedResourceString : IResourceString
|
||||||
|
{
|
||||||
|
public IResourceString Separator { get; }
|
||||||
|
|
||||||
|
public IEnumerable<IResourceString> Elements { get; }
|
||||||
|
|
||||||
|
public string Value => GetValue(CultureInfo.CurrentCulture);
|
||||||
|
|
||||||
|
public JoinedResourceString(
|
||||||
|
IResourceString separator,
|
||||||
|
params IResourceString[] elements)
|
||||||
|
{
|
||||||
|
Separator = separator ?? new LiteralString(
|
||||||
|
() => ","
|
||||||
|
);
|
||||||
|
|
||||||
|
Elements = elements;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetValue(CultureInfo cultureInfo)
|
||||||
|
{
|
||||||
|
var separator = Separator.GetValue(cultureInfo);
|
||||||
|
var elementsStrings = Elements.Select(p => p.GetValue(cultureInfo));
|
||||||
|
return string.Join(separator, elementsStrings);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static class ResourceStrings
|
||||||
|
{
|
||||||
|
private static readonly ResourceManager ResourceManager = new ResourceManager(typeof(int));
|
||||||
|
|
||||||
|
private static readonly Lazy<ResourceManagerString> LazyEntry = new Lazy<ResourceManagerString>(
|
||||||
|
() => new ResourceManagerString("EntryId", ResourceManager, CultureInfo.CurrentCulture),
|
||||||
|
LazyThreadSafetyMode.PublicationOnly
|
||||||
|
);
|
||||||
|
|
||||||
|
public static ResourceManagerString Entry => LazyEntry.Value;
|
||||||
|
|
||||||
|
public static class FormattedEntry
|
||||||
|
{
|
||||||
|
private static readonly Lazy<ResourceManagerString> Value = new Lazy<ResourceManagerString>(
|
||||||
|
() => new ResourceManagerString("FormatEntryId", ResourceManager, CultureInfo.CurrentCulture),
|
||||||
|
LazyThreadSafetyMode.PublicationOnly
|
||||||
|
);
|
||||||
|
|
||||||
|
public static string Id => Value.Value.Id;
|
||||||
|
|
||||||
|
public static ResourceManager Manager => Value.Value.Manager;
|
||||||
|
|
||||||
|
public static IResourceString Format => Value.Value;
|
||||||
|
|
||||||
|
public static IResourceString From(IResourceString p0, IResourceString p1) => new FormattableResourceString(
|
||||||
|
Format,
|
||||||
|
p0,
|
||||||
|
p1
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
static IEnumerable<IResourceString> test(IResourceReader r)
|
||||||
|
{
|
||||||
|
var enumerator = r.GetEnumerator();
|
||||||
|
|
||||||
|
var dict = enumerator.ToDictionary<string, string>();
|
||||||
|
|
||||||
|
return dict.Select(e =>new LiteralString(() => CreateString(e)));
|
||||||
|
|
||||||
|
string CreateString(KeyValuePair<string, string> entry)
|
||||||
|
{
|
||||||
|
var key = entry.Key;
|
||||||
|
var keyName = key.Replace(" ", "").Trim();
|
||||||
|
return @$"
|
||||||
|
private static readonly Lazy<ResourceString> Lazy{keyName} = new Lazy<ResourceString>(
|
||||||
|
() => new ResourceString(""{key}"", ResourceManager, CultureInfo.CurrentCulture),
|
||||||
|
LazyThreadSafetyMode.PublicationOnly
|
||||||
|
);
|
||||||
|
|
||||||
|
public static ResourceString {keyName} => Lazy{keyName}.Value;
|
||||||
|
";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Hello
|
||||||
|
{
|
||||||
|
public static IResourceString Format { get; } = LiteralString.Factory("{0}, {1} !!!");
|
||||||
|
|
||||||
|
public static IResourceString Value { get; } = LiteralString.Factory("Hello");
|
||||||
|
|
||||||
|
public static IResourceString From(IResourceString name) => new FormattableResourceString(
|
||||||
|
Format,
|
||||||
|
Value,
|
||||||
|
name
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class HelloWorld
|
||||||
|
{
|
||||||
|
public static IResourceString Value { get; } = Hello.From(World);
|
||||||
|
|
||||||
|
public static IResourceString From(IResourceString name) => new FormattableResourceString(
|
||||||
|
Hello.Format,
|
||||||
|
Value,
|
||||||
|
name
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IResourceString World { get; } = LiteralString.Factory("World");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Extensions
|
||||||
|
{
|
||||||
|
public static IDictionary<TKey, TValue> ToDictionary<TKey, TValue>(this IDictionaryEnumerator source)
|
||||||
|
{
|
||||||
|
return source.Collect<TKey, TValue>().ToDictionary(k => k.Key, v => v.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IEnumerable<KeyValuePair<TKey, TValue>> Collect<TKey, TValue>(this IDictionaryEnumerator source)
|
||||||
|
{
|
||||||
|
if (source is null)
|
||||||
|
{
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (source.MoveNext())
|
||||||
|
{
|
||||||
|
if (source.Key is TKey key && source.Value is TValue value)
|
||||||
|
{
|
||||||
|
yield return new KeyValuePair<TKey, TValue>(
|
||||||
|
key,
|
||||||
|
value
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netstandard2.0</TargetFramework>
|
||||||
|
<LangVersion>latest</LangVersion>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
68
ResourceString.Net.Logic.Tests/LogicResourcesTests.cs
Normal file
68
ResourceString.Net.Logic.Tests/LogicResourcesTests.cs
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
using ResourceString.Net.Logic.Factories;
|
||||||
|
|
||||||
|
namespace ResourceString.Net.Logic.Tests;
|
||||||
|
|
||||||
|
[TestClass]
|
||||||
|
public class LogicResourcesTests
|
||||||
|
{
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Test_Get_ResourceStringMembers()
|
||||||
|
{
|
||||||
|
var rm = Properties.Resources.ResourceManager;
|
||||||
|
Assert.AreEqual(
|
||||||
|
new FormattableResourceString(
|
||||||
|
Properties.Resources.ResourceStringMembers,
|
||||||
|
LiteralString.Factory("ResourceStringMembers"),
|
||||||
|
LiteralString.Factory("ResourceManager")
|
||||||
|
).Value,
|
||||||
|
string.Format(
|
||||||
|
rm.GetString("ResourceStringMembers") ?? string.Empty,
|
||||||
|
"ResourceStringMembers",
|
||||||
|
"ResourceManager"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Test_Get_ResourceManagerMemberTemplate()
|
||||||
|
{
|
||||||
|
var rm = Properties.Resources.ResourceManager;
|
||||||
|
Assert.AreEqual(
|
||||||
|
CodeSnippetFactory.CreateResourceMangerMemberCodeSnippet(
|
||||||
|
"Resources"
|
||||||
|
).Value,
|
||||||
|
string.Format(
|
||||||
|
rm.GetString("ResourceManagerMemberTemplate") ?? string.Empty,
|
||||||
|
"Resources"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Test_Get_ResourcesClassTemplate()
|
||||||
|
{
|
||||||
|
var rm = Properties.Resources.ResourceManager;
|
||||||
|
|
||||||
|
var rmSnippet = CodeSnippetFactory.CreateResourceMangerMemberCodeSnippet(
|
||||||
|
"Resources"
|
||||||
|
);
|
||||||
|
|
||||||
|
Assert.AreEqual(
|
||||||
|
CodeSnippetFactory.CreateResourceClassCodeSnippet(
|
||||||
|
"ResourceString.Net.Logic.Properties",
|
||||||
|
"Resources",
|
||||||
|
rmSnippet,
|
||||||
|
Enumerable.Empty<IResourceString>()
|
||||||
|
).Value,
|
||||||
|
string.Format(
|
||||||
|
rm.GetString("ResourcesClassTemplate") ?? string.Empty,
|
||||||
|
"ResourceString.Net.Logic.Properties",
|
||||||
|
"Resources",
|
||||||
|
rmSnippet.Value,
|
||||||
|
string.Empty
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net7.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<LangVersion>latest</LangVersion>
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
|
||||||
|
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
|
||||||
|
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
|
||||||
|
<PackageReference Include="coverlet.collector" Version="3.1.2">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\ResourceString.Net.Logic\ResourceString.Net.Logic.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
175
ResourceString.Net.Logic.Tests/ResxFileTests.cs
Normal file
175
ResourceString.Net.Logic.Tests/ResxFileTests.cs
Normal file
@@ -0,0 +1,175 @@
|
|||||||
|
using ResourceString.Net.Logic.DomainObjects.Resx;
|
||||||
|
using ResourceString.Net.Logic.Factories;
|
||||||
|
using ResourceString.Net.Logic.Parsers.Resx;
|
||||||
|
|
||||||
|
namespace ResourceString.Net.Logic.Tests;
|
||||||
|
|
||||||
|
[TestClass]
|
||||||
|
public class ResxFileTests
|
||||||
|
{
|
||||||
|
private readonly string validXml = @$"<?xml version='1.0' encoding='utf-8'?>
|
||||||
|
<root>
|
||||||
|
<data name='Test1'>
|
||||||
|
<value>Value1</value>
|
||||||
|
</data>
|
||||||
|
<data name='Test2' type='{typeof(int).FullName}'>
|
||||||
|
<value>Value2</value>
|
||||||
|
</data>
|
||||||
|
</root>";
|
||||||
|
|
||||||
|
private const string expectedClass = @"
|
||||||
|
using ResourceString.Net.Contract;
|
||||||
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Resources;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
|
namespace TestNameSpace
|
||||||
|
{
|
||||||
|
internal static class TestResourceClass
|
||||||
|
{
|
||||||
|
|
||||||
|
#region ResourceManager
|
||||||
|
|
||||||
|
private static readonly Type _Type = typeof(ResourceManager);
|
||||||
|
|
||||||
|
private static readonly Lazy<ResourceManager> _ResourceManager = new Lazy<ResourceManager>(
|
||||||
|
() => new ResourceManager(_Type.FullName, _Type.Assembly),
|
||||||
|
LazyThreadSafetyMode.PublicationOnly
|
||||||
|
);
|
||||||
|
|
||||||
|
public static ResourceManager ResourceManager => _ResourceManager.Value;
|
||||||
|
|
||||||
|
#endregion // ResourceManager
|
||||||
|
|
||||||
|
|
||||||
|
#region Test1
|
||||||
|
|
||||||
|
private static readonly Lazy<IResourceString> LazyTest1 = new Lazy<IResourceString>(
|
||||||
|
() => new ResourceManagerString(""Test1"", ResourceManager, CultureInfo.CurrentCulture),
|
||||||
|
LazyThreadSafetyMode.PublicationOnly
|
||||||
|
);
|
||||||
|
|
||||||
|
public static IResourceString Test1 => LazyTest1.Value;
|
||||||
|
|
||||||
|
#endregion // Test1
|
||||||
|
|
||||||
|
#region Test2
|
||||||
|
|
||||||
|
private static readonly Lazy<IResourceString> LazyTest2 = new Lazy<IResourceString>(
|
||||||
|
() => new ResourceManagerString(""Test2"", ResourceManager, CultureInfo.CurrentCulture),
|
||||||
|
LazyThreadSafetyMode.PublicationOnly
|
||||||
|
);
|
||||||
|
|
||||||
|
public static IResourceString Test2 => LazyTest2.Value;
|
||||||
|
|
||||||
|
#endregion // Test2
|
||||||
|
|
||||||
|
}
|
||||||
|
}";
|
||||||
|
|
||||||
|
private readonly string emptyXml = @"<?xml version='1.0' encoding='utf-8'?><root></root>";
|
||||||
|
|
||||||
|
private readonly string invalidXml = @"<?xml version='1.0' encoding='utf-8'?><root></data>";
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Test_TryParse_ValidXml()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var expectedData = new[] {
|
||||||
|
("Test1", "Value1", string.Empty),
|
||||||
|
("Test2", "Value2", typeof(int).FullName)
|
||||||
|
};
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = Parser.TryParse(validXml).Match(
|
||||||
|
Some: v => v.Resources,
|
||||||
|
None: () => throw new InvalidOperationException()
|
||||||
|
);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
CollectionAssert.AreEqual(
|
||||||
|
expectedData,
|
||||||
|
result.Select(i => (i.Name, i.Value, i.Type.IfNone(string.Empty))).ToList()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Test_TryParse_EmptyXml()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var expectedData = Enumerable.Empty<Resource>();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var isSome = Parser.TryParse(emptyXml).Match(
|
||||||
|
Some: _ => true,
|
||||||
|
None: () => false
|
||||||
|
);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.IsFalse(isSome);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Test_TryParse_InValidXml()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var expectedData = Enumerable.Empty<Resource>();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var isSome = Parser.TryParse(invalidXml).Match(
|
||||||
|
Some: _ => true,
|
||||||
|
None: () => false
|
||||||
|
);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.IsFalse(isSome);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Test_ToMemberString()
|
||||||
|
{
|
||||||
|
// Act
|
||||||
|
var result = Parser.TryParse(validXml).Match(
|
||||||
|
Some: v => CodeSnippetFactory.CreateMemberCodeSnippets(v.Resources),
|
||||||
|
None: () => throw new InvalidOperationException()
|
||||||
|
);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.AreEqual(2, result.Count());
|
||||||
|
|
||||||
|
Assert.AreEqual(
|
||||||
|
"#region Test1",
|
||||||
|
result.Select(i => i.Value.Substring(0, 25).Trim()).ToList()[0]
|
||||||
|
);
|
||||||
|
|
||||||
|
Assert.AreEqual(
|
||||||
|
"#region Test2",
|
||||||
|
result.Select(i => i.Value.Substring(0, 25).Trim()).ToList()[1]
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Test_ToClassString()
|
||||||
|
{
|
||||||
|
// Act
|
||||||
|
var result = Parser.TryParse(validXml).Match(
|
||||||
|
Some: v => CodeSnippetFactory.CreateResourceClassCodeSnippet(
|
||||||
|
"TestNameSpace",
|
||||||
|
"TestResourceClass",
|
||||||
|
CodeSnippetFactory.CreateResourceMangerMemberCodeSnippet("ResourceManager"),
|
||||||
|
v.Resources
|
||||||
|
),
|
||||||
|
None: () => throw new InvalidOperationException()
|
||||||
|
);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.AreEqual(
|
||||||
|
expectedClass.Trim(),
|
||||||
|
result.Value.Trim()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
4
ResourceString.Net.Logic.Tests/Usings.cs
Normal file
4
ResourceString.Net.Logic.Tests/Usings.cs
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
global using LanguageExt;
|
||||||
|
global using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
global using ResourceString.Net.Contract;
|
||||||
|
global using ResourceString.Net.Logic;
|
||||||
16
ResourceString.Net.Logic/DomainObjects/Resx/File.cs
Normal file
16
ResourceString.Net.Logic/DomainObjects/Resx/File.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace ResourceString.Net.Logic.DomainObjects.Resx;
|
||||||
|
|
||||||
|
internal record File
|
||||||
|
{
|
||||||
|
public File(IEnumerable<Resource> resources)
|
||||||
|
{
|
||||||
|
Resources = new Seq<Resource>(
|
||||||
|
resources?.Where(o => o != null) ?? Enumerable.Empty<Resource>()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<Resource> Resources { get; }
|
||||||
|
}
|
||||||
16
ResourceString.Net.Logic/DomainObjects/Resx/Resource.cs
Normal file
16
ResourceString.Net.Logic/DomainObjects/Resx/Resource.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
namespace ResourceString.Net.Logic.DomainObjects.Resx;
|
||||||
|
|
||||||
|
internal record Resource
|
||||||
|
{
|
||||||
|
public Resource(string name, string value)
|
||||||
|
{
|
||||||
|
Name = name ?? string.Empty;
|
||||||
|
Value = value ?? string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Name { get;}
|
||||||
|
|
||||||
|
public Option<string> Type { get; init;}
|
||||||
|
|
||||||
|
public string Value { get; }
|
||||||
|
}
|
||||||
80
ResourceString.Net.Logic/Factories/CodeSnippetFactory.cs
Normal file
80
ResourceString.Net.Logic/Factories/CodeSnippetFactory.cs
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
using ResourceString.Net.Logic.DomainObjects.Resx;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace ResourceString.Net.Logic.Factories;
|
||||||
|
|
||||||
|
internal static class CodeSnippetFactory
|
||||||
|
{
|
||||||
|
public static IResourceString CreateResourceMangerMemberCodeSnippet(string typeName)
|
||||||
|
{
|
||||||
|
var formatString = Properties.Resources.ResourceManagerMemberTemplate;
|
||||||
|
return new FormattableResourceString(
|
||||||
|
formatString,
|
||||||
|
LiteralString.Factory(typeName)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static IEnumerable<IResourceString> CreateMemberCodeSnippets(IEnumerable<Resource> resources)
|
||||||
|
{
|
||||||
|
return CreateMemberCodeSnippets(
|
||||||
|
resources,
|
||||||
|
Properties.Resources.DefaultPropertyName_ResourceManager
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IEnumerable<IResourceString> CreateMemberCodeSnippets(
|
||||||
|
IEnumerable<Resource> resources,
|
||||||
|
IResourceString resourceManagerName
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if (resources is null)
|
||||||
|
{
|
||||||
|
return Enumerable.Empty<IResourceString>();
|
||||||
|
}
|
||||||
|
|
||||||
|
var formatString = Properties.Resources.ResourceStringMembers;
|
||||||
|
return resources.Select(r => new FormattableResourceString(
|
||||||
|
formatString,
|
||||||
|
LiteralString.Factory(r.Name),
|
||||||
|
resourceManagerName
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IResourceString CreateResourceClassCodeSnippet(
|
||||||
|
string namespaceString,
|
||||||
|
string resourceClassName,
|
||||||
|
IResourceString resourceManagerSnippet,
|
||||||
|
IEnumerable<IResourceString> memberSnippets
|
||||||
|
)
|
||||||
|
{
|
||||||
|
var formatString = Properties.Resources.ResourcesClassTemplate;
|
||||||
|
return new FormattableResourceString(
|
||||||
|
formatString,
|
||||||
|
LiteralString.Factory(namespaceString),
|
||||||
|
LiteralString.Factory(resourceClassName),
|
||||||
|
resourceManagerSnippet,
|
||||||
|
new JoinedResourceString(
|
||||||
|
LiteralString.Empty,
|
||||||
|
memberSnippets?.ToArray() ?? Array.Empty<IResourceString>()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IResourceString CreateResourceClassCodeSnippet(
|
||||||
|
string namespaceString,
|
||||||
|
string resourceClassName,
|
||||||
|
IResourceString resourceManagerSnippet,
|
||||||
|
IEnumerable<Resource> resources
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return CreateResourceClassCodeSnippet(
|
||||||
|
namespaceString,
|
||||||
|
resourceClassName,
|
||||||
|
resourceManagerSnippet,
|
||||||
|
CreateMemberCodeSnippets(resources)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
3
ResourceString.Net.Logic/IsExternalInit.cs
Normal file
3
ResourceString.Net.Logic/IsExternalInit.cs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
namespace System.Runtime.CompilerServices;
|
||||||
|
|
||||||
|
internal static class IsExternalInit { }
|
||||||
38
ResourceString.Net.Logic/Parsers/Resx/Parser.cs
Normal file
38
ResourceString.Net.Logic/Parsers/Resx/Parser.cs
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
using ResourceString.Net.Logic.DomainObjects.Resx;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Xml;
|
||||||
|
|
||||||
|
namespace ResourceString.Net.Logic.Parsers.Resx;
|
||||||
|
|
||||||
|
internal static class Parser
|
||||||
|
{
|
||||||
|
public static Option<File> TryParse(string xmlString)
|
||||||
|
{
|
||||||
|
var doc = new XmlDocument();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
doc.LoadXml(xmlString);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return Option<File>.None;
|
||||||
|
}
|
||||||
|
|
||||||
|
var resources = doc.SelectNodes("descendant::data").OfType<XmlElement>().Select((i, _) =>
|
||||||
|
{
|
||||||
|
var name = i.GetAttribute("name");
|
||||||
|
var type = i.GetAttribute("type");
|
||||||
|
var value = i.SelectSingleNode("descendant::value")?.InnerXml;
|
||||||
|
|
||||||
|
return new Resource(name, value ?? string.Empty)
|
||||||
|
{
|
||||||
|
Type = type
|
||||||
|
};
|
||||||
|
}).ToArray();
|
||||||
|
|
||||||
|
return resources.Any()
|
||||||
|
? Option<File>.Some(new File(resources))
|
||||||
|
: Option<File>.None;
|
||||||
|
}
|
||||||
|
}
|
||||||
67
ResourceString.Net.Logic/Properties/Resources.cs
Normal file
67
ResourceString.Net.Logic/Properties/Resources.cs
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Resources;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
|
namespace ResourceString.Net.Logic.Properties
|
||||||
|
{
|
||||||
|
internal static class Resources
|
||||||
|
{
|
||||||
|
#region ResourceManager
|
||||||
|
|
||||||
|
private static readonly Type _Type = typeof(Resources);
|
||||||
|
|
||||||
|
private static readonly Lazy<ResourceManager> _ResourceManager = new Lazy<ResourceManager>(
|
||||||
|
() => new ResourceManager(_Type.FullName, _Type.Assembly),
|
||||||
|
LazyThreadSafetyMode.PublicationOnly
|
||||||
|
);
|
||||||
|
|
||||||
|
public static ResourceManager ResourceManager => _ResourceManager.Value;
|
||||||
|
|
||||||
|
#endregion // ResourceManager
|
||||||
|
|
||||||
|
#region ResourceStringMembers
|
||||||
|
|
||||||
|
private static readonly Lazy<IResourceString> LazyResourceStringMembers = new Lazy<IResourceString>(
|
||||||
|
() => new ResourceManagerString("ResourceStringMembers", ResourceManager, CultureInfo.CurrentCulture),
|
||||||
|
LazyThreadSafetyMode.PublicationOnly
|
||||||
|
);
|
||||||
|
|
||||||
|
public static IResourceString ResourceStringMembers => LazyResourceStringMembers.Value;
|
||||||
|
|
||||||
|
#endregion // ResourceStringMembers
|
||||||
|
|
||||||
|
#region ResourceManagerMemberTemplate
|
||||||
|
|
||||||
|
private static readonly Lazy<IResourceString> LazyResourceManagerMemberTemplate = new Lazy<IResourceString>(
|
||||||
|
() => new ResourceManagerString("ResourceManagerMemberTemplate", ResourceManager, CultureInfo.CurrentCulture),
|
||||||
|
LazyThreadSafetyMode.PublicationOnly
|
||||||
|
);
|
||||||
|
|
||||||
|
public static IResourceString ResourceManagerMemberTemplate => LazyResourceManagerMemberTemplate.Value;
|
||||||
|
|
||||||
|
#endregion // ResourceManagerMemberTemplate
|
||||||
|
|
||||||
|
#region ResourcesClassTemplate
|
||||||
|
|
||||||
|
private static readonly Lazy<IResourceString> LazyResourcesClassTemplate = new Lazy<IResourceString>(
|
||||||
|
() => new ResourceManagerString("ResourcesClassTemplate", ResourceManager, CultureInfo.CurrentCulture),
|
||||||
|
LazyThreadSafetyMode.PublicationOnly
|
||||||
|
);
|
||||||
|
|
||||||
|
public static IResourceString ResourcesClassTemplate => LazyResourcesClassTemplate.Value;
|
||||||
|
|
||||||
|
#endregion // ResourcesClassTemplate
|
||||||
|
|
||||||
|
#region DefaultPropertyName_ResourceManager
|
||||||
|
|
||||||
|
private static readonly Lazy<IResourceString> LazyDefaultPropertyName_ResourceManager = new Lazy<IResourceString>(
|
||||||
|
() => new ResourceManagerString("DefaultPropertyName_ResourceManager", ResourceManager, CultureInfo.CurrentCulture),
|
||||||
|
LazyThreadSafetyMode.PublicationOnly
|
||||||
|
);
|
||||||
|
|
||||||
|
public static IResourceString DefaultPropertyName_ResourceManager => LazyDefaultPropertyName_ResourceManager.Value;
|
||||||
|
|
||||||
|
#endregion // DefaultPropertyName_ResourceManager
|
||||||
|
}
|
||||||
|
}
|
||||||
54
ResourceString.Net.Logic/Properties/Resources.resx
Normal file
54
ResourceString.Net.Logic/Properties/Resources.resx
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<data name="ResourceStringMembers" xml:space="preserve">
|
||||||
|
<value>
|
||||||
|
#region {0}
|
||||||
|
|
||||||
|
private static readonly Lazy<IResourceString> Lazy{0} = new Lazy<IResourceString>(
|
||||||
|
() => new ResourceManagerString("{0}", {1}, CultureInfo.CurrentCulture),
|
||||||
|
LazyThreadSafetyMode.PublicationOnly
|
||||||
|
);
|
||||||
|
|
||||||
|
public static IResourceString {0} => Lazy{0}.Value;
|
||||||
|
|
||||||
|
#endregion // {0}
|
||||||
|
</value>
|
||||||
|
</data>
|
||||||
|
<data name="ResourcesClassTemplate" xml:space="preserve">
|
||||||
|
<value>
|
||||||
|
using ResourceString.Net.Contract;
|
||||||
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Resources;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
|
namespace {0}
|
||||||
|
{{
|
||||||
|
internal static class {1}
|
||||||
|
{{
|
||||||
|
{2}
|
||||||
|
{3}
|
||||||
|
}}
|
||||||
|
}}
|
||||||
|
</value>
|
||||||
|
</data>
|
||||||
|
<data name="ResourceManagerMemberTemplate" xml:space="preserve">
|
||||||
|
<value>
|
||||||
|
#region ResourceManager
|
||||||
|
|
||||||
|
private static readonly Type _Type = typeof({0});
|
||||||
|
|
||||||
|
private static readonly Lazy<ResourceManager> _ResourceManager = new Lazy<ResourceManager>(
|
||||||
|
() => new ResourceManager(_Type.FullName, _Type.Assembly),
|
||||||
|
LazyThreadSafetyMode.PublicationOnly
|
||||||
|
);
|
||||||
|
|
||||||
|
public static ResourceManager ResourceManager => _ResourceManager.Value;
|
||||||
|
|
||||||
|
#endregion // ResourceManager
|
||||||
|
</value>
|
||||||
|
</data>
|
||||||
|
<data name="DefaultPropertyName_ResourceManager">
|
||||||
|
<value>ResourceManager</value>
|
||||||
|
</data>
|
||||||
|
</root>
|
||||||
23
ResourceString.Net.Logic/ResourceString.Net.Logic.csproj
Normal file
23
ResourceString.Net.Logic/ResourceString.Net.Logic.csproj
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netstandard2.0</TargetFramework>
|
||||||
|
<LangVersion>latest</LangVersion>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="LanguageExt.Core" Version="4.4.2" />
|
||||||
|
<PackageReference Include="System.Resources.Extensions" Version="7.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\ResourceString.Net.Contract\ResourceString.Net.Contract.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
|
||||||
|
<_Parameter1>$(MSBuildProjectName).Tests</_Parameter1>
|
||||||
|
</AssemblyAttribute>
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
||||||
4
ResourceString.Net.Logic/Usings.cs
Normal file
4
ResourceString.Net.Logic/Usings.cs
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
global using LanguageExt;
|
||||||
|
|
||||||
|
global using ResourceString.Net.Contract;
|
||||||
|
|
||||||
Reference in New Issue
Block a user