Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
49e625c8
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,发现更多精彩内容 >>
提交
49e625c8
编写于
3月 15, 2020
作者:
C
Cyrus Najmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Further along
上级
bfdaee1e
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
80 addition
and
50 deletion
+80
-50
src/EditorFeatures/CSharpTest/ImplementInterface/ImplementInterfaceTests.cs
.../CSharpTest/ImplementInterface/ImplementInterfaceTests.cs
+15
-15
src/Features/Core/Portable/ImplementInterface/AbstractImplementInterfaceService.CodeAction.cs
...Interface/AbstractImplementInterfaceService.CodeAction.cs
+3
-6
src/Features/Core/Portable/ImplementInterface/AbstractImplementInterfaceService.DisposePatternCodeAction.cs
...ractImplementInterfaceService.DisposePatternCodeAction.cs
+21
-5
src/Workspaces/CSharp/Portable/CodeGeneration/CSharpDeclarationComparer.cs
...harp/Portable/CodeGeneration/CSharpDeclarationComparer.cs
+30
-13
src/Workspaces/Core/Portable/CodeGeneration/AbstractCodeGenerationService.cs
.../Portable/CodeGeneration/AbstractCodeGenerationService.cs
+11
-11
未找到文件。
src/EditorFeatures/CSharpTest/ImplementInterface/ImplementInterfaceTests.cs
浏览文件 @
49e625c8
...
...
@@ -6611,7 +6611,21 @@ partial class C
string
implementationVisibility
,
string
disposeField
=
"disposedValue"
)
{
return
$@"
{
disposeVisibility
}
void Dispose(bool disposing)
return
$@"
{
implementationVisibility
}
Dispose()
{{
// {string.Format(FeaturesResources.Do_not_change_this_code_Put_cleanup_code_in_0_method, "Dispose(bool disposing)")}
Dispose
(
disposing
:
true
);
GC
.
SuppressFinalize
(
this
);
}}
// //
{
string
.
Format
(
FeaturesResources
.
TODO_colon_override_finalizer_only_if_0_has_code_to_free_unmanaged_resources
,
"Dispose(bool disposing)"
)}
// ~
{
className
}
()
//
{{
// // {string.Format(FeaturesResources.Do_not_change_this_code_Put_cleanup_code_in_0_method, "Dispose(bool disposing)")}
// Dispose(disposing: false);
// }}
{
disposeVisibility
}
void
Dispose
(
bool
disposing
)
{{
if
(!{
disposeField
})
{{
...
...
@@ -6623,20 +6637,6 @@ partial class C
// {FeaturesResources.TODO_colon_set_large_fields_to_null}
{
disposeField
}
=
true
;
}}
}}
//
{
FeaturesResources
.
TODO_colon_override_finalizer_only_if_0_has_code_to_free_unmanaged_resources
}
// ~
{
className
}
()
//
{{
// // {FeaturesResources.Do_not_change_this_code_Put_cleanup_code_in_0_method}
// Dispose(disposing: false);
// }}
{
implementationVisibility
}
Dispose
()
{{
// {FeaturesResources.Do_not_change_this_code_Put_cleanup_code_in_0_method}
Dispose
(
disposing
:
true
);
GC
.
SuppressFinalize
(
this
);
}}
";
}
...
...
src/Features/Core/Portable/ImplementInterface/AbstractImplementInterfaceService.CodeAction.cs
浏览文件 @
49e625c8
...
...
@@ -168,7 +168,7 @@ public Task<Document> GetUpdatedDocumentAsync(CancellationToken cancellationToke
{
return
GetUpdatedDocumentAsync
(
document
,
unimplementedMembers
,
classOrStructType
,
classOrStructDecl
,
extraMembers
:
ImmutableArray
<
ISymbol
>.
Empty
,
cancellationToken
);
ImmutableArray
<
ISymbol
>.
Empty
,
cancellationToken
);
}
protected
async
Task
<
Document
>
GetUpdatedDocumentAsync
(
...
...
@@ -196,16 +196,13 @@ public Task<Document> GetUpdatedDocumentAsync(CancellationToken cancellationToke
var
groupMembers
=
!
isComImport
&&
insertionBehavior
==
ImplementTypeInsertionBehavior
.
WithOtherMembersOfTheSameKind
;
re
sult
=
await
CodeGenerator
.
AddMemberDeclarationsAsync
(
re
turn
await
CodeGenerator
.
AddMemberDeclarationsAsync
(
result
.
Project
.
Solution
,
classOrStructType
,
memberDefinitions
.
Concat
(
extraMembers
),
new
CodeGenerationOptions
(
contextLocation
:
classOrStructDecl
.
GetLocation
(),
autoInsertionLocation
:
groupMembers
,
sortMembers
:
this
.
SortMembers
),
autoInsertionLocation
:
groupMembers
),
cancellationToken
).
ConfigureAwait
(
false
);
return
result
;
}
private
ImmutableArray
<
ISymbol
>
GenerateMembers
(
...
...
src/Features/Core/Portable/ImplementInterface/AbstractImplementInterfaceService.DisposePatternCodeAction.cs
浏览文件 @
49e625c8
...
...
@@ -136,18 +136,34 @@ public override string Title
document
,
classOrStructType
,
cancellationToken
).
ConfigureAwait
(
false
);
var
(
idisposable
,
disposeMethod
)
=
TryGetSymbolForIDisposable
(
compilation
);
var
(
disposableMethods
,
finalizer
)
=
CreateDisposableMethods
(
compilation
,
document
,
classOrStructType
,
disposeMethod
,
disposedValueField
);
var
updatedDocument
=
await
GetUpdatedDocumentAsync
(
var
docWithCoreMembers
=
await
GetUpdatedDocumentAsync
(
document
,
unimplementedMembers
.
WhereAsArray
(
m
=>
!
m
.
type
.
Equals
(
idisposable
)),
classOrStructType
,
classOrStructDecl
,
extraMembers
:
disposableMethods
.
Concat
(
disposedValueField
),
extraMembers
:
ImmutableArray
.
Create
<
ISymbol
>
(
disposedValueField
),
cancellationToken
).
ConfigureAwait
(
false
);
return
await
AddFinalizerCommentAsync
(
updatedDocument
,
finalizer
,
cancellationToken
).
ConfigureAwait
(
false
);
var
rootWithCoreMembers
=
await
docWithCoreMembers
.
GetRequiredSyntaxRootAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
firstGeneratedMember
=
rootWithCoreMembers
.
GetAnnotatedNodes
(
CodeGenerator
.
Annotation
).
First
();
var
typeDeclarationWithCoreMembers
=
firstGeneratedMember
.
Parent
;
var
typeDeclarationWithAllMembers
=
CodeGenerator
.
AddMemberDeclarations
(
typeDeclarationWithCoreMembers
,
disposableMethods
,
document
.
Project
.
Solution
.
Workspace
,
new
CodeGenerationOptions
(
parseOptions
:
rootWithCoreMembers
.
SyntaxTree
.
Options
,
autoInsertionLocation
:
false
));
var
docWithAllMembers
=
docWithCoreMembers
.
WithSyntaxRoot
(
rootWithCoreMembers
.
ReplaceNode
(
typeDeclarationWithCoreMembers
,
typeDeclarationWithAllMembers
));
return
await
AddFinalizerCommentAsync
(
docWithAllMembers
,
finalizer
,
cancellationToken
).
ConfigureAwait
(
false
);
}
private
async
Task
<
Document
>
AddFinalizerCommentAsync
(
...
...
@@ -192,7 +208,7 @@ public override string Title
var
g
=
document
.
GetRequiredLanguageService
<
SyntaxGenerator
>();
var
finalizer
=
this
.
Service
.
CreateFinalizer
(
g
,
classOrStructType
,
disposeMethodDisplayString
);
return
(
ImmutableArray
.
Create
<
ISymbol
>(
disposeI
mplMethod
,
disposeInterface
Method
),
finalizer
);
return
(
ImmutableArray
.
Create
<
ISymbol
>(
disposeI
nterfaceMethod
,
disposeImpl
Method
),
finalizer
);
}
private
IMethodSymbol
CreateDisposeImplementationMethod
(
...
...
src/Workspaces/CSharp/Portable/CodeGeneration/CSharpDeclarationComparer.cs
浏览文件 @
49e625c8
...
...
@@ -137,7 +137,7 @@ public int Compare(SyntaxNode x, SyntaxNode y)
private
int
Compare
(
DelegateDeclarationSyntax
x
,
DelegateDeclarationSyntax
y
)
{
if
(
EqualAccessibility
(
x
,
x
.
Modifiers
,
y
,
y
.
Modifiers
,
out
var
result
))
if
(
EqualAccessibility
(
x
,
x
.
Modifiers
,
null
,
y
,
y
.
Modifiers
,
null
,
out
var
result
))
{
if
(
_includeName
)
{
...
...
@@ -153,7 +153,7 @@ private int Compare(BaseFieldDeclarationSyntax x, BaseFieldDeclarationSyntax y)
if
(
EqualConstness
(
x
.
Modifiers
,
y
.
Modifiers
,
out
var
result
)
&&
EqualStaticness
(
x
.
Modifiers
,
y
.
Modifiers
,
out
result
)
&&
EqualReadOnlyness
(
x
.
Modifiers
,
y
.
Modifiers
,
out
result
)
&&
EqualAccessibility
(
x
,
x
.
Modifiers
,
y
,
y
.
Modifiers
,
out
result
))
EqualAccessibility
(
x
,
x
.
Modifiers
,
null
,
y
,
y
.
Modifiers
,
null
,
out
result
))
{
if
(
_includeName
)
{
...
...
@@ -170,7 +170,7 @@ private int Compare(BaseFieldDeclarationSyntax x, BaseFieldDeclarationSyntax y)
private
static
int
Compare
(
ConstructorDeclarationSyntax
x
,
ConstructorDeclarationSyntax
y
)
{
if
(
EqualStaticness
(
x
.
Modifiers
,
y
.
Modifiers
,
out
var
result
)
&&
EqualAccessibility
(
x
,
x
.
Modifiers
,
y
,
y
.
Modifiers
,
out
result
))
EqualAccessibility
(
x
,
x
.
Modifiers
,
null
,
y
,
y
.
Modifiers
,
null
,
out
result
))
{
EqualParameterCount
(
x
.
ParameterList
,
y
.
ParameterList
,
out
result
);
}
...
...
@@ -181,7 +181,9 @@ private static int Compare(ConstructorDeclarationSyntax x, ConstructorDeclaratio
private
int
Compare
(
MethodDeclarationSyntax
x
,
MethodDeclarationSyntax
y
)
{
if
(
EqualStaticness
(
x
.
Modifiers
,
y
.
Modifiers
,
out
var
result
)
&&
EqualAccessibility
(
x
,
x
.
Modifiers
,
y
,
y
.
Modifiers
,
out
result
))
EqualAccessibility
(
x
,
x
.
Modifiers
,
x
.
ExplicitInterfaceSpecifier
,
y
,
y
.
Modifiers
,
y
.
ExplicitInterfaceSpecifier
,
out
result
))
{
if
(!
_includeName
)
{
...
...
@@ -217,7 +219,9 @@ private static int Compare(OperatorDeclarationSyntax x, OperatorDeclarationSynta
private
int
Compare
(
EventDeclarationSyntax
x
,
EventDeclarationSyntax
y
)
{
if
(
EqualStaticness
(
x
.
Modifiers
,
y
.
Modifiers
,
out
var
result
)
&&
EqualAccessibility
(
x
,
x
.
Modifiers
,
y
,
y
.
Modifiers
,
out
result
))
EqualAccessibility
(
x
,
x
.
Modifiers
,
x
.
ExplicitInterfaceSpecifier
,
y
,
y
.
Modifiers
,
y
.
ExplicitInterfaceSpecifier
,
out
result
))
{
if
(
_includeName
)
{
...
...
@@ -231,7 +235,9 @@ private int Compare(EventDeclarationSyntax x, EventDeclarationSyntax y)
private
static
int
Compare
(
IndexerDeclarationSyntax
x
,
IndexerDeclarationSyntax
y
)
{
if
(
EqualStaticness
(
x
.
Modifiers
,
y
.
Modifiers
,
out
var
result
)
&&
EqualAccessibility
(
x
,
x
.
Modifiers
,
y
,
y
.
Modifiers
,
out
result
))
EqualAccessibility
(
x
,
x
.
Modifiers
,
x
.
ExplicitInterfaceSpecifier
,
y
,
y
.
Modifiers
,
y
.
ExplicitInterfaceSpecifier
,
out
result
))
{
EqualParameterCount
(
x
.
ParameterList
,
y
.
ParameterList
,
out
result
);
}
...
...
@@ -242,7 +248,9 @@ private static int Compare(IndexerDeclarationSyntax x, IndexerDeclarationSyntax
private
int
Compare
(
PropertyDeclarationSyntax
x
,
PropertyDeclarationSyntax
y
)
{
if
(
EqualStaticness
(
x
.
Modifiers
,
y
.
Modifiers
,
out
var
result
)
&&
EqualAccessibility
(
x
,
x
.
Modifiers
,
y
,
y
.
Modifiers
,
out
result
))
EqualAccessibility
(
x
,
x
.
Modifiers
,
x
.
ExplicitInterfaceSpecifier
,
y
,
y
.
Modifiers
,
y
.
ExplicitInterfaceSpecifier
,
out
result
))
{
if
(
_includeName
)
{
...
...
@@ -255,7 +263,7 @@ private int Compare(PropertyDeclarationSyntax x, PropertyDeclarationSyntax y)
private
int
Compare
(
EnumDeclarationSyntax
x
,
EnumDeclarationSyntax
y
)
{
if
(
EqualAccessibility
(
x
,
x
.
Modifiers
,
y
,
y
.
Modifiers
,
out
var
result
))
if
(
EqualAccessibility
(
x
,
x
.
Modifiers
,
null
,
y
,
y
.
Modifiers
,
null
,
out
var
result
))
{
if
(
_includeName
)
{
...
...
@@ -269,7 +277,7 @@ private int Compare(EnumDeclarationSyntax x, EnumDeclarationSyntax y)
private
int
Compare
(
BaseTypeDeclarationSyntax
x
,
BaseTypeDeclarationSyntax
y
)
{
if
(
EqualStaticness
(
x
.
Modifiers
,
y
.
Modifiers
,
out
var
result
)
&&
EqualAccessibility
(
x
,
x
.
Modifiers
,
y
,
y
.
Modifiers
,
out
result
))
EqualAccessibility
(
x
,
x
.
Modifiers
,
null
,
y
,
y
.
Modifiers
,
null
,
out
result
))
{
if
(
_includeName
)
{
...
...
@@ -394,12 +402,21 @@ private static bool EqualConstness(SyntaxTokenList x, SyntaxTokenList y, out int
private
static
bool
EqualReadOnlyness
(
SyntaxTokenList
x
,
SyntaxTokenList
y
,
out
int
comparisonResult
)
=>
BothHaveModifier
(
x
,
y
,
SyntaxKind
.
ReadOnlyKeyword
,
out
comparisonResult
);
private
static
bool
EqualAccessibility
(
SyntaxNode
x
,
SyntaxTokenList
xModifiers
,
SyntaxNode
y
,
SyntaxTokenList
yModifiers
,
out
int
comparisonResult
)
private
static
bool
EqualAccessibility
(
SyntaxNode
x
,
SyntaxTokenList
xModifiers
,
ExplicitInterfaceSpecifierSyntax
xExplicit
,
SyntaxNode
y
,
SyntaxTokenList
yModifiers
,
ExplicitInterfaceSpecifierSyntax
yExplicit
,
out
int
comparisonResult
)
{
var
xAccessibility
=
GetAccessibilityPrecedence
(
x
,
x
.
Parent
??
y
.
Parent
,
xModifiers
);
var
yAccessibility
=
GetAccessibilityPrecedence
(
y
,
y
.
Parent
??
x
.
Parent
,
yModifiers
);
if
(
xExplicit
!=
null
||
yExplicit
!=
null
)
{
comparisonResult
=
0
;
}
else
{
var
xAccessibility
=
GetAccessibilityPrecedence
(
x
,
x
.
Parent
??
y
.
Parent
,
xModifiers
);
var
yAccessibility
=
GetAccessibilityPrecedence
(
y
,
y
.
Parent
??
x
.
Parent
,
yModifiers
);
comparisonResult
=
xAccessibility
-
yAccessibility
;
}
comparisonResult
=
xAccessibility
-
yAccessibility
;
return
comparisonResult
==
0
;
}
...
...
src/Workspaces/Core/Portable/CodeGeneration/AbstractCodeGenerationService.cs
浏览文件 @
49e625c8
...
...
@@ -183,7 +183,6 @@ protected static T Cast<T>(object value)
INamespaceOrTypeSymbol
destination
,
Func
<
SyntaxNode
,
CodeGenerationOptions
,
IList
<
bool
>,
CancellationToken
,
SyntaxNode
>
declarationTransform
,
CodeGenerationOptions
options
,
IEnumerable
<
ISymbol
>
members
,
CancellationToken
cancellationToken
)
{
options
??=
CodeGenerationOptions
.
Default
;
...
...
@@ -238,13 +237,12 @@ protected static T Cast<T>(object value)
return
options
.
AutoInsertionLocation
?
AddMembersToAppropiateLocationInDestination
(
destination
,
filteredMembers
,
availableIndices
,
options
,
cancellationToken
)
:
AddMembersToEndOfDestination
(
destination
,
filteredMembers
,
availableIndices
,
options
,
cancellationToken
);
:
AddMembersToEndOfDestination
(
destination
,
filteredMembers
,
options
,
cancellationToken
);
}
private
TDeclarationSyntax
AddMembersToEndOfDestination
<
TDeclarationSyntax
>(
TDeclarationSyntax
destination
,
IEnumerable
<
ISymbol
>
members
,
IList
<
bool
>
availableIndices
,
CodeGenerationOptions
options
,
CancellationToken
cancellationToken
)
where
TDeclarationSyntax
:
SyntaxNode
...
...
@@ -357,7 +355,6 @@ protected static CodeGenerationOptions CreateOptionsForMultipleMembers(CodeGener
destination
,
(
t
,
opts
,
ai
,
ct
)
=>
AddEvent
(
t
,
@event
,
opts
,
ai
),
options
,
new
[]
{
@event
},
cancellationToken
);
}
...
...
@@ -368,7 +365,6 @@ public Task<Document> AddFieldAsync(Solution solution, INamedTypeSymbol destinat
destination
,
(
t
,
opts
,
ai
,
ct
)
=>
AddField
(
t
,
field
,
opts
,
ai
),
options
,
new
[]
{
field
},
cancellationToken
);
}
...
...
@@ -377,7 +373,7 @@ public Task<Document> AddPropertyAsync(Solution solution, INamedTypeSymbol desti
return
GetEditAsync
(
solution
,
destination
,
(
t
,
opts
,
ai
,
ct
)
=>
AddProperty
(
t
,
property
,
opts
,
ai
),
options
,
new
[]
{
property
},
options
,
cancellationToken
);
}
...
...
@@ -386,7 +382,7 @@ public Task<Document> AddNamedTypeAsync(Solution solution, INamedTypeSymbol dest
return
GetEditAsync
(
solution
,
destination
,
(
t
,
opts
,
ai
,
ct
)
=>
AddNamedType
(
t
,
namedType
,
opts
,
ai
,
ct
),
options
,
new
[]
{
namedType
},
options
,
cancellationToken
);
}
...
...
@@ -395,7 +391,8 @@ public Task<Document> AddNamedTypeAsync(Solution solution, INamespaceSymbol dest
return
GetEditAsync
(
solution
,
destination
,
(
t
,
opts
,
ai
,
ct
)
=>
AddNamedType
(
t
,
namedType
,
opts
,
ai
,
ct
),
options
,
new
[]
{
namedType
},
cancellationToken
);
options
,
cancellationToken
);
}
public
Task
<
Document
>
AddNamespaceAsync
(
Solution
solution
,
INamespaceSymbol
destination
,
INamespaceSymbol
@namespace
,
CodeGenerationOptions
options
,
CancellationToken
cancellationToken
)
...
...
@@ -403,7 +400,8 @@ public Task<Document> AddNamespaceAsync(Solution solution, INamespaceSymbol dest
return
GetEditAsync
(
solution
,
destination
,
(
t
,
opts
,
ai
,
ct
)
=>
AddNamespace
(
t
,
@namespace
,
opts
,
ai
,
ct
),
options
,
new
[]
{
@namespace
},
cancellationToken
);
options
,
cancellationToken
);
}
public
Task
<
Document
>
AddMethodAsync
(
Solution
solution
,
INamedTypeSymbol
destination
,
IMethodSymbol
method
,
CodeGenerationOptions
options
,
CancellationToken
cancellationToken
)
...
...
@@ -411,7 +409,8 @@ public Task<Document> AddMethodAsync(Solution solution, INamedTypeSymbol destina
return
GetEditAsync
(
solution
,
destination
,
(
t
,
opts
,
ai
,
ct
)
=>
AddMethod
(
t
,
method
,
opts
,
ai
),
options
,
new
[]
{
method
},
cancellationToken
);
options
,
cancellationToken
);
}
public
Task
<
Document
>
AddMembersAsync
(
Solution
solution
,
INamedTypeSymbol
destination
,
IEnumerable
<
ISymbol
>
members
,
CodeGenerationOptions
options
,
CancellationToken
cancellationToken
)
...
...
@@ -419,7 +418,8 @@ public Task<Document> AddMembersAsync(Solution solution, INamedTypeSymbol destin
return
GetEditAsync
(
solution
,
destination
,
(
t
,
opts
,
ai
,
ct
)
=>
AddMembers
(
t
,
members
,
ai
,
opts
,
ct
),
options
,
members
,
cancellationToken
);
options
,
cancellationToken
);
}
public
Task
<
Document
>
AddNamespaceOrTypeAsync
(
Solution
solution
,
INamespaceSymbol
destination
,
INamespaceOrTypeSymbol
namespaceOrType
,
CodeGenerationOptions
options
,
CancellationToken
cancellationToken
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录