Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
jobily
Prism
提交
3ebefb86
P
Prism
项目概览
jobily
/
Prism
9 个月 前同步成功
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Prism
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
3ebefb86
编写于
8月 17, 2023
作者:
D
Dan Siegel
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
chore: migrate the UriParsingHelper to Prism.Core
上级
09804758
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
201 addition
and
181 deletion
+201
-181
src/Maui/Prism.Maui/Common/UriParsingHelper.cs
src/Maui/Prism.Maui/Common/UriParsingHelper.cs
+0
-126
src/Prism.Core/Common/UriParsingHelper.cs
src/Prism.Core/Common/UriParsingHelper.cs
+201
-0
src/Wpf/Prism.Wpf/Common/UriParsingHelper.cs
src/Wpf/Prism.Wpf/Common/UriParsingHelper.cs
+0
-55
未找到文件。
src/Maui/Prism.Maui/Common/UriParsingHelper.cs
已删除
100644 → 0
浏览文件 @
09804758
using
Prism.Dialogs
;
using
Prism.Navigation
;
namespace
Prism.Common
;
/// <summary>
/// Helper class for parsing <see cref="Uri"/> instances.
/// </summary>
public
static
class
UriParsingHelper
{
private
static
readonly
char
[]
_pathDelimiter
=
{
'/'
};
public
static
Queue
<
string
>
GetUriSegments
(
Uri
uri
)
{
var
segmentStack
=
new
Queue
<
string
>();
if
(!
uri
.
IsAbsoluteUri
)
{
uri
=
EnsureAbsolute
(
uri
);
}
string
[]
segments
=
uri
.
PathAndQuery
.
Split
(
_pathDelimiter
,
StringSplitOptions
.
RemoveEmptyEntries
);
foreach
(
var
segment
in
segments
)
{
segmentStack
.
Enqueue
(
Uri
.
UnescapeDataString
(
segment
));
}
return
segmentStack
;
}
public
static
string
GetSegmentName
(
string
segment
)
{
return
segment
.
Split
(
'?'
)[
0
];
}
public
static
INavigationParameters
GetSegmentParameters
(
string
segment
)
{
string
query
=
string
.
Empty
;
if
(
string
.
IsNullOrWhiteSpace
(
segment
))
{
return
new
NavigationParameters
(
query
);
}
var
indexOfQuery
=
segment
.
IndexOf
(
'?'
);
if
(
indexOfQuery
>
0
)
query
=
segment
[
indexOfQuery
..];
return
new
NavigationParameters
(
query
);
}
public
static
INavigationParameters
GetSegmentParameters
(
string
uriSegment
,
INavigationParameters
parameters
)
{
var
navParameters
=
UriParsingHelper
.
GetSegmentParameters
(
uriSegment
);
if
(
parameters
!=
null
)
{
foreach
(
KeyValuePair
<
string
,
object
>
navigationParameter
in
parameters
)
{
navParameters
.
Add
(
navigationParameter
.
Key
,
navigationParameter
.
Value
);
}
}
return
navParameters
;
}
public
static
IDialogParameters
GetSegmentDialogParameters
(
string
segment
)
{
string
query
=
string
.
Empty
;
if
(
string
.
IsNullOrWhiteSpace
(
segment
))
{
return
new
DialogParameters
(
query
);
}
var
indexOfQuery
=
segment
.
IndexOf
(
'?'
);
if
(
indexOfQuery
>
0
)
query
=
segment
[
indexOfQuery
..];
return
new
DialogParameters
(
query
);
}
public
static
IDialogParameters
GetSegmentParameters
(
string
uriSegment
,
IDialogParameters
parameters
)
{
var
dialogParameters
=
GetSegmentDialogParameters
(
uriSegment
);
if
(
parameters
!=
null
)
{
foreach
(
KeyValuePair
<
string
,
object
>
navigationParameter
in
parameters
)
{
dialogParameters
.
Add
(
navigationParameter
.
Key
,
navigationParameter
.
Value
);
}
}
return
dialogParameters
;
}
public
static
Uri
EnsureAbsolute
(
Uri
uri
)
{
if
(
uri
.
IsAbsoluteUri
)
{
return
uri
;
}
if
(!
uri
.
OriginalString
.
StartsWith
(
"/"
,
StringComparison
.
Ordinal
))
{
return
new
Uri
(
"app://prismapp.maui/"
+
uri
,
UriKind
.
Absolute
);
}
return
new
Uri
(
"app://prismapp.maui"
+
uri
,
UriKind
.
Absolute
);
}
public
static
Uri
Parse
(
string
uri
)
{
if
(
string
.
IsNullOrEmpty
(
uri
))
throw
new
ArgumentNullException
(
nameof
(
uri
));
if
(
uri
.
StartsWith
(
"/"
,
StringComparison
.
Ordinal
))
{
return
new
Uri
(
"app://prismapp.maui"
+
uri
,
UriKind
.
Absolute
);
}
else
{
return
new
Uri
(
uri
,
UriKind
.
RelativeOrAbsolute
);
}
}
}
src/
Forms/Prism.Forms
/Common/UriParsingHelper.cs
→
src/
Prism.Core
/Common/UriParsingHelper.cs
浏览文件 @
3ebefb86
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
Prism.Dialogs
;
using
Prism.Dialogs
;
using
Prism.Navigation
;
using
Prism.Navigation
;
...
@@ -12,6 +12,11 @@ namespace Prism.Common
...
@@ -12,6 +12,11 @@ namespace Prism.Common
{
{
private
static
readonly
char
[]
_pathDelimiter
=
{
'/'
};
private
static
readonly
char
[]
_pathDelimiter
=
{
'/'
};
/// <summary>
/// Gets the Uri segments from a deep linked Navigation Uri
/// </summary>
/// <param name="uri">A navigation <see cref="Uri"/>.</param>
/// <returns>A collection of strings for each navigation segment within the Navigation <see cref="Uri"/>.</returns>
public
static
Queue
<
string
>
GetUriSegments
(
Uri
uri
)
public
static
Queue
<
string
>
GetUriSegments
(
Uri
uri
)
{
{
var
segmentStack
=
new
Queue
<
string
>();
var
segmentStack
=
new
Queue
<
string
>();
...
@@ -30,11 +35,21 @@ namespace Prism.Common
...
@@ -30,11 +35,21 @@ namespace Prism.Common
return
segmentStack
;
return
segmentStack
;
}
}
/// <summary>
/// Gets the Segment name from a Navigation Segment
/// </summary>
/// <param name="segment">A Navigation Segment</param>
/// <returns>The navigation segment name from the provided segment.</returns>
public
static
string
GetSegmentName
(
string
segment
)
public
static
string
GetSegmentName
(
string
segment
)
{
{
return
segment
.
Split
(
'?'
)[
0
];
return
segment
.
Split
(
'?'
)[
0
];
}
}
/// <summary>
/// Gets the Segment Parameters from a Navigation Segment that may contain a querystring
/// </summary>
/// <param name="segment">A navigation segment which may contain a querystring</param>
/// <returns>The <see cref="INavigationParameters"/>.</returns>
public
static
INavigationParameters
GetSegmentParameters
(
string
segment
)
public
static
INavigationParameters
GetSegmentParameters
(
string
segment
)
{
{
string
query
=
string
.
Empty
;
string
query
=
string
.
Empty
;
...
@@ -51,9 +66,15 @@ namespace Prism.Common
...
@@ -51,9 +66,15 @@ namespace Prism.Common
return
new
NavigationParameters
(
query
);
return
new
NavigationParameters
(
query
);
}
}
/// <summary>
/// Gets Segment Parameters including those parameters from an existing <see cref="INavigationParameters"/> collection.
/// </summary>
/// <param name="uriSegment">The <see cref="Uri"/> segment</param>
/// <param name="parameters">The existing <see cref="INavigationParameters"/>.</param>
/// <returns>The combined <see cref="INavigationParameters"/>.</returns>
public
static
INavigationParameters
GetSegmentParameters
(
string
uriSegment
,
INavigationParameters
parameters
)
public
static
INavigationParameters
GetSegmentParameters
(
string
uriSegment
,
INavigationParameters
parameters
)
{
{
var
navParameters
=
UriParsingHelper
.
GetSegmentParameters
(
uriSegment
);
var
navParameters
=
GetSegmentParameters
(
uriSegment
);
if
(
parameters
!=
null
)
if
(
parameters
!=
null
)
{
{
...
@@ -66,6 +87,11 @@ namespace Prism.Common
...
@@ -66,6 +87,11 @@ namespace Prism.Common
return
navParameters
;
return
navParameters
;
}
}
/// <summary>
/// Gets the <see cref="IDialogParameters"/> from a specified segment
/// </summary>
/// <param name="segment">A navigation segment which may contain a querystring.</param>
/// <returns>The <see cref="IDialogParameters"/>.</returns>
public
static
IDialogParameters
GetSegmentDialogParameters
(
string
segment
)
public
static
IDialogParameters
GetSegmentDialogParameters
(
string
segment
)
{
{
string
query
=
string
.
Empty
;
string
query
=
string
.
Empty
;
...
@@ -82,9 +108,15 @@ namespace Prism.Common
...
@@ -82,9 +108,15 @@ namespace Prism.Common
return
new
DialogParameters
(
query
);
return
new
DialogParameters
(
query
);
}
}
/// <summary>
/// Gets the combined <see cref="IDialogParameters"/> from a specified segment and existing <see cref="IDialogParameters"/>
/// </summary>
/// <param name="uriSegment">A navigation segment which may contain a querystring.</param>
/// <param name="parameters">Existing <see cref="IDialogParameters"/>.</param>
/// <returns></returns>
public
static
IDialogParameters
GetSegmentParameters
(
string
uriSegment
,
IDialogParameters
parameters
)
public
static
IDialogParameters
GetSegmentParameters
(
string
uriSegment
,
IDialogParameters
parameters
)
{
{
var
dialogParameters
=
UriParsingHelper
.
GetSegmentDialogParameters
(
uriSegment
);
var
dialogParameters
=
GetSegmentDialogParameters
(
uriSegment
);
if
(
parameters
!=
null
)
if
(
parameters
!=
null
)
{
{
...
@@ -97,20 +129,41 @@ namespace Prism.Common
...
@@ -97,20 +129,41 @@ namespace Prism.Common
return
dialogParameters
;
return
dialogParameters
;
}
}
public
static
Uri
EnsureAbsolute
(
Uri
uri
)
/// <summary>
/// Gets the query part of <paramref name="uri"/>.
/// </summary>
/// <param name="uri">The Uri.</param>
public
static
string
GetQuery
(
Uri
uri
)
{
{
if
(
uri
.
IsAbsoluteUri
)
return
EnsureAbsolute
(
uri
).
Query
;
{
}
return
uri
;
}
if
(!
uri
.
OriginalString
.
StartsWith
(
"/"
,
StringComparison
.
Ordinal
))
/// <summary>
{
/// Gets the AbsolutePath part of <paramref name="uri"/>.
return
new
Uri
(
"http://localhost/"
+
uri
,
UriKind
.
Absolute
);
/// </summary>
}
/// <param name="uri">The Uri.</param>
return
new
Uri
(
"http://localhost"
+
uri
,
UriKind
.
Absolute
);
public
static
string
GetAbsolutePath
(
Uri
uri
)
{
return
EnsureAbsolute
(
uri
).
AbsolutePath
;
}
}
/// <summary>
/// Parses the query of <paramref name="uri"/> into a dictionary.
/// </summary>
/// <param name="uri">The URI.</param>
public
static
INavigationParameters
ParseQuery
(
Uri
uri
)
{
var
query
=
GetQuery
(
uri
);
return
new
NavigationParameters
(
query
);
}
/// <summary>
/// Parses a uri string to a properly initialized Uri for Prism
/// </summary>
/// <param name="uri">A uri string.</param>
/// <returns>A <see cref="Uri"/>.</returns>
/// <exception cref="ArgumentNullException">Throws an <see cref="ArgumentNullException"/> when the string is null or empty.</exception>
public
static
Uri
Parse
(
string
uri
)
public
static
Uri
Parse
(
string
uri
)
{
{
if
(
uri
==
null
)
throw
new
ArgumentNullException
(
nameof
(
uri
));
if
(
uri
==
null
)
throw
new
ArgumentNullException
(
nameof
(
uri
));
...
@@ -124,5 +177,25 @@ namespace Prism.Common
...
@@ -124,5 +177,25 @@ namespace Prism.Common
return
new
Uri
(
uri
,
UriKind
.
RelativeOrAbsolute
);
return
new
Uri
(
uri
,
UriKind
.
RelativeOrAbsolute
);
}
}
}
}
/// <summary>
/// This will provide the existing <see cref="Uri"/> if it is already Absolute, otherwise
/// it will build a new Absolute <see cref="Uri"/>.
/// </summary>
/// <param name="uri">The source <see cref="Uri"/>.</param>
/// <returns>An Absolute <see cref="Uri"/>.</returns>
public
static
Uri
EnsureAbsolute
(
Uri
uri
)
{
if
(
uri
.
IsAbsoluteUri
)
{
return
uri
;
}
if
((
uri
!=
null
)
&&
!
uri
.
OriginalString
.
StartsWith
(
"/"
,
StringComparison
.
Ordinal
))
{
return
new
Uri
(
"http://localhost/"
+
uri
,
UriKind
.
Absolute
);
}
return
new
Uri
(
"http://localhost"
+
uri
,
UriKind
.
Absolute
);
}
}
}
}
}
src/Wpf/Prism.Wpf/Common/UriParsingHelper.cs
已删除
100644 → 0
浏览文件 @
09804758
using
System
;
using
Prism.Navigation
;
using
Prism.Regions
;
namespace
Prism.Common
{
/// <summary>
/// Helper class for parsing <see cref="Uri"/> instances.
/// </summary>
public
static
class
UriParsingHelper
{
/// <summary>
/// Gets the query part of <paramref name="uri"/>.
/// </summary>
/// <param name="uri">The Uri.</param>
public
static
string
GetQuery
(
Uri
uri
)
{
return
EnsureAbsolute
(
uri
).
Query
;
}
/// <summary>
/// Gets the AbsolutePath part of <paramref name="uri"/>.
/// </summary>
/// <param name="uri">The Uri.</param>
public
static
string
GetAbsolutePath
(
Uri
uri
)
{
return
EnsureAbsolute
(
uri
).
AbsolutePath
;
}
/// <summary>
/// Parses the query of <paramref name="uri"/> into a dictionary.
/// </summary>
/// <param name="uri">The URI.</param>
public
static
INavigationParameters
ParseQuery
(
Uri
uri
)
{
var
query
=
GetQuery
(
uri
);
return
new
NavigationParameters
(
query
);
}
private
static
Uri
EnsureAbsolute
(
Uri
uri
)
{
if
(
uri
.
IsAbsoluteUri
)
{
return
uri
;
}
if
((
uri
!=
null
)
&&
!
uri
.
OriginalString
.
StartsWith
(
"/"
,
StringComparison
.
Ordinal
))
{
return
new
Uri
(
"http://localhost/"
+
uri
,
UriKind
.
Absolute
);
}
return
new
Uri
(
"http://localhost"
+
uri
,
UriKind
.
Absolute
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录