22 changed files with 965 additions and 119 deletions
@ -0,0 +1,31 @@
@@ -0,0 +1,31 @@
|
||||
/* |
||||
* Created by SharpDevelop. |
||||
* User: Daniel |
||||
* Date: 6/13/2013 |
||||
* Time: 17:50 |
||||
* |
||||
* To change this template use Tools | Options | Coding | Edit Standard Headers. |
||||
*/ |
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Resolver |
||||
{ |
||||
/// <summary>
|
||||
/// Arguments for the callback of <see cref="FindReferences.RenameReferencesInFile"/>.
|
||||
/// </summary>
|
||||
public class RenameCallbackArguments |
||||
{ |
||||
public AstNode NodeToReplace { get; private set; } |
||||
public AstNode NewNode { get; private set; } |
||||
|
||||
public RenameCallbackArguments(AstNode nodeToReplace, AstNode newNode) |
||||
{ |
||||
if (nodeToReplace == null) |
||||
throw new ArgumentNullException("nodeToReplace"); |
||||
if (newNode == null) |
||||
throw new ArgumentNullException("newNode"); |
||||
this.NodeToReplace = nodeToReplace; |
||||
this.NewNode = newNode; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,206 @@
@@ -0,0 +1,206 @@
|
||||
//
|
||||
// SymbolCollectorTests.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2013 Xamarin Inc. (http://xamarin.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
using System; |
||||
using System.Linq; |
||||
using ICSharpCode.NRefactory.CSharp; |
||||
using ICSharpCode.NRefactory.TypeSystem; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.CSharp.CodeCompletion; |
||||
using System.Text; |
||||
using System.Collections.Generic; |
||||
using ICSharpCode.NRefactory.Editor; |
||||
using ICSharpCode.NRefactory.CSharp.Resolver; |
||||
|
||||
namespace ICSharpCode.NRefactory.Analysis |
||||
{ |
||||
[TestFixture] |
||||
public class SymbolCollectorTests |
||||
{ |
||||
|
||||
void CollectMembers(string code, string memberName, bool includeOverloads = true) |
||||
{ |
||||
StringBuilder sb = new StringBuilder(); |
||||
List<int> offsets = new List<int>(); |
||||
foreach (var ch in code) { |
||||
if (ch == '$') { |
||||
offsets.Add(sb.Length); |
||||
continue; |
||||
} |
||||
sb.Append(ch); |
||||
} |
||||
var syntaxTree = SyntaxTree.Parse(sb.ToString (), "test.cs"); |
||||
var unresolvedFile = syntaxTree.ToTypeSystem(); |
||||
var compilation = TypeSystemHelper.CreateCompilation(unresolvedFile); |
||||
|
||||
var symbol = FindReferencesTest.GetSymbol(compilation, memberName); |
||||
var col = new SymbolCollector(); |
||||
col.IncludeOverloads = includeOverloads; |
||||
col.GroupForRenaming = true; |
||||
|
||||
var result = col.GetRelatedSymbols (new TypeGraph (compilation.Assemblies), |
||||
symbol); |
||||
if (offsets.Count != result.Count()) { |
||||
foreach (var a in result) |
||||
Console.WriteLine(a); |
||||
} |
||||
Assert.AreEqual(offsets.Count, result.Count()); |
||||
var doc = new ReadOnlyDocument(sb.ToString ()); |
||||
result |
||||
.Select(r => doc.GetOffset ((r as IEntity).Region.Begin)) |
||||
.SequenceEqual(offsets); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestSingleInterfaceImpl () |
||||
{ |
||||
var code = @"
|
||||
interface IA |
||||
{ |
||||
void $Method(); |
||||
} |
||||
|
||||
class A : IA |
||||
{ |
||||
public virtual void $Method() { }; |
||||
} |
||||
|
||||
class B : A |
||||
{ |
||||
public override void Method() { }; |
||||
} |
||||
|
||||
class C : IA |
||||
{ |
||||
public void $Method() { }; |
||||
}";
|
||||
CollectMembers(code, "IA.Method"); |
||||
} |
||||
|
||||
|
||||
[Test] |
||||
public void TestMultiInterfacesImpl1 () |
||||
{ |
||||
var code = @"
|
||||
interface IA |
||||
{ |
||||
void $Method(); |
||||
} |
||||
interface IB |
||||
{ |
||||
void $Method(); |
||||
} |
||||
class A : IA, IB |
||||
{ |
||||
public void $Method() { } |
||||
} |
||||
class B : IA |
||||
{ |
||||
public void $Method() { } |
||||
} |
||||
class C : IB |
||||
{ |
||||
public void $Method() { } |
||||
}";
|
||||
CollectMembers(code, "A.Method"); |
||||
} |
||||
|
||||
|
||||
[Test] |
||||
public void TestOverloads () |
||||
{ |
||||
var code = @"
|
||||
class A |
||||
{ |
||||
public void $Method () { } |
||||
public void $Method (int i) { } |
||||
public void $Method (string i) { } |
||||
} |
||||
";
|
||||
CollectMembers(code, "A.Method"); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestConstructor () |
||||
{ |
||||
var code = @"
|
||||
class $A |
||||
{ |
||||
public $A() { } |
||||
public $A(int i) { } |
||||
} |
||||
";
|
||||
CollectMembers(code, "A"); |
||||
} |
||||
|
||||
|
||||
[Test] |
||||
public void TestDestructor () |
||||
{ |
||||
var code = @"
|
||||
class $A |
||||
{ |
||||
$~A() { } |
||||
} |
||||
";
|
||||
CollectMembers(code, "A"); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestStaticConstructor () |
||||
{ |
||||
var code = @"
|
||||
class $A |
||||
{ |
||||
static $A() { } |
||||
public $A(int i) { } |
||||
} |
||||
";
|
||||
CollectMembers(code, "A"); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestShadowedMember () |
||||
{ |
||||
var code = @"
|
||||
class A |
||||
{ |
||||
public int $Prop |
||||
{ get; set; } |
||||
} |
||||
class B : A |
||||
{ |
||||
public int Prop |
||||
{ get; set; } |
||||
} |
||||
";
|
||||
CollectMembers(code, "A.Prop"); |
||||
} |
||||
|
||||
|
||||
|
||||
} |
||||
} |
||||
|
@ -0,0 +1,159 @@
@@ -0,0 +1,159 @@
|
||||
// Copyright (c) 2013 AlphaSierraPapa for the SharpDevelop Team
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||
// software and associated documentation files (the "Software"), to deal in the Software
|
||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using ICSharpCode.NRefactory.TypeSystem; |
||||
using System.Linq; |
||||
|
||||
namespace ICSharpCode.NRefactory.Analysis |
||||
{ |
||||
/// <summary>
|
||||
/// The symbol collector collects related symbols that form a group of symbols that should be renamed
|
||||
/// when a name of one symbol changes. For example if a type definition name should be changed
|
||||
/// the constructors and destructor names should change as well.
|
||||
/// </summary>
|
||||
public class SymbolCollector |
||||
{ |
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether this <see cref="ICSharpCode.NRefactory.Analysis.SymbolCollector"/> should include overloads.
|
||||
/// </summary>
|
||||
/// <value><c>true</c> if overloads should be included; otherwise, <c>false</c>.</value>
|
||||
public bool IncludeOverloads { |
||||
get; |
||||
set; |
||||
} |
||||
|
||||
public bool GroupForRenaming { |
||||
get; |
||||
set; |
||||
} |
||||
|
||||
static IEnumerable<ISymbol> CollectTypeRelatedMembers (ITypeDefinition type) |
||||
{ |
||||
yield return type; |
||||
foreach (var c in type.GetDefinition ().GetMembers (m => !m.IsSynthetic && (m.SymbolKind == SymbolKind.Constructor || m.SymbolKind == SymbolKind.Destructor), GetMemberOptions.IgnoreInheritedMembers)) { |
||||
yield return c; |
||||
} |
||||
} |
||||
|
||||
static IEnumerable<ISymbol> CollectOverloads (TypeGraph g, IMethod method) |
||||
{ |
||||
return method.DeclaringType |
||||
.GetMethods (m => m.Name == method.Name) |
||||
.Where (m => m != method); |
||||
} |
||||
|
||||
static IMember SearchMember (ITypeDefinition derivedType, IMember method) |
||||
{ |
||||
foreach (var m in derivedType.Members) { |
||||
if (m.ImplementedInterfaceMembers.Contains (method)) |
||||
return m; |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
static IEnumerable<ISymbol> MakeUnique (List<ISymbol> symbols) |
||||
{ |
||||
HashSet<ISymbol> taken = new HashSet<ISymbol> (); |
||||
foreach (var sym in symbols) { |
||||
if (taken.Contains (sym)) |
||||
continue; |
||||
taken.Add (sym); |
||||
yield return sym; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the related symbols.
|
||||
/// </summary>
|
||||
/// <returns>The related symbols.</returns>
|
||||
/// <param name="g">The type graph.</param>
|
||||
/// <param name="m">The symbol to search</param>
|
||||
/// <param name="includeOverloads">If set to <c>true</c> overloads are included in the rename.</param>
|
||||
public IEnumerable<ISymbol> GetRelatedSymbols(TypeGraph g, ISymbol m) |
||||
{ |
||||
switch (m.SymbolKind) { |
||||
case SymbolKind.TypeDefinition: |
||||
return CollectTypeRelatedMembers ((ITypeDefinition)m); |
||||
|
||||
case SymbolKind.Field: |
||||
case SymbolKind.Operator: |
||||
case SymbolKind.Variable: |
||||
case SymbolKind.Parameter: |
||||
case SymbolKind.TypeParameter: |
||||
return new ISymbol[] { m }; |
||||
|
||||
case SymbolKind.Constructor: |
||||
if (GroupForRenaming) |
||||
return GetRelatedSymbols (g, ((IMethod)m).DeclaringTypeDefinition); |
||||
List<ISymbol> constructorSymbols = new List<ISymbol> (); |
||||
if (IncludeOverloads) { |
||||
foreach (var m3 in CollectOverloads (g, (IMethod)m)) { |
||||
constructorSymbols.Add (m3); |
||||
} |
||||
} |
||||
return constructorSymbols; |
||||
|
||||
case SymbolKind.Destructor: |
||||
if (GroupForRenaming) |
||||
return GetRelatedSymbols (g, ((IMethod)m).DeclaringTypeDefinition); |
||||
return new ISymbol[] { m }; |
||||
|
||||
case SymbolKind.Indexer: |
||||
case SymbolKind.Event: |
||||
case SymbolKind.Property: |
||||
return new ISymbol[] { m }; |
||||
|
||||
case SymbolKind.Method: |
||||
var method = (IMethod)m; |
||||
List<ISymbol> symbols = new List<ISymbol> (); |
||||
if (method.ImplementedInterfaceMembers.Count > 0) { |
||||
foreach (var m2 in method.ImplementedInterfaceMembers) { |
||||
symbols.AddRange (GetRelatedSymbols (g, m2)); |
||||
} |
||||
} else { |
||||
symbols.Add (method); |
||||
} |
||||
|
||||
if (method.DeclaringType.Kind == TypeKind.Interface) { |
||||
foreach (var derivedType in g.GetNode (method.DeclaringTypeDefinition).DerivedTypes) { |
||||
var member = SearchMember (derivedType.TypeDefinition, method); |
||||
if (member != null) |
||||
symbols.Add (member); |
||||
} |
||||
} |
||||
|
||||
|
||||
if (IncludeOverloads) { |
||||
IncludeOverloads = false; |
||||
foreach (var m3 in CollectOverloads (g, method)) { |
||||
symbols.AddRange (GetRelatedSymbols (g, m3)); |
||||
} |
||||
} |
||||
return MakeUnique (symbols); |
||||
|
||||
case SymbolKind.Namespace: |
||||
// TODO?
|
||||
return new ISymbol[] { m }; |
||||
default: |
||||
throw new ArgumentOutOfRangeException ("symbol:"+m.SymbolKind); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,82 @@
@@ -0,0 +1,82 @@
|
||||
// Copyright (c) 2013 AlphaSierraPapa for the SharpDevelop Team
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||
// software and associated documentation files (the "Software"), to deal in the Software
|
||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using ICSharpCode.NRefactory.TypeSystem; |
||||
|
||||
namespace ICSharpCode.NRefactory.Analysis |
||||
{ |
||||
/// <summary>
|
||||
/// A graph where type definitions are nodes; and edges are given by inheritance.
|
||||
/// </summary>
|
||||
public class TypeGraph |
||||
{ |
||||
Dictionary<AssemblyQualifiedTypeName, TypeGraphNode> dict; |
||||
|
||||
/// <summary>
|
||||
/// Builds a graph of all type definitions in the specified set of assemblies.
|
||||
/// </summary>
|
||||
/// <param name="assemblies">The input assemblies. The assemblies may belong to multiple compilations.</param>
|
||||
/// <remarks>The resulting graph may be cyclic if there are cyclic type definitions.</remarks>
|
||||
public TypeGraph(IEnumerable<IAssembly> assemblies) |
||||
{ |
||||
if (assemblies == null) |
||||
throw new ArgumentNullException("assemblies"); |
||||
dict = new Dictionary<AssemblyQualifiedTypeName, TypeGraphNode>(); |
||||
foreach (IAssembly assembly in assemblies) { |
||||
foreach (ITypeDefinition typeDef in assembly.GetAllTypeDefinitions()) { |
||||
// Overwrite previous entry - duplicates can occur if there are multiple versions of the
|
||||
// same project loaded in the solution (e.g. separate .csprojs for separate target frameworks)
|
||||
dict[new AssemblyQualifiedTypeName(typeDef)] = new TypeGraphNode(typeDef); |
||||
} |
||||
} |
||||
foreach (IAssembly assembly in assemblies) { |
||||
foreach (ITypeDefinition typeDef in assembly.GetAllTypeDefinitions()) { |
||||
TypeGraphNode typeNode = dict[new AssemblyQualifiedTypeName(typeDef)]; |
||||
foreach (IType baseType in typeDef.DirectBaseTypes) { |
||||
ITypeDefinition baseTypeDef = baseType.GetDefinition(); |
||||
if (baseTypeDef != null) { |
||||
TypeGraphNode baseTypeNode; |
||||
if (dict.TryGetValue(new AssemblyQualifiedTypeName(baseTypeDef), out baseTypeNode)) { |
||||
typeNode.BaseTypes.Add(baseTypeNode); |
||||
baseTypeNode.DerivedTypes.Add(typeNode); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
public TypeGraphNode GetNode(ITypeDefinition typeDefinition) |
||||
{ |
||||
if (typeDefinition == null) |
||||
return null; |
||||
return GetNode(new AssemblyQualifiedTypeName(typeDefinition)); |
||||
} |
||||
|
||||
public TypeGraphNode GetNode(AssemblyQualifiedTypeName typeName) |
||||
{ |
||||
TypeGraphNode node; |
||||
if (dict.TryGetValue(typeName, out node)) |
||||
return node; |
||||
else |
||||
return null; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,51 @@
@@ -0,0 +1,51 @@
|
||||
// Copyright (c) 2013 AlphaSierraPapa for the SharpDevelop Team
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||
// software and associated documentation files (the "Software"), to deal in the Software
|
||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using ICSharpCode.NRefactory.TypeSystem; |
||||
|
||||
namespace ICSharpCode.NRefactory.Analysis |
||||
{ |
||||
public sealed class TypeGraphNode |
||||
{ |
||||
readonly ITypeDefinition typeDef; |
||||
readonly List<TypeGraphNode> baseTypes = new List<TypeGraphNode>(); |
||||
readonly List<TypeGraphNode> derivedTypes = new List<TypeGraphNode>(); |
||||
|
||||
/// <summary>
|
||||
/// Creates a new unconnected type graph node.
|
||||
/// </summary>
|
||||
public TypeGraphNode(ITypeDefinition typeDef) |
||||
{ |
||||
this.typeDef = typeDef; |
||||
} |
||||
|
||||
public ITypeDefinition TypeDefinition { |
||||
get { return typeDef; } |
||||
} |
||||
|
||||
public IList<TypeGraphNode> DerivedTypes { |
||||
get { return derivedTypes; } |
||||
} |
||||
|
||||
public IList<TypeGraphNode> BaseTypes { |
||||
get { return baseTypes; } |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,79 @@
@@ -0,0 +1,79 @@
|
||||
// Copyright (c) 2013 AlphaSierraPapa for the SharpDevelop Team
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||
// software and associated documentation files (the "Software"), to deal in the Software
|
||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.TypeSystem |
||||
{ |
||||
public struct AssemblyQualifiedTypeName : IEquatable<AssemblyQualifiedTypeName> |
||||
{ |
||||
public readonly string AssemblyName; |
||||
public readonly FullTypeName TypeName; |
||||
|
||||
public AssemblyQualifiedTypeName(FullTypeName typeName, string assemblyName) |
||||
{ |
||||
this.AssemblyName = assemblyName; |
||||
this.TypeName = typeName; |
||||
} |
||||
|
||||
public AssemblyQualifiedTypeName(ITypeDefinition typeDefinition) |
||||
{ |
||||
this.AssemblyName = typeDefinition.ParentAssembly.AssemblyName; |
||||
this.TypeName = typeDefinition.FullTypeName; |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
if (string.IsNullOrEmpty(AssemblyName)) |
||||
return TypeName.ToString(); |
||||
else |
||||
return TypeName.ToString() + ", " + AssemblyName; |
||||
} |
||||
|
||||
public override bool Equals(object obj) |
||||
{ |
||||
return (obj is AssemblyQualifiedTypeName) && Equals((AssemblyQualifiedTypeName)obj); |
||||
} |
||||
|
||||
public bool Equals(AssemblyQualifiedTypeName other) |
||||
{ |
||||
return this.AssemblyName == other.AssemblyName && this.TypeName == other.TypeName; |
||||
} |
||||
|
||||
public override int GetHashCode() |
||||
{ |
||||
int hashCode = 0; |
||||
unchecked { |
||||
if (AssemblyName != null) |
||||
hashCode += 1000000007 * AssemblyName.GetHashCode(); |
||||
hashCode += TypeName.GetHashCode(); |
||||
} |
||||
return hashCode; |
||||
} |
||||
|
||||
public static bool operator ==(AssemblyQualifiedTypeName lhs, AssemblyQualifiedTypeName rhs) |
||||
{ |
||||
return lhs.Equals(rhs); |
||||
} |
||||
|
||||
public static bool operator !=(AssemblyQualifiedTypeName lhs, AssemblyQualifiedTypeName rhs) |
||||
{ |
||||
return !lhs.Equals(rhs); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue