4 changed files with 80 additions and 100 deletions
@ -0,0 +1,73 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.Linq; |
||||||
|
using System.Threading; |
||||||
|
using ICSharpCode.Core; |
||||||
|
using ICSharpCode.NRefactory.TypeSystem; |
||||||
|
using ICSharpCode.NRefactory.TypeSystem.Implementation; |
||||||
|
using ICSharpCode.SharpDevelop.Gui; |
||||||
|
using ICSharpCode.SharpDevelop.Parser; |
||||||
|
using ICSharpCode.SharpDevelop.Project; |
||||||
|
|
||||||
|
namespace ICSharpCode.SharpDevelop.Refactoring |
||||||
|
{ |
||||||
|
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); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -1,93 +0,0 @@ |
|||||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
|
||||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
|
||||||
|
|
||||||
using System; |
|
||||||
using System.Collections.Generic; |
|
||||||
using System.Linq; |
|
||||||
using System.Threading; |
|
||||||
using ICSharpCode.Core; |
|
||||||
using ICSharpCode.NRefactory.TypeSystem; |
|
||||||
using ICSharpCode.NRefactory.TypeSystem.Implementation; |
|
||||||
using ICSharpCode.SharpDevelop.Gui; |
|
||||||
using ICSharpCode.SharpDevelop.Parser; |
|
||||||
using ICSharpCode.SharpDevelop.Project; |
|
||||||
|
|
||||||
namespace ICSharpCode.SharpDevelop.Refactoring |
|
||||||
{ |
|
||||||
public struct TypeName : IEquatable<TypeName> |
|
||||||
{ |
|
||||||
public readonly string AssemblyName; |
|
||||||
public readonly string Namespace; |
|
||||||
public readonly string Name; |
|
||||||
public readonly int TypeParameterCount; |
|
||||||
|
|
||||||
public TypeName(string assemblyName, string @namespace, string name, int typeParameterCount) |
|
||||||
{ |
|
||||||
this.AssemblyName = assemblyName; |
|
||||||
this.Namespace = @namespace; |
|
||||||
this.Name = name; |
|
||||||
this.TypeParameterCount = typeParameterCount; |
|
||||||
} |
|
||||||
|
|
||||||
public TypeName(ITypeDefinition typeDefinition) |
|
||||||
{ |
|
||||||
this.AssemblyName = typeDefinition.ParentAssembly.AssemblyName; |
|
||||||
this.Namespace = typeDefinition.Namespace; |
|
||||||
this.Name = typeDefinition.Name; |
|
||||||
for (ITypeDefinition parent = typeDefinition.DeclaringTypeDefinition; parent != null; parent = parent.DeclaringTypeDefinition) { |
|
||||||
this.Name = parent.Name + "." + this.Name; |
|
||||||
} |
|
||||||
this.TypeParameterCount = typeDefinition.TypeParameterCount; |
|
||||||
} |
|
||||||
|
|
||||||
public override string ToString() |
|
||||||
{ |
|
||||||
string fullName; |
|
||||||
if (string.IsNullOrEmpty(Namespace)) |
|
||||||
fullName = Name; |
|
||||||
else |
|
||||||
fullName = Namespace + "." + Name; |
|
||||||
if (TypeParameterCount > 0) |
|
||||||
fullName = fullName + "`" + TypeParameterCount.ToString(); |
|
||||||
if (string.IsNullOrEmpty(AssemblyName)) |
|
||||||
return fullName; |
|
||||||
else |
|
||||||
return fullName + ", " + AssemblyName; |
|
||||||
} |
|
||||||
|
|
||||||
public override bool Equals(object obj) |
|
||||||
{ |
|
||||||
return (obj is TypeName) && Equals((TypeName)obj); |
|
||||||
} |
|
||||||
|
|
||||||
public bool Equals(TypeName other) |
|
||||||
{ |
|
||||||
return this.AssemblyName == other.AssemblyName && this.Namespace == other.Namespace && this.Name == other.Name && this.TypeParameterCount == other.TypeParameterCount; |
|
||||||
} |
|
||||||
|
|
||||||
public override int GetHashCode() |
|
||||||
{ |
|
||||||
int hashCode = 0; |
|
||||||
unchecked { |
|
||||||
if (AssemblyName != null) |
|
||||||
hashCode += 1000000007 * AssemblyName.GetHashCode(); |
|
||||||
if (Namespace != null) |
|
||||||
hashCode += 1000000009 * Namespace.GetHashCode(); |
|
||||||
if (Name != null) |
|
||||||
hashCode += 1000000021 * Name.GetHashCode(); |
|
||||||
hashCode += TypeParameterCount; |
|
||||||
} |
|
||||||
return hashCode; |
|
||||||
} |
|
||||||
|
|
||||||
public static bool operator ==(TypeName lhs, TypeName rhs) |
|
||||||
{ |
|
||||||
return lhs.Equals(rhs); |
|
||||||
} |
|
||||||
|
|
||||||
public static bool operator !=(TypeName lhs, TypeName rhs) |
|
||||||
{ |
|
||||||
return !lhs.Equals(rhs); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
Loading…
Reference in new issue