diff --git a/ln.type.sln b/ln.type.sln new file mode 100644 index 0000000..6d70f7d --- /dev/null +++ b/ln.type.sln @@ -0,0 +1,48 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26124.0 +MinimumVisualStudioVersion = 15.0.26124.0 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ln.type", "ln.type\ln.type.csproj", "{98686C62-A822-4045-8403-A6CBD40E7EB3}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ln.type.tests", "ln.type.tests\ln.type.tests.csproj", "{EDFCB172-4EFD-4731-98CB-CB0E082F3204}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {98686C62-A822-4045-8403-A6CBD40E7EB3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {98686C62-A822-4045-8403-A6CBD40E7EB3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {98686C62-A822-4045-8403-A6CBD40E7EB3}.Debug|x64.ActiveCfg = Debug|Any CPU + {98686C62-A822-4045-8403-A6CBD40E7EB3}.Debug|x64.Build.0 = Debug|Any CPU + {98686C62-A822-4045-8403-A6CBD40E7EB3}.Debug|x86.ActiveCfg = Debug|Any CPU + {98686C62-A822-4045-8403-A6CBD40E7EB3}.Debug|x86.Build.0 = Debug|Any CPU + {98686C62-A822-4045-8403-A6CBD40E7EB3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {98686C62-A822-4045-8403-A6CBD40E7EB3}.Release|Any CPU.Build.0 = Release|Any CPU + {98686C62-A822-4045-8403-A6CBD40E7EB3}.Release|x64.ActiveCfg = Release|Any CPU + {98686C62-A822-4045-8403-A6CBD40E7EB3}.Release|x64.Build.0 = Release|Any CPU + {98686C62-A822-4045-8403-A6CBD40E7EB3}.Release|x86.ActiveCfg = Release|Any CPU + {98686C62-A822-4045-8403-A6CBD40E7EB3}.Release|x86.Build.0 = Release|Any CPU + {EDFCB172-4EFD-4731-98CB-CB0E082F3204}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EDFCB172-4EFD-4731-98CB-CB0E082F3204}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EDFCB172-4EFD-4731-98CB-CB0E082F3204}.Debug|x64.ActiveCfg = Debug|Any CPU + {EDFCB172-4EFD-4731-98CB-CB0E082F3204}.Debug|x64.Build.0 = Debug|Any CPU + {EDFCB172-4EFD-4731-98CB-CB0E082F3204}.Debug|x86.ActiveCfg = Debug|Any CPU + {EDFCB172-4EFD-4731-98CB-CB0E082F3204}.Debug|x86.Build.0 = Debug|Any CPU + {EDFCB172-4EFD-4731-98CB-CB0E082F3204}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EDFCB172-4EFD-4731-98CB-CB0E082F3204}.Release|Any CPU.Build.0 = Release|Any CPU + {EDFCB172-4EFD-4731-98CB-CB0E082F3204}.Release|x64.ActiveCfg = Release|Any CPU + {EDFCB172-4EFD-4731-98CB-CB0E082F3204}.Release|x64.Build.0 = Release|Any CPU + {EDFCB172-4EFD-4731-98CB-CB0E082F3204}.Release|x86.ActiveCfg = Release|Any CPU + {EDFCB172-4EFD-4731-98CB-CB0E082F3204}.Release|x86.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/ln.type.tests/URITests.cs b/ln.type.tests/URITests.cs new file mode 100644 index 0000000..49bd792 --- /dev/null +++ b/ln.type.tests/URITests.cs @@ -0,0 +1,41 @@ +using NUnit.Framework; + +namespace ln.type.tests +{ + public class URITests + { + [SetUp] + public void Setup() + { + } + + [Test] + public void Test1() + { + string testBaseURI = "http://alpha:beta:gamma@myHost:3456/path/to/resource?query=all#fragmentA"; + + URI testURI = new URI(testBaseURI); + Assert.AreEqual(testBaseURI, testURI.ToString(true)); + + Assert.AreEqual( + "http://omega@myHost:3456/path/to/resource?query=all#fragmentA", + testURI.WithUserInfo("omega").ToString(true) + ); + Assert.AreEqual( + "http://alpha:beta:gamma@myHost:3456/my/path?query=all#fragmentA", + testURI.WithPath("/my/path").ToString(true) + ); + Assert.AreEqual( + "http://alpha:beta:gamma@myHost:3456/path/to/resource?such=a&shame#fragmentA", + testURI.WithQuery("such=a&shame").ToString(true) + ); + Assert.AreEqual( + "https://alpha:beta:gamma@myHost:3456/path/to/resource?query=all#fragmentA", + testURI.WithScheme("https").ToString(true) + ); + + + Assert.Pass(); + } + } +} \ No newline at end of file diff --git a/ln.type.tests/ln.type.tests.csproj b/ln.type.tests/ln.type.tests.csproj new file mode 100644 index 0000000..9273211 --- /dev/null +++ b/ln.type.tests/ln.type.tests.csproj @@ -0,0 +1,16 @@ + + + + netcoreapp3.1 + + false + + + + + + + + + + diff --git a/ByteArrayExtensions.cs b/ln.type/ByteArrayExtensions.cs similarity index 100% rename from ByteArrayExtensions.cs rename to ln.type/ByteArrayExtensions.cs diff --git a/Cast.cs b/ln.type/Cast.cs similarity index 100% rename from Cast.cs rename to ln.type/Cast.cs diff --git a/Date.cs b/ln.type/Date.cs similarity index 100% rename from Date.cs rename to ln.type/Date.cs diff --git a/DvDt.cs b/ln.type/DvDt.cs similarity index 100% rename from DvDt.cs rename to ln.type/DvDt.cs diff --git a/Endpoint.cs b/ln.type/Endpoint.cs similarity index 100% rename from Endpoint.cs rename to ln.type/Endpoint.cs diff --git a/Extensions.cs b/ln.type/Extensions.cs similarity index 100% rename from Extensions.cs rename to ln.type/Extensions.cs diff --git a/Factory.cs b/ln.type/Factory.cs similarity index 100% rename from Factory.cs rename to ln.type/Factory.cs diff --git a/GeoLocation.cs b/ln.type/GeoLocation.cs similarity index 100% rename from GeoLocation.cs rename to ln.type/GeoLocation.cs diff --git a/IPv6.cs b/ln.type/IPv6.cs similarity index 100% rename from IPv6.cs rename to ln.type/IPv6.cs diff --git a/MAC.cs b/ln.type/MAC.cs similarity index 100% rename from MAC.cs rename to ln.type/MAC.cs diff --git a/Promise.cs b/ln.type/Promise.cs similarity index 100% rename from Promise.cs rename to ln.type/Promise.cs diff --git a/TypeExtensions.cs b/ln.type/TypeExtensions.cs similarity index 100% rename from TypeExtensions.cs rename to ln.type/TypeExtensions.cs diff --git a/URI.cs b/ln.type/URI.cs similarity index 81% rename from URI.cs rename to ln.type/URI.cs index f50d92c..f693a74 100644 --- a/URI.cs +++ b/ln.type/URI.cs @@ -8,6 +8,7 @@ // * // **/ using System; +using System.Reflection.Metadata; using System.Text; namespace ln.type { @@ -43,6 +44,20 @@ namespace ln.type Parse(String.Format("{0}://{1}{2}", scheme, authority, path)); ParseAuthority(); } + public URI(String scheme,string[] userinfo,string host,string port,string path,string query,string fragment) + { + Scheme = scheme; + UserInfo = userinfo ?? new string[0]; + Host = host; + Port = port; + if (userinfo.Length == 0) + Authority = String.Format("{0}:{1}", Host, Port); + else + Authority = String.Format("{2}@{0}:{1}", Host, Port, string.Join(':', UserInfo)); + Path = path; + Query = query; + Fragment = fragment; + } public URI(String scheme,String authority,string path,string query,string fragment) { Scheme = scheme; @@ -75,6 +90,13 @@ namespace ln.type } } + public URI WithUserInfo(params string[] userInfo) => new URI(Scheme,userInfo, Host, Port, Path, Query, Fragment); + public URI WithHost(string host) => new URI(Scheme,UserInfo, host, Port, Path, Query, Fragment); + public URI WithPort(string port) => new URI(Scheme,UserInfo, Host, port, Path, Query, Fragment); + public URI WithScheme(string scheme) => new URI(scheme, UserInfo, Host, Port, Path, Query, Fragment); + public URI WithPath(string path) => new URI(Scheme, UserInfo, Host, Port, path, Query, Fragment); + public URI WithQuery(string query) => new URI(Scheme, UserInfo, Host, Port, Path, query, Fragment); + public URI WithFragment(string fragment) => new URI(Scheme, UserInfo, Host, Port, Path, Query, fragment); private void Parse(String uri) { @@ -181,7 +203,8 @@ namespace ln.type } - public override string ToString() + public override string ToString() => ToString(false); + public string ToString(bool withFullUserInfo) { StringBuilder stringBuilder = new StringBuilder(); @@ -193,7 +216,10 @@ namespace ln.type stringBuilder.Append("//"); if (UserInfo.Length > 0) { - stringBuilder.Append(UserInfo[0]); + if (withFullUserInfo) + stringBuilder.Append(String.Join(':',UserInfo)); + else + stringBuilder.Append(UserInfo[0]); stringBuilder.Append('@'); } diff --git a/arithmetics/Words.cs b/ln.type/arithmetics/Words.cs similarity index 100% rename from arithmetics/Words.cs rename to ln.type/arithmetics/Words.cs diff --git a/data/Country.cs b/ln.type/data/Country.cs similarity index 100% rename from data/Country.cs rename to ln.type/data/Country.cs diff --git a/ln.type.csproj b/ln.type/ln.type.csproj similarity index 94% rename from ln.type.csproj rename to ln.type/ln.type.csproj index 35c8e1c..c9b5fd3 100644 --- a/ln.type.csproj +++ b/ln.type/ln.type.csproj @@ -3,7 +3,7 @@ netcoreapp3.1 true - 0.1.4 + 0.1.5 Harald Wolff-Thobaben l--n.de 0.0.1.0 diff --git a/rpc/RPCCall.cs b/ln.type/rpc/RPCCall.cs similarity index 100% rename from rpc/RPCCall.cs rename to ln.type/rpc/RPCCall.cs diff --git a/rpc/RPCContainer.cs b/ln.type/rpc/RPCContainer.cs similarity index 100% rename from rpc/RPCContainer.cs rename to ln.type/rpc/RPCContainer.cs diff --git a/rpc/RPCResult.cs b/ln.type/rpc/RPCResult.cs similarity index 100% rename from rpc/RPCResult.cs rename to ln.type/rpc/RPCResult.cs