Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
da717b8e
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,发现更多精彩内容 >>
提交
da717b8e
编写于
3月 26, 2017
作者:
C
CyrusNajmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Cleanup and simplify the viewmodels for boolean and enum code styles.
上级
985791b6
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
89 addition
and
89 deletion
+89
-89
src/VisualStudio/CSharp/Impl/Options/Formatting/StyleViewModel.cs
...alStudio/CSharp/Impl/Options/Formatting/StyleViewModel.cs
+8
-0
src/VisualStudio/Core/Impl/Options/Style/AbstractCodeStyleOptionViewModel.cs
...re/Impl/Options/Style/AbstractCodeStyleOptionViewModel.cs
+1
-9
src/VisualStudio/Core/Impl/Options/Style/BooleanCodeStyleOptionViewModel.cs
...ore/Impl/Options/Style/BooleanCodeStyleOptionViewModel.cs
+34
-34
src/VisualStudio/Core/Impl/Options/Style/EnumCodeStyleOptionViewModel.cs
...o/Core/Impl/Options/Style/EnumCodeStyleOptionViewModel.cs
+46
-46
未找到文件。
src/VisualStudio/CSharp/Impl/Options/Formatting/StyleViewModel.cs
浏览文件 @
da717b8e
...
...
@@ -715,39 +715,47 @@ private void AddExpressionBodyOptions(OptionSet optionSet, string expressionPref
new
CodeStylePreference
(
CSharpVSResources
.
When_on_single_line
,
isChecked
:
false
),
};
var
enumValues
=
new
[]
{
ExpressionBodyPreference
.
Never
,
ExpressionBodyPreference
.
WhenPossible
,
ExpressionBodyPreference
.
WhenOnSingleLine
};
CodeStyleItems
.
Add
(
new
EnumCodeStyleOptionViewModel
<
ExpressionBodyPreference
>(
CSharpCodeStyleOptions
.
PreferExpressionBodiedMethods
,
ServicesVSResources
.
Use_expression_body_for_methods
,
enumValues
,
new
[]
{
s_preferBlockBodyForMethods
,
s_preferExpressionBodyForMethods
,
s_preferExpressionBodyForMethods
},
this
,
optionSet
,
expressionPreferencesGroupTitle
,
expressionBodyPreferences
));
CodeStyleItems
.
Add
(
new
EnumCodeStyleOptionViewModel
<
ExpressionBodyPreference
>(
CSharpCodeStyleOptions
.
PreferExpressionBodiedConstructors
,
ServicesVSResources
.
Use_expression_body_for_constructors
,
enumValues
,
new
[]
{
s_preferBlockBodyForConstructors
,
s_preferExpressionBodyForConstructors
,
s_preferExpressionBodyForConstructors
},
this
,
optionSet
,
expressionPreferencesGroupTitle
,
expressionBodyPreferences
));
CodeStyleItems
.
Add
(
new
EnumCodeStyleOptionViewModel
<
ExpressionBodyPreference
>(
CSharpCodeStyleOptions
.
PreferExpressionBodiedOperators
,
ServicesVSResources
.
Use_expression_body_for_operators
,
enumValues
,
new
[]
{
s_preferBlockBodyForOperators
,
s_preferExpressionBodyForOperators
,
s_preferExpressionBodyForOperators
},
this
,
optionSet
,
expressionPreferencesGroupTitle
,
expressionBodyPreferences
));
CodeStyleItems
.
Add
(
new
EnumCodeStyleOptionViewModel
<
ExpressionBodyPreference
>(
CSharpCodeStyleOptions
.
PreferExpressionBodiedProperties
,
ServicesVSResources
.
Use_expression_body_for_properties
,
enumValues
,
new
[]
{
s_preferBlockBodyForProperties
,
s_preferExpressionBodyForProperties
,
s_preferExpressionBodyForProperties
},
this
,
optionSet
,
expressionPreferencesGroupTitle
,
expressionBodyPreferences
));
CodeStyleItems
.
Add
(
new
EnumCodeStyleOptionViewModel
<
ExpressionBodyPreference
>(
CSharpCodeStyleOptions
.
PreferExpressionBodiedIndexers
,
ServicesVSResources
.
Use_expression_body_for_indexers
,
enumValues
,
new
[]
{
s_preferBlockBodyForIndexers
,
s_preferExpressionBodyForIndexers
,
s_preferExpressionBodyForIndexers
},
this
,
optionSet
,
expressionPreferencesGroupTitle
,
expressionBodyPreferences
));
CodeStyleItems
.
Add
(
new
EnumCodeStyleOptionViewModel
<
ExpressionBodyPreference
>(
CSharpCodeStyleOptions
.
PreferExpressionBodiedAccessors
,
ServicesVSResources
.
Use_expression_body_for_accessors
,
enumValues
,
new
[]
{
s_preferBlockBodyForAccessors
,
s_preferExpressionBodyForAccessors
,
s_preferExpressionBodyForAccessors
},
this
,
optionSet
,
expressionPreferencesGroupTitle
,
expressionBodyPreferences
));
}
...
...
src/VisualStudio/Core/Impl/Options/Style/AbstractCodeStyleOptionViewModel.cs
浏览文件 @
da717b8e
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using
System.Collections.Generic
;
using
System.Collections.Immutable
;
using
System.Linq
;
using
Microsoft.CodeAnalysis.CodeStyle
;
using
Microsoft.CodeAnalysis.Options
;
...
...
@@ -11,8 +10,7 @@
namespace
Microsoft.VisualStudio.LanguageServices.Implementation.Options
{
/// <summary>
/// This class acts as a base for any view model that
/// binds to the codestyle options UI.
/// This class acts as a base for any view model that binds to the codestyle options UI.
/// </summary>
/// <remarks>
/// This supports databinding of:
...
...
@@ -25,8 +23,6 @@ namespace Microsoft.VisualStudio.LanguageServices.Implementation.Options
/// </remarks>
internal
abstract
class
AbstractCodeStyleOptionViewModel
:
AbstractNotifyPropertyChanged
{
protected
readonly
ImmutableArray
<
string
>
Previews
;
protected
AbstractOptionPreviewViewModel
Info
{
get
;
}
public
IOption
Option
{
get
;
}
...
...
@@ -37,7 +33,6 @@ internal abstract class AbstractCodeStyleOptionViewModel : AbstractNotifyPropert
public
List
<
NotificationOptionViewModel
>
NotificationPreferences
{
get
;
set
;
}
public
abstract
CodeStylePreference
SelectedPreference
{
get
;
set
;
}
public
abstract
bool
NotificationsAvailable
{
get
;
}
public
abstract
string
GetPreview
();
public
virtual
NotificationOptionViewModel
SelectedNotificationPreference
...
...
@@ -49,15 +44,12 @@ public virtual NotificationOptionViewModel SelectedNotificationPreference
public
AbstractCodeStyleOptionViewModel
(
IOption
option
,
string
description
,
string
[]
previews
,
AbstractOptionPreviewViewModel
info
,
OptionSet
options
,
string
groupName
,
List
<
CodeStylePreference
>
preferences
=
null
,
List
<
NotificationOptionViewModel
>
notificationPreferences
=
null
)
{
Previews
=
ImmutableArray
.
Create
(
previews
);
Info
=
info
;
Option
=
option
;
Description
=
description
;
...
...
src/VisualStudio/Core/Impl/Options/Style/BooleanCodeStyleOptionViewModel.cs
浏览文件 @
da717b8e
...
...
@@ -13,40 +13,11 @@ namespace Microsoft.VisualStudio.LanguageServices.Implementation.Options
/// </summary>
internal
class
BooleanCodeStyleOptionViewModel
:
AbstractCodeStyleOptionViewModel
{
private
CodeStylePreference
_selectedPreference
;
public
override
CodeStylePreference
SelectedPreference
{
get
{
return
_selectedPreference
;
}
set
{
if
(
SetProperty
(
ref
_selectedPreference
,
value
))
{
Info
.
SetOptionAndUpdatePreview
(
new
CodeStyleOption
<
bool
>(
_selectedPreference
.
IsChecked
,
_selectedNotificationPreference
.
Notification
),
Option
,
GetPreview
());
}
}
}
private
readonly
string
_truePreview
;
private
readonly
string
_falsePreview
;
private
CodeStylePreference
_selectedPreference
;
private
NotificationOptionViewModel
_selectedNotificationPreference
;
public
override
NotificationOptionViewModel
SelectedNotificationPreference
{
get
{
return
_selectedNotificationPreference
;
}
set
{
if
(
SetProperty
(
ref
_selectedNotificationPreference
,
value
))
{
Info
.
SetOptionAndUpdatePreview
(
new
CodeStyleOption
<
bool
>(
_selectedPreference
.
IsChecked
,
_selectedNotificationPreference
.
Notification
),
Option
,
GetPreview
());
}
}
}
public
override
bool
NotificationsAvailable
=>
true
;
public
BooleanCodeStyleOptionViewModel
(
IOption
option
,
...
...
@@ -58,8 +29,11 @@ public override NotificationOptionViewModel SelectedNotificationPreference
string
groupName
,
List
<
CodeStylePreference
>
preferences
=
null
,
List
<
NotificationOptionViewModel
>
notificationPreferences
=
null
)
:
base
(
option
,
description
,
new
[]
{
truePreview
,
falsePreview
},
info
,
options
,
groupName
,
preferences
,
notificationPreferences
)
:
base
(
option
,
description
,
info
,
options
,
groupName
,
preferences
,
notificationPreferences
)
{
_truePreview
=
truePreview
;
_falsePreview
=
falsePreview
;
var
codeStyleOption
=
((
CodeStyleOption
<
bool
>)
options
.
GetOption
(
new
OptionKey
(
option
,
option
.
IsPerLanguage
?
info
.
Language
:
null
)));
_selectedPreference
=
Preferences
.
Single
(
c
=>
c
.
IsChecked
==
codeStyleOption
.
Value
);
...
...
@@ -70,7 +44,33 @@ public override NotificationOptionViewModel SelectedNotificationPreference
NotifyPropertyChanged
(
nameof
(
SelectedNotificationPreference
));
}
public
override
CodeStylePreference
SelectedPreference
{
get
=>
_selectedPreference
;
set
{
if
(
SetProperty
(
ref
_selectedPreference
,
value
))
{
Info
.
SetOptionAndUpdatePreview
(
new
CodeStyleOption
<
bool
>(
_selectedPreference
.
IsChecked
,
_selectedNotificationPreference
.
Notification
),
Option
,
GetPreview
());
}
}
}
public
override
NotificationOptionViewModel
SelectedNotificationPreference
{
get
=>
_selectedNotificationPreference
;
set
{
if
(
SetProperty
(
ref
_selectedNotificationPreference
,
value
))
{
Info
.
SetOptionAndUpdatePreview
(
new
CodeStyleOption
<
bool
>(
_selectedPreference
.
IsChecked
,
_selectedNotificationPreference
.
Notification
),
Option
,
GetPreview
());
}
}
}
public
override
string
GetPreview
()
=>
SelectedPreference
.
IsChecked
?
Previews
[
0
]
:
Previews
[
1
]
;
=>
SelectedPreference
.
IsChecked
?
_truePreview
:
_falsePreview
;
}
}
\ No newline at end of file
src/VisualStudio/Core/Impl/Options/Style/EnumCodeStyleOptionViewModel.cs
浏览文件 @
da717b8e
...
...
@@ -27,23 +27,60 @@ static EnumCodeStyleOptionViewModel()
Contract
.
ThrowIfFalse
(
typeof
(
T
).
IsEnum
);
}
private
static
readonly
ImmutableArray
<
T
>
s_enumValues
=
ImmutableArray
.
Create
((
T
[])
Enum
.
GetValues
(
typeof
(
T
)))
;
private
readonly
ImmutableArray
<
T
>
_enumValues
;
private
readonly
ImmutableArray
<
string
>
_previews
;
private
CodeStylePreference
_selectedPreference
;
private
NotificationOptionViewModel
_selectedNotificationPreference
;
public
EnumCodeStyleOptionViewModel
(
Option
<
CodeStyleOption
<
T
>>
option
,
string
description
,
T
[]
enumValues
,
string
[]
previews
,
AbstractOptionPreviewViewModel
info
,
OptionSet
options
,
string
groupName
,
List
<
CodeStylePreference
>
preferences
)
:
base
(
option
,
description
,
info
,
options
,
groupName
,
preferences
)
{
Debug
.
Assert
(
preferences
.
Count
==
enumValues
.
Length
);
Debug
.
Assert
(
previews
.
Length
==
enumValues
.
Length
);
var
expectedEnumValues
=
Enum
.
GetValues
(
typeof
(
T
));
Debug
.
Assert
(
expectedEnumValues
.
Length
==
enumValues
.
Length
,
"Enum was updated, but UI wasn't."
);
_enumValues
=
enumValues
.
ToImmutableArray
();
_previews
=
previews
.
ToImmutableArray
();
var
codeStyleOption
=
options
.
GetOption
(
option
);
var
enumIndex
=
_enumValues
.
IndexOf
(
codeStyleOption
.
Value
);
_selectedPreference
=
Preferences
[
enumIndex
];
var
notificationViewModel
=
NotificationPreferences
.
Single
(
i
=>
i
.
Notification
.
Value
==
codeStyleOption
.
Notification
.
Value
);
_selectedNotificationPreference
=
NotificationPreferences
.
Single
(
p
=>
p
.
Notification
.
Value
==
notificationViewModel
.
Notification
.
Value
);
NotifyPropertyChanged
(
nameof
(
SelectedPreference
));
NotifyPropertyChanged
(
nameof
(
SelectedNotificationPreference
));
}
public
override
string
GetPreview
()
{
var
index
=
Preferences
.
IndexOf
(
SelectedPreference
);
return
_previews
[
index
];
}
public
override
CodeStylePreference
SelectedPreference
{
get
{
return
_selectedPreference
;
}
get
=>
_selectedPreference
;
set
{
if
(
SetProperty
(
ref
_selectedPreference
,
value
))
{
var
index
=
Preferences
.
IndexOf
(
value
);
var
enumValue
=
s
_enumValues
[
index
];
var
enumValue
=
_enumValues
[
index
];
Info
.
SetOptionAndUpdatePreview
(
new
CodeStyleOption
<
T
>(
...
...
@@ -53,20 +90,16 @@ public override CodeStylePreference SelectedPreference
}
}
private
NotificationOptionViewModel
_selectedNotificationPreference
;
public
override
NotificationOptionViewModel
SelectedNotificationPreference
{
get
{
return
_selectedNotificationPreference
;
}
get
=>
_selectedNotificationPreference
;
set
{
if
(
SetProperty
(
ref
_selectedNotificationPreference
,
value
))
{
var
index
=
Preferences
.
IndexOf
(
SelectedPreference
);
var
enumValue
=
s
_enumValues
[
index
];
var
enumValue
=
_enumValues
[
index
];
Info
.
SetOptionAndUpdatePreview
(
new
CodeStyleOption
<
T
>(
...
...
@@ -75,38 +108,5 @@ public override NotificationOptionViewModel SelectedNotificationPreference
}
}
}
public
override
bool
NotificationsAvailable
=>
true
;
public
override
string
GetPreview
()
{
var
index
=
Preferences
.
IndexOf
(
SelectedPreference
);
return
Previews
[
index
];
}
public
EnumCodeStyleOptionViewModel
(
Option
<
CodeStyleOption
<
T
>>
option
,
string
description
,
string
[]
previews
,
AbstractOptionPreviewViewModel
info
,
OptionSet
options
,
string
groupName
,
List
<
CodeStylePreference
>
preferences
)
:
base
(
option
,
description
,
previews
,
info
,
options
,
groupName
,
preferences
)
{
Debug
.
Assert
(
preferences
.
Count
==
s_enumValues
.
Length
);
Debug
.
Assert
(
previews
.
Length
==
s_enumValues
.
Length
);
var
codeStyleOption
=
options
.
GetOption
(
option
);
var
enumIndex
=
s_enumValues
.
IndexOf
(
codeStyleOption
.
Value
);
_selectedPreference
=
Preferences
[
enumIndex
];
var
notificationViewModel
=
NotificationPreferences
.
Single
(
i
=>
i
.
Notification
.
Value
==
codeStyleOption
.
Notification
.
Value
);
_selectedNotificationPreference
=
NotificationPreferences
.
Single
(
p
=>
p
.
Notification
.
Value
==
notificationViewModel
.
Notification
.
Value
);
NotifyPropertyChanged
(
nameof
(
SelectedPreference
));
NotifyPropertyChanged
(
nameof
(
SelectedNotificationPreference
));
}
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录