Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
6e3d4540
R
roslyn
项目概览
lwm1986
/
roslyn
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roslyn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6e3d4540
编写于
6月 29, 2017
作者:
A
Andrew Casey
提交者:
GitHub
6月 29, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #20521 from amcasey/OptionalToString
Override object.ToString in Optional<T>
上级
8de36652
809fc29b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
19 addition
and
6 deletion
+19
-6
src/Compilers/Core/Portable/Optional.cs
src/Compilers/Core/Portable/Optional.cs
+18
-6
src/Compilers/Core/Portable/PublicAPI.Unshipped.txt
src/Compilers/Core/Portable/PublicAPI.Unshipped.txt
+1
-0
未找到文件。
src/Compilers/Core/Portable/Optional.cs
浏览文件 @
6e3d4540
...
...
@@ -5,16 +5,17 @@
namespace
Microsoft.CodeAnalysis
{
/// <summary>
/// Represents a value type that can be assigned null.
/// Combines a value, <see cref="Value"/>, and a flag, <see cref="HasValue"/>,
/// indicating whether or not that value is meaningful.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="T">
The type of the value.
</typeparam>
public
struct
Optional
<
T
>
{
private
readonly
bool
_hasValue
;
private
readonly
T
_value
;
/// <summary>
///
Initializes a new instance to the specified
value.
///
Constructs an <see cref="Optional{T}"/> with a meaningful
value.
/// </summary>
/// <param name="value"></param>
public
Optional
(
T
value
)
...
...
@@ -24,7 +25,7 @@ public Optional(T value)
}
/// <summary>
///
Gets a value indicating whether the current object has a
value.
///
Returns <see langword="true"/> if the <see cref="Value"/> will return a meaningful
value.
/// </summary>
/// <returns></returns>
public
bool
HasValue
...
...
@@ -33,7 +34,7 @@ public bool HasValue
}
/// <summary>
/// Gets the value of the current object.
/// Gets the value of the current object.
Not meaningful unless <see cref="HasValue"/> returns <see langword="true"/>.
/// </summary>
/// <remarks>
/// <para>Unlike <see cref="Nullable{T}.Value"/>, this property does not throw an exception when
...
...
@@ -49,12 +50,23 @@ public T Value
}
/// <summary>
/// Creates a new object initialized to a
specified
value.
/// Creates a new object initialized to a
meaningful
value.
/// </summary>
/// <param name="value"></param>
public
static
implicit
operator
Optional
<
T
>(
T
value
)
{
return
new
Optional
<
T
>(
value
);
}
/// <summary>
/// Returns a string representation of this object.
/// </summary>
public
override
string
ToString
()
{
// Note: For nullable types, it's possible to have _hasValue true and _value null.
return
_hasValue
?
_value
?.
ToString
()
??
"null"
:
"unspecified"
;
}
}
}
src/Compilers/Core/Portable/PublicAPI.Unshipped.txt
浏览文件 @
6e3d4540
...
...
@@ -666,6 +666,7 @@ abstract Microsoft.CodeAnalysis.Diagnostics.OperationBlockStartAnalysisContext.R
abstract Microsoft.CodeAnalysis.Diagnostics.OperationBlockStartAnalysisContext.RegisterOperationBlockEndAction(System.Action<Microsoft.CodeAnalysis.Diagnostics.OperationBlockAnalysisContext> action) -> void
abstract Microsoft.CodeAnalysis.SemanticModel.GetOperationCore(Microsoft.CodeAnalysis.SyntaxNode node, System.Threading.CancellationToken cancellationToken) -> Microsoft.CodeAnalysis.IOperation
const Microsoft.CodeAnalysis.LanguageNames.FSharp = "F#" -> string
override Microsoft.CodeAnalysis.Optional<T>.ToString() -> string
override Microsoft.CodeAnalysis.Semantics.OperationWalker.Visit(Microsoft.CodeAnalysis.IOperation operation) -> void
override Microsoft.CodeAnalysis.Semantics.OperationWalker.VisitAddressOfExpression(Microsoft.CodeAnalysis.Semantics.IAddressOfExpression operation) -> void
override Microsoft.CodeAnalysis.Semantics.OperationWalker.VisitArgument(Microsoft.CodeAnalysis.Semantics.IArgument operation) -> void
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录