diff --git a/.gitignore b/.gitignore
index 0031dcbe29..813e7d15cd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,6 @@
bin
obj
+*.suo
/lib/*.dll
/ICSharpCode.NRefactory.Tests/PartCover/*
_ReSharper*/*
diff --git a/ICSharpCode.NRefactory.CSharp/OutputVisitor/CSharpAmbience.cs b/ICSharpCode.NRefactory.CSharp/OutputVisitor/CSharpAmbience.cs
index 1cd38fc354..043461bd7c 100644
--- a/ICSharpCode.NRefactory.CSharp/OutputVisitor/CSharpAmbience.cs
+++ b/ICSharpCode.NRefactory.CSharp/OutputVisitor/CSharpAmbience.cs
@@ -267,6 +267,11 @@ namespace ICSharpCode.NRefactory.CSharp
astType.AcceptVisitor(new CSharpOutputVisitor(formatter, formattingPolicy));
}
+ public string ConvertConstantValue(object constantValue)
+ {
+ return CSharpOutputVisitor.PrintPrimitiveValue(constantValue);
+ }
+
public string WrapComment(string comment)
{
return "// " + comment;
diff --git a/ICSharpCode.NRefactory.CSharp/Resolver/MemberLookup.cs b/ICSharpCode.NRefactory.CSharp/Resolver/MemberLookup.cs
index d87982b719..9d5d989696 100644
--- a/ICSharpCode.NRefactory.CSharp/Resolver/MemberLookup.cs
+++ b/ICSharpCode.NRefactory.CSharp/Resolver/MemberLookup.cs
@@ -83,7 +83,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
///
/// Whether protected access to instance members is allowed.
/// True if the type of the reference is derived from the current class.
- /// Protected static members may be accessibe even if false is passed for this parameter.
+ /// Protected static members may be accessible even if false is passed for this parameter.
///
public bool IsAccessible(IEntity entity, bool allowProtectedAccess)
{
diff --git a/ICSharpCode.NRefactory/TypeSystem/IAmbience.cs b/ICSharpCode.NRefactory/TypeSystem/IAmbience.cs
index 779d4c7614..1aa9d299cb 100644
--- a/ICSharpCode.NRefactory/TypeSystem/IAmbience.cs
+++ b/ICSharpCode.NRefactory/TypeSystem/IAmbience.cs
@@ -89,6 +89,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
string ConvertEntity(IEntity entity);
string ConvertType(IType type);
string ConvertVariable(IVariable variable);
+ string ConvertConstantValue(object constantValue);
string WrapComment(string comment);
}
diff --git a/ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultResolvedTypeDefinition.cs b/ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultResolvedTypeDefinition.cs
index c60238d940..799d388920 100644
--- a/ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultResolvedTypeDefinition.cs
+++ b/ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultResolvedTypeDefinition.cs
@@ -395,9 +395,9 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
KnownTypeCode result = this.knownTypeCode;
if (result == (KnownTypeCode)(-1)) {
result = KnownTypeCode.None;
+ ICompilation compilation = this.Compilation;
for (int i = 0; i < KnownTypeReference.KnownTypeCodeCount; i++) {
- KnownTypeReference r = KnownTypeReference.Get((KnownTypeCode)i);
- if (r != null && r.Resolve(parentContext) == this) {
+ if (compilation.FindType((KnownTypeCode)i) == this) {
result = (KnownTypeCode)i;
break;
}
diff --git a/ICSharpCode.NRefactory/TypeSystem/TypeSystemExtensions.cs b/ICSharpCode.NRefactory/TypeSystem/TypeSystemExtensions.cs
index 03a22d2f34..0ab3f22c2b 100644
--- a/ICSharpCode.NRefactory/TypeSystem/TypeSystemExtensions.cs
+++ b/ICSharpCode.NRefactory/TypeSystem/TypeSystemExtensions.cs
@@ -85,11 +85,27 @@ namespace ICSharpCode.NRefactory.TypeSystem
///
public static bool IsDerivedFrom(this ITypeDefinition type, ITypeDefinition baseType)
{
+ if (type == null)
+ throw new ArgumentNullException("type");
+ if (baseType == null)
+ return false;
if (type.Compilation != baseType.Compilation) {
throw new InvalidOperationException("Both arguments to IsDerivedFrom() must be from the same compilation.");
}
return type.GetAllBaseTypeDefinitions().Contains(baseType);
}
+
+ ///
+ /// Gets whether this type definition is derived from a given known type.
+ ///
+ public static bool IsDerivedFrom(this ITypeDefinition type, KnownTypeCode baseType)
+ {
+ if (type == null)
+ throw new ArgumentNullException("type");
+ if (baseType == KnownTypeCode.None)
+ return false;
+ return IsDerivedFrom(type, type.Compilation.FindType(baseType).GetDefinition());
+ }
#endregion
#region IsOpen / IsUnbound / IsKnownType
@@ -535,7 +551,118 @@ namespace ICSharpCode.NRefactory.TypeSystem
return reference.Resolve (compilation.TypeResolveContext);
}
#endregion
-
+
+ #region ITypeDefinition.GetAttribute
+ ///
+ /// Gets the attribute of the specified attribute type (or derived attribute types).
+ ///
+ /// The entity on which the attributes are declared.
+ /// The attribute type to look for.
+ ///
+ /// Specifies whether attributes inherited from base classes and base members (if the given in an override)
+ /// should be returned. The default is true.
+ ///
+ ///
+ /// Returns the attribute that was found; or null if none was found.
+ /// If inherit is true, an from the entity itself will be returned if possible;
+ /// and the base entity will only be searched if none exists.
+ ///
+ public static IAttribute GetAttribute(this IEntity entity, IType attributeType, bool inherit = true)
+ {
+ return GetAttributes(entity, attributeType, inherit).FirstOrDefault();
+ }
+
+ ///
+ /// Gets the attributes of the specified attribute type (or derived attribute types).
+ ///
+ /// The entity on which the attributes are declared.
+ /// The attribute type to look for.
+ ///
+ /// Specifies whether attributes inherited from base classes and base members (if the given in an override)
+ /// should be returned. The default is true.
+ ///
+ ///
+ /// Returns the list of attributes that were found.
+ /// If inherit is true, attributes from the entity itself are returned first; followed by attributes inherited from the base entity.
+ ///
+ public static IEnumerable GetAttributes(this IEntity entity, IType attributeType, bool inherit = true)
+ {
+ if (entity == null)
+ throw new ArgumentNullException("entity");
+ if (attributeType == null)
+ throw new ArgumentNullException("attributeType");
+ return GetAttributes(entity, attributeType.Equals, inherit);
+ }
+
+ ///
+ /// Gets the attribute of the specified attribute type (or derived attribute types).
+ ///
+ /// The entity on which the attributes are declared.
+ /// The attribute type to look for.
+ ///
+ /// Specifies whether attributes inherited from base classes and base members (if the given in an override)
+ /// should be returned. The default is true.
+ ///
+ ///
+ /// Returns the attribute that was found; or null if none was found.
+ /// If inherit is true, an from the entity itself will be returned if possible;
+ /// and the base entity will only be searched if none exists.
+ ///
+ public static IAttribute GetAttribute(this IEntity entity, FullTypeName attributeType, bool inherit = true)
+ {
+ return GetAttributes(entity, attributeType, inherit).FirstOrDefault();
+ }
+
+ ///
+ /// Gets the attributes of the specified attribute type (or derived attribute types).
+ ///
+ /// The entity on which the attributes are declared.
+ /// The attribute type to look for.
+ ///
+ /// Specifies whether attributes inherited from base classes and base members (if the given in an override)
+ /// should be returned. The default is true.
+ ///
+ ///
+ /// Returns the list of attributes that were found.
+ /// If inherit is true, attributes from the entity itself are returned first; followed by attributes inherited from the base entity.
+ ///
+ public static IEnumerable GetAttributes(this IEntity entity, FullTypeName attributeType, bool inherit = true)
+ {
+ if (entity == null)
+ throw new ArgumentNullException("entity");
+ return GetAttributes(entity, attrType => {
+ ITypeDefinition typeDef = attrType.GetDefinition();
+ return typeDef != null && typeDef.FullTypeName == attributeType;
+ }, inherit);
+ }
+
+ static IEnumerable GetAttributes(IEntity entity, Predicate attributeTypePredicate, bool inherit)
+ {
+ if (!inherit) {
+ foreach (var attr in entity.Attributes) {
+ if (attributeTypePredicate(attr.AttributeType))
+ yield return attr;
+ }
+ yield break;
+ }
+ ITypeDefinition typeDef = entity as ITypeDefinition;
+ if (typeDef != null) {
+ foreach (var baseType in typeDef.GetNonInterfaceBaseTypes().Reverse()) {
+ ITypeDefinition baseTypeDef = baseType.GetDefinition();
+ if (baseTypeDef == null)
+ continue;
+ foreach (var attr in baseTypeDef.Attributes) {
+ if (attributeTypePredicate(attr.AttributeType))
+ yield return attr;
+ }
+ }
+ }
+ IMember member = entity as IMember;
+ if (member != null)
+ throw new NotImplementedException();
+ throw new NotSupportedException("Unknown entity type");
+ }
+ #endregion
#region IAssembly.GetTypeDefinition(string,string,int)
///
diff --git a/NRefactory.suo b/NRefactory.suo
deleted file mode 100644
index cb425d4826..0000000000
Binary files a/NRefactory.suo and /dev/null differ