Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
df3d2ae9
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,发现更多精彩内容 >>
提交
df3d2ae9
编写于
10月 05, 2015
作者:
T
Tomas Matousek
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Sync C# and VB implementations of AssemblyData subclasses
上级
e4a7cca2
变更
8
展开全部
隐藏空白更改
内联
并排
Showing
8 changed file
with
470 addition
and
96 deletion
+470
-96
src/Compilers/CSharp/Portable/Symbols/ReferenceManager.cs
src/Compilers/CSharp/Portable/Symbols/ReferenceManager.cs
+1
-1
src/Compilers/CSharp/Test/Symbol/Compilation/ReferenceManagerTests.cs
...s/CSharp/Test/Symbol/Compilation/ReferenceManagerTests.cs
+0
-25
src/Compilers/Core/CodeAnalysisTest/Collections/ArrayBuilderTests.cs
...rs/Core/CodeAnalysisTest/Collections/ArrayBuilderTests.cs
+24
-0
src/Compilers/Core/SharedCollections/ArrayBuilder.cs
src/Compilers/Core/SharedCollections/ArrayBuilder.cs
+2
-2
src/Compilers/VisualBasic/Portable/Symbols/ReferenceManager.vb
...ompilers/VisualBasic/Portable/Symbols/ReferenceManager.vb
+59
-68
src/Compilers/VisualBasic/Test/Semantic/Compilation/ReferenceManagerTests.vb
...lBasic/Test/Semantic/Compilation/ReferenceManagerTests.vb
+350
-0
src/Test/Utilities/Shared/Mocks/TestMissingMetadataReferenceResolver.cs
...ties/Shared/Mocks/TestMissingMetadataReferenceResolver.cs
+33
-0
src/Test/Utilities/Shared/TestUtilities.projitems
src/Test/Utilities/Shared/TestUtilities.projitems
+1
-0
未找到文件。
src/Compilers/CSharp/Portable/Symbols/ReferenceManager.cs
浏览文件 @
df3d2ae9
...
...
@@ -368,7 +368,7 @@ private bool CreateAndSetSourceAssemblyFullBind(CSharpCompilation compilation)
{
if
((
object
)
bindingResult
[
i
].
AssemblySymbol
==
null
)
{
// symbol
s
hasn't been found in the cache, create a new one
// symbol hasn't been found in the cache, create a new one
var
compilationData
=
(
AssemblyDataForMetadataOrCompilation
)
allAssemblyData
[
i
];
bindingResult
[
i
].
AssemblySymbol
=
compilationData
.
CreateAssemblySymbol
();
newSymbols
.
Add
(
i
);
...
...
src/Compilers/CSharp/Test/Symbol/Compilation/ReferenceManagerTests.cs
浏览文件 @
df3d2ae9
...
...
@@ -2175,31 +2175,6 @@ public void AsymmetricUnification()
Assert
.
Equal
(
"System.Numerics.Vectors, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
,
((
IAssemblySymbol
)
a1
).
Identity
.
GetDisplayName
());
}
private
class
TestMissingMetadataReferenceResolver
:
MetadataReferenceResolver
{
private
readonly
Dictionary
<
string
,
MetadataReference
>
_map
;
public
readonly
List
<
AssemblyIdentity
>
ResolutionAttempts
=
new
List
<
AssemblyIdentity
>();
public
TestMissingMetadataReferenceResolver
(
Dictionary
<
string
,
MetadataReference
>
map
)
{
_map
=
map
;
}
public
override
PortableExecutableReference
ResolveMissingAssembly
(
AssemblyIdentity
identity
)
{
ResolutionAttempts
.
Add
(
identity
);
MetadataReference
reference
;
string
nameAndVersion
=
identity
.
Name
+
(
identity
.
Version
!=
AssemblyIdentity
.
NullVersion
?
$",
{
identity
.
Version
}
"
:
""
);
return
_map
.
TryGetValue
(
nameAndVersion
,
out
reference
)
?
(
PortableExecutableReference
)
reference
:
null
;
}
public
override
bool
ResolveMissingAssemblies
=>
true
;
public
override
bool
Equals
(
object
other
)
=>
true
;
public
override
int
GetHashCode
()
=>
1
;
public
override
ImmutableArray
<
PortableExecutableReference
>
ResolveReference
(
string
reference
,
string
baseFilePath
,
MetadataReferenceProperties
properties
)
=>
default
(
ImmutableArray
<
PortableExecutableReference
>);
}
[
Fact
]
public
void
MissingAssemblyResolution1
()
{
...
...
src/Compilers/Core/CodeAnalysisTest/Collections/ArrayBuilderTests.cs
浏览文件 @
df3d2ae9
...
...
@@ -41,5 +41,29 @@ public void SelectDistinct1()
builder
=
new
ArrayBuilder
<
int
>
{
1
,
2
,
3
,
2
,
4
,
5
,
1
};
AssertEx
.
Equal
(
new
byte
[]
{
1
,
2
,
3
,
4
,
5
},
builder
.
SelectDistinct
(
n
=>
(
byte
)
n
));
}
[
Fact
]
public
void
AddRange
()
{
var
builder
=
new
ArrayBuilder
<
int
>();
builder
.
AddRange
(
new
int
[
0
],
0
,
0
);
AssertEx
.
Equal
(
new
int
[
0
],
builder
.
ToArray
());
builder
.
AddRange
(
new
[]
{
1
,
2
,
3
},
0
,
3
);
AssertEx
.
Equal
(
new
[]
{
1
,
2
,
3
},
builder
.
ToArray
());
builder
.
AddRange
(
new
[]
{
1
,
2
,
3
},
2
,
0
);
AssertEx
.
Equal
(
new
[]
{
1
,
2
,
3
},
builder
.
ToArray
());
builder
.
AddRange
(
new
[]
{
1
,
2
,
3
},
1
,
1
);
AssertEx
.
Equal
(
new
[]
{
1
,
2
,
3
,
2
},
builder
.
ToArray
());
builder
.
AddRange
(
new
[]
{
1
,
2
,
3
},
1
,
2
);
AssertEx
.
Equal
(
new
[]
{
1
,
2
,
3
,
2
,
2
,
3
},
builder
.
ToArray
());
builder
.
AddRange
(
new
[]
{
1
,
2
,
3
},
2
,
1
);
AssertEx
.
Equal
(
new
[]
{
1
,
2
,
3
,
2
,
2
,
3
,
3
},
builder
.
ToArray
());
}
}
}
src/Compilers/Core/SharedCollections/ArrayBuilder.cs
浏览文件 @
df3d2ae9
...
...
@@ -385,9 +385,9 @@ public void AddRange(ImmutableArray<T> items, int length)
public
void
AddRange
(
T
[]
items
,
int
start
,
int
length
)
{
for
(
int
i
=
0
;
i
<
length
;
i
++)
for
(
int
i
=
start
,
end
=
start
+
length
;
i
<
end
;
i
++)
{
Add
(
items
[
start
+
i
]);
Add
(
items
[
i
]);
}
}
...
...
src/Compilers/VisualBasic/Portable/Symbols/ReferenceManager.vb
浏览文件 @
df3d2ae9
...
...
@@ -4,6 +4,7 @@ Imports System.Collections.Immutable
Imports
Microsoft.CodeAnalysis.VisualBasic.Emit
Imports
Microsoft.CodeAnalysis.VisualBasic.Symbols
Imports
Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE
Imports
Microsoft.CodeAnalysis.VisualBasic.Symbols.Retargeting
Imports
MetadataOrDiagnostic
=
System
.
Object
Namespace
Microsoft.CodeAnalysis.VisualBasic
...
...
@@ -277,8 +278,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Dim
explicitAssemblyData
=
referencedAssemblies
.
Insert
(
0
,
assemblyBeingBuiltData
)
' Let's bind all the references and resolve missing one (if resolver is available)
Dim
corLibraryIndex
As
Integer
Dim
hasCircularReference
As
Boolean
Dim
corLibraryIndex
As
Integer
Dim
implicitlyResolvedReferences
As
ImmutableArray
(
Of
MetadataReference
)
=
Nothing
Dim
implicitlyResolvedReferenceMap
As
ImmutableArray
(
Of
ResolvedReference
)
=
Nothing
Dim
allAssemblyData
As
ImmutableArray
(
Of
AssemblyData
)
=
Nothing
...
...
@@ -295,6 +296,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Debug
.
Assert
(
bindingResult
.
Length
=
allAssemblyData
.
Length
)
references
=
references
.
AddRange
(
implicitlyResolvedReferences
)
referenceMap
=
referenceMap
.
AddRange
(
implicitlyResolvedReferenceMap
)
Dim
referencedAssembliesMap
As
Dictionary
(
Of
MetadataReference
,
Integer
)
=
Nothing
...
...
@@ -314,21 +316,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
For
i
As
Integer
=
1
To
bindingResult
.
Length
-
1
Step
1
If
bindingResult
(
i
).
AssemblySymbol
Is
Nothing
Then
Dim
compilationData
=
TryCast
(
allAssemblyData
(
i
),
AssemblyDataForCompilation
)
If
compilationData
IsNot
Nothing
Then
bindingResult
(
i
).
AssemblySymbol
=
New
Retargeting
.
RetargetingAssemblySymbol
(
compilationData
.
Compilation
.
SourceAssembly
,
compilationData
.
IsLinked
)
Else
Dim
fileData
=
DirectCast
(
allAssemblyData
(
i
),
AssemblyDataForFile
)
bindingResult
(
i
).
AssemblySymbol
=
New
PEAssemblySymbol
(
fileData
.
Assembly
,
fileData
.
DocumentationProvider
,
fileData
.
IsLinked
,
fileData
.
EffectiveImportOptions
)
End
If
' symbol hasn't been found in the cache, create a new one
Dim
compilationData
=
DirectCast
(
allAssemblyData
(
i
),
AssemblyDataForMetadataOrCompilation
)
bindingResult
(
i
).
AssemblySymbol
=
compilationData
.
CreateAssemblySymbol
()
newSymbols
.
Add
(
i
)
End
If
...
...
@@ -353,11 +343,14 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
' This should be done after we created/found all AssemblySymbols
Dim
missingAssemblies
As
Dictionary
(
Of
AssemblyIdentity
,
MissingAssemblySymbol
)
=
Nothing
' -1 for assembly being built
Dim
totalReferencedAssemblyCount
=
allAssemblyData
.
Length
-
1
' Setup bound references for newly created SourceAssemblySymbol
Dim
moduleReferences
As
ImmutableArray
(
Of
ModuleReferences
(
Of
AssemblySymbol
))
=
Nothing
SetupReferencesForSourceAssembly
(
allAssemblyData
,
assemblySymbol
,
SetupReferencesForSourceAssembly
(
assemblySymbol
,
modules
,
totalReferencedAssemblyCount
,
bindingResult
,
missingAssemblies
,
moduleReferences
)
...
...
@@ -596,9 +589,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End
Sub
Private
Shared
Sub
SetupReferencesForSourceAssembly
(
allAssemblyData
As
ImmutableArray
(
Of
AssemblyData
),
sourceAssembly
As
SourceAssemblySymbol
,
modules
As
ImmutableArray
(
Of
PEModule
),
totalReferencedAssemblyCount
As
Integer
,
bindingResult
()
As
BoundInputAssembly
,
ByRef
missingAssemblies
As
Dictionary
(
Of
AssemblyIdentity
,
MissingAssemblySymbol
),
ByRef
moduleReferences
As
ImmutableArray
(
Of
ModuleReferences
(
Of
AssemblySymbol
))
...
...
@@ -610,8 +603,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Dim
refsUsed
As
Integer
=
0
For
moduleIndex
As
Integer
=
0
To
moduleSymbols
.
Length
-
1
Step
1
' -1 for assembly being built
Dim
refsCount
As
Integer
=
If
(
moduleIndex
=
0
,
allAssemblyData
.
Length
-
1
,
modules
(
moduleIndex
-
1
).
ReferencedAssemblies
.
Length
)
Dim
refsCount
As
Integer
=
If
(
moduleIndex
=
0
,
totalReferencedAssemblyCount
,
modules
(
moduleIndex
-
1
).
ReferencedAssemblies
.
Length
)
Dim
identities
(
refsCount
-
1
)
As
AssemblyIdentity
Dim
symbols
(
refsCount
-
1
)
As
AssemblySymbol
...
...
@@ -629,7 +621,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
identities
(
k
)
=
boundReference
.
ReferenceIdentity
Next
Dim
references
=
New
ModuleReferences
(
Of
AssemblySymbol
)(
identities
.
AsImmutableOrNull
(),
symbols
.
AsImmutableOrNull
(),
unifiedAssemblies
.
AsImmutableOrEmpty
())
Dim
references
=
New
ModuleReferences
(
Of
AssemblySymbol
)(
identities
.
AsImmutableOrNull
(),
symbols
.
AsImmutableOrNull
(),
unifiedAssemblies
.
AsImmutableOrEmpty
())
If
moduleIndex
>
0
Then
moduleReferencesBuilder
.
Add
(
references
)
...
...
@@ -640,7 +634,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
refsUsed
+=
refsCount
Next
moduleReferences
=
moduleReferencesBuilder
.
AsImmutableOrEmpty
()
moduleReferences
=
moduleReferencesBuilder
.
ToImmutableOrEmptyAndFree
()
End
Sub
Private
Shared
Function
GetAssemblyDefinitionSymbol
(
bindingResult
As
BoundInputAssembly
(),
...
...
@@ -687,16 +681,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Private
ReadOnly
m_ReferencedAssemblies
As
ImmutableArray
(
Of
AssemblyIdentity
)
Private
ReadOnly
m_EmbedInteropTypes
As
Boolean
'This is the name of the compilation that is being built.
'This should be the assembly name w/o the extension. It is
'used to compute whether or not it is possible that this
'assembly will give friend access to the compilation.
Protected
ReadOnly
m_CompilationName
As
String
Protected
Sub
New
(
identity
As
AssemblyIdentity
,
referencedAssemblies
As
ImmutableArray
(
Of
AssemblyIdentity
),
embedInteropTypes
As
Boolean
,
compilationName
As
String
)
embedInteropTypes
As
Boolean
)
Debug
.
Assert
(
identity
IsNot
Nothing
)
Debug
.
Assert
(
Not
referencedAssemblies
.
IsDefault
)
...
...
@@ -704,9 +691,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
m_EmbedInteropTypes
=
embedInteropTypes
m_Identity
=
identity
m_ReferencedAssemblies
=
referencedAssemblies
m_CompilationName
=
compilationName
End
Sub
Friend
MustOverride
Function
CreateAssemblySymbol
()
As
AssemblySymbol
Public
Overrides
ReadOnly
Property
Identity
As
AssemblyIdentity
Get
Return
m_Identity
...
...
@@ -750,61 +738,60 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Private
NotInheritable
Class
AssemblyDataForFile
Inherits
AssemblyDataForMetadataOrCompilation
Private
ReadOnly
_assembly
As
PEAssembly
Private
ReadOnly
_cachedSymbols
As
WeakList
(
Of
IAssemblySymbol
)
Private
ReadOnly
_documentationProvider
As
DocumentationProvider
Private
ReadOnly
_compilationImportOptions
As
MetadataImportOptions
Public
ReadOnly
Property
Assembly
As
PEAssembly
Get
Return
_assembly
End
Get
End
Property
Public
ReadOnly
Assembly
As
PEAssembly
''' <summary>
''' Guarded by <see cref="CommonReferenceManager.SymbolCacheAndReferenceManagerStateGuard"/>.
''' </summary>
Public
ReadOnly
Property
CachedSymbols
As
WeakList
(
Of
IAssemblySymbol
)
Get
Return
_cachedSymbols
End
Get
End
Property
Public
ReadOnly
CachedSymbols
As
WeakList
(
Of
IAssemblySymbol
)
Public
ReadOnly
Property
DocumentationProvider
As
DocumentationProvider
Get
Return
_documentationProvider
End
Get
End
Property
Public
ReadOnly
DocumentationProvider
As
DocumentationProvider
''' <summary>
''' Import options of the compilation being built.
''' </summary>
Private
ReadOnly
_compilationImportOptions
As
MetadataImportOptions
' This is the name of the compilation that is being built.
' This should be the assembly name w/o the extension. It is
' used to compute whether or not it is possible that this
' assembly will give friend access to the compilation.
Private
ReadOnly
_sourceAssemblySimpleName
As
String
Private
_internalsVisibleComputed
As
Boolean
=
False
Private
_internalsPotentiallyVisibleToCompilation
As
Boolean
=
False
Public
Sub
New
(
assembly
As
PEAssembly
,
cachedSymbols
As
WeakList
(
Of
IAssemblySymbol
),
embedInteropTypes
As
Boolean
,
documentationProvider
As
DocumentationProvider
,
compilation
Name
As
String
,
sourceAssemblySimple
Name
As
String
,
compilationImportOptions
As
MetadataImportOptions
)
MyBase
.
New
(
assembly
.
Identity
,
assembly
.
AssemblyReferences
,
embedInteropTypes
,
compilationName
)
MyBase
.
New
(
assembly
.
Identity
,
assembly
.
AssemblyReferences
,
embedInteropTypes
)
Debug
.
Assert
(
documentationProvider
IsNot
Nothing
)
Debug
.
Assert
(
cachedSymbols
IsNot
Nothing
)
_cachedSymbols
=
cachedSymbols
_assembly
=
assembly
_documentationProvider
=
If
(
documentationProvider
,
DocumentationProvider
.
Default
)
Me
.
CachedSymbols
=
cachedSymbols
Me
.
Assembly
=
assembly
Me
.
DocumentationProvider
=
documentationProvider
_compilationImportOptions
=
compilationImportOptions
_sourceAssemblySimpleName
=
sourceAssemblySimpleName
End
Sub
Private
_internalsVisibleComputed
As
Boolean
=
False
Private
_internalsVisibleToCompilation
As
Boolean
=
False
Friend
Overrides
Function
CreateAssemblySymbol
()
As
AssemblySymbol
Return
New
PEAssemblySymbol
(
Assembly
,
DocumentationProvider
,
IsLinked
,
EffectiveImportOptions
)
End
Function
Friend
ReadOnly
Property
InternalsMayBeVisibleToCompilation
As
Boolean
Get
If
Not
_internalsVisibleComputed
Then
_internals
VisibleToCompilation
=
InternalsMayBeVisibleToAssemblyBeingCompiled
(
m_CompilationName
,
_a
ssembly
)
_internals
PotentiallyVisibleToCompilation
=
InternalsMayBeVisibleToAssemblyBeingCompiled
(
_sourceAssemblySimpleName
,
A
ssembly
)
_internalsVisibleComputed
=
True
End
If
Return
_internalsVisibleToCompilation
Return
_internals
Potentially
VisibleToCompilation
End
Get
End
Property
...
...
@@ -823,7 +810,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
' accessing cached symbols requires a lock
SyncLock
SymbolCacheAndReferenceManagerStateGuard
For
Each
assemblySymbol
In
_c
achedSymbols
For
Each
assemblySymbol
In
C
achedSymbols
Dim
peAssembly
=
TryCast
(
assemblySymbol
,
PEAssemblySymbol
)
If
IsMatchingAssembly
(
peAssembly
)
Then
assemblies
.
Add
(
peAssembly
)
...
...
@@ -862,13 +849,13 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Public
Overrides
ReadOnly
Property
ContainsNoPiaLocalTypes
()
As
Boolean
Get
Return
_a
ssembly
.
ContainsNoPiaLocalTypes
()
Return
A
ssembly
.
ContainsNoPiaLocalTypes
()
End
Get
End
Property
Public
Overrides
ReadOnly
Property
DeclaresTheObjectClass
As
Boolean
Get
Return
_a
ssembly
.
DeclaresTheObjectClass
Return
A
ssembly
.
DeclaresTheObjectClass
End
Get
End
Property
...
...
@@ -885,7 +872,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Public
ReadOnly
Compilation
As
VisualBasicCompilation
Public
Sub
New
(
compilation
As
VisualBasicCompilation
,
embedInteropTypes
As
Boolean
)
MyBase
.
New
(
compilation
.
Assembly
.
Identity
,
GetReferencedAssemblies
(
compilation
),
embedInteropTypes
,
compilation
.
AssemblyName
)
MyBase
.
New
(
compilation
.
Assembly
.
Identity
,
GetReferencedAssemblies
(
compilation
),
embedInteropTypes
)
Debug
.
Assert
(
compilation
IsNot
Nothing
)
Me
.
Compilation
=
compilation
...
...
@@ -916,6 +903,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Return
refs
.
ToImmutableAndFree
()
End
Function
Friend
Overrides
Function
CreateAssemblySymbol
()
As
AssemblySymbol
Return
New
RetargetingAssemblySymbol
(
Compilation
.
SourceAssembly
,
IsLinked
)
End
Function
Protected
Overrides
Sub
AddAvailableSymbols
(
assemblies
As
List
(
Of
AssemblySymbol
))
assemblies
.
Add
(
Compilation
.
Assembly
)
...
...
@@ -926,7 +917,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End
Sub
Public
Overrides
Function
IsMatchingAssembly
(
candidateAssembly
As
AssemblySymbol
)
As
Boolean
Dim
retargeting
=
TryCast
(
candidateAssembly
,
Retargeting
.
Retargeting
AssemblySymbol
)
Dim
retargeting
=
TryCast
(
candidateAssembly
,
RetargetingAssemblySymbol
)
Dim
asm
As
AssemblySymbol
If
retargeting
IsNot
Nothing
Then
...
...
@@ -935,7 +926,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
asm
=
TryCast
(
candidateAssembly
,
SourceAssemblySymbol
)
End
If
Debug
.
Assert
(
Not
(
TypeOf
asm
Is
Retargeting
.
RetargetingAssemblySymbol
)
)
Debug
.
Assert
(
TypeOf
asm
IsNot
RetargetingAssemblySymbol
)
Return
asm
Is
Compilation
.
Assembly
End
Function
...
...
src/Compilers/VisualBasic/Test/Semantic/Compilation/ReferenceManagerTests.vb
浏览文件 @
df3d2ae9
此差异已折叠。
点击以展开。
src/Test/Utilities/Shared/Mocks/TestMissingMetadataReferenceResolver.cs
0 → 100644
浏览文件 @
df3d2ae9
// 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
Microsoft.CodeAnalysis
;
namespace
Roslyn.Test.Utilities
{
internal
class
TestMissingMetadataReferenceResolver
:
MetadataReferenceResolver
{
private
readonly
Dictionary
<
string
,
MetadataReference
>
_map
;
public
readonly
List
<
AssemblyIdentity
>
ResolutionAttempts
=
new
List
<
AssemblyIdentity
>();
public
TestMissingMetadataReferenceResolver
(
Dictionary
<
string
,
MetadataReference
>
map
)
{
_map
=
map
;
}
public
override
PortableExecutableReference
ResolveMissingAssembly
(
AssemblyIdentity
identity
)
{
ResolutionAttempts
.
Add
(
identity
);
MetadataReference
reference
;
string
nameAndVersion
=
identity
.
Name
+
(
identity
.
Version
!=
AssemblyIdentity
.
NullVersion
?
$",
{
identity
.
Version
}
"
:
""
);
return
_map
.
TryGetValue
(
nameAndVersion
,
out
reference
)
?
(
PortableExecutableReference
)
reference
:
null
;
}
public
override
bool
ResolveMissingAssemblies
=>
true
;
public
override
bool
Equals
(
object
other
)
=>
true
;
public
override
int
GetHashCode
()
=>
1
;
public
override
ImmutableArray
<
PortableExecutableReference
>
ResolveReference
(
string
reference
,
string
baseFilePath
,
MetadataReferenceProperties
properties
)
=>
default
(
ImmutableArray
<
PortableExecutableReference
>);
}
}
src/Test/Utilities/Shared/TestUtilities.projitems
浏览文件 @
df3d2ae9
...
...
@@ -52,6 +52,7 @@
<Compile
Include=
"$(MSBuildThisFileDirectory)Metadata\TypeAttributesMissing.cs"
/>
<Compile
Include=
"$(MSBuildThisFileDirectory)Metadata\PEModuleTestHelpers.cs"
/>
<Compile
Include=
"$(MSBuildThisFileDirectory)Mocks\TestDocumentationCommentProvider.cs"
/>
<Compile
Include=
"$(MSBuildThisFileDirectory)Mocks\TestMissingMetadataReferenceResolver.cs"
/>
<Compile
Include=
"$(MSBuildThisFileDirectory)Mocks\VirtualizedRelativePathResolver.cs"
/>
<Compile
Include=
"$(MSBuildThisFileDirectory)Pdb\MockSymWriter.cs"
/>
<Compile
Include=
"$(MSBuildThisFileDirectory)Pdb\PdbTestUtilities.cs"
/>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录