Author: spouliot
Date: 2008-01-02 11:20:01 -0500 (Wed, 02 Jan 2008)
New Revision: 92111
Modified:
trunk/cecil/gendarme/framework/Gendarme.Framework.Rocks/ChangeLog
trunk/cecil/gendarme/framework/Gendarme.Framework.Rocks/MethodRocks.cs
trunk/cecil/gendarme/framework/Gendarme.Framework.Rocks/TypeRocks.cs
Log:
2008-01-02 Sebastien Pouliot <[EMAIL PROTECTED]>
* MethodRocks.cs: Added IsArray extension method (based on code
from Adrian Tsai).
* TypeRocks.cs: Added IsAttribute and Inherits extensions methods
(based on code from Daniel Abramov) and IsProperty (based on code
from Adrian Tsai).
Modified: trunk/cecil/gendarme/framework/Gendarme.Framework.Rocks/ChangeLog
===================================================================
--- trunk/cecil/gendarme/framework/Gendarme.Framework.Rocks/ChangeLog
2008-01-02 15:33:23 UTC (rev 92110)
+++ trunk/cecil/gendarme/framework/Gendarme.Framework.Rocks/ChangeLog
2008-01-02 16:20:01 UTC (rev 92111)
@@ -1,3 +1,11 @@
+2008-01-02 Sebastien Pouliot <[EMAIL PROTECTED]>
+
+ * MethodRocks.cs: Added IsArray extension method (based on code
+ from Adrian Tsai).
+ * TypeRocks.cs: Added IsAttribute and Inherits extensions methods
+ (based on code from Daniel Abramov) and IsProperty (based on code
+ from Adrian Tsai).
+
2007-12-26 Sebastien Pouliot <[EMAIL PROTECTED]>
* CustomAttributeRocks.cs: New. Extension methods for Cecil's
Modified: trunk/cecil/gendarme/framework/Gendarme.Framework.Rocks/MethodRocks.cs
===================================================================
--- trunk/cecil/gendarme/framework/Gendarme.Framework.Rocks/MethodRocks.cs
2008-01-02 15:33:23 UTC (rev 92110)
+++ trunk/cecil/gendarme/framework/Gendarme.Framework.Rocks/MethodRocks.cs
2008-01-02 16:20:01 UTC (rev 92111)
@@ -3,8 +3,10 @@
//
// Authors:
// Sebastien Pouliot <[EMAIL PROTECTED]>
+// Adrian Tsai <[EMAIL PROTECTED]>
//
-// Copyright (C) 2007 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2007-2008 Novell, Inc (http://www.novell.com)
+// Copyright (c) 2007 Adrian Tsai
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
deal
@@ -131,6 +133,16 @@
}
/// <summary>
+ /// Check if the method corresponds to the get or set operation
on a property.
+ /// </summary>
+ /// <param name="self">The MethodDefinition on which the
extension method can be called.</param>
+ /// <returns>True if the method is a getter or a setter, False
otherwise</returns>
+ public static bool IsProperty (this MethodDefinition self)
+ {
+ return ((self.SemanticsAttributes &
(MethodSemanticsAttributes.Getter | MethodSemanticsAttributes.Setter)) != 0);
+ }
+
+ /// <summary>
/// Check if the method corresponds to the set operation on a
property.
/// </summary>
/// <param name="self">The MethodDefinition on which the
extension method can be called.</param>
Modified: trunk/cecil/gendarme/framework/Gendarme.Framework.Rocks/TypeRocks.cs
===================================================================
--- trunk/cecil/gendarme/framework/Gendarme.Framework.Rocks/TypeRocks.cs
2008-01-02 15:33:23 UTC (rev 92110)
+++ trunk/cecil/gendarme/framework/Gendarme.Framework.Rocks/TypeRocks.cs
2008-01-02 16:20:01 UTC (rev 92111)
@@ -3,8 +3,12 @@
//
// Authors:
// Sebastien Pouliot <[EMAIL PROTECTED]>
+// Daniel Abramov <[EMAIL PROTECTED]>
+// Adrian Tsai <[EMAIL PROTECTED]>
//
-// Copyright (C) 2007 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2007-2008 Novell, Inc (http://www.novell.com)
+// (C) 2007 Daniel Abramov
+// Copyright (c) 2007 Adrian Tsai
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
deal
@@ -91,6 +95,54 @@
}
/// <summary>
+ /// Check if the type inherits from the specified type. Note
that it is possible that
+ /// we might now be able to know the complete inheritance chain
since the assembly
+ /// where the information resides could be unavailable.
+ /// </summary>
+ /// <param name="self">The TypeReference on which the extension
method can be called.</param>
+ /// <param name="className">Full name of the base class</param>
+ /// <returns>True if the type inherits from specified class,
False otherwise</returns>
+ public static bool Inherits (this TypeReference self, string
className)
+ {
+ if (className == null)
+ throw new ArgumentNullException ("className");
+
+ TypeReference current = self;
+ while ((current != null) && (current.FullName !=
"System.Object")) {
+ if (current.FullName == className)
+ return true;
+
+ // FIXME: plugin AssemblyResolver when ready
+ TypeDefinition type = (current as
TypeDefinition);
+ current = (type == null) ? null : type.BaseType;
+ }
+ return false;
+ }
+
+ /// <summary>
+ /// Check if the type represent an array (of any other type).
+ /// </summary>
+ /// <param name="self">The TypeReference on which the extension
method can be called.</param>
+ /// <returns>True if the type is an array, False
otherwise</returns>
+ public static bool IsArray (this TypeReference self)
+ {
+ return (self is ArrayType);
+ }
+
+ /// <summary>
+ /// Checks if type is attribute. Note that it is possible that
+ /// we might now be able to know all inheritance since the
assembly where
+ /// the information resides could be unavailable.
+ /// </summary>
+ /// <param name="self">The TypeDefinition on which the
extension method can be called.</param>
+ /// <returns>True if the type inherits from
<c>System.Attribute</c>,
+ /// False otherwise.</returns>
+ public static bool IsAttribute (this TypeDefinition self)
+ {
+ return self.Inherits ("System.Attribute");
+ }
+
+ /// <summary>
/// Check if the type is a enumeration flags.
/// </summary>
/// <param name="self">The TypeDefinition on which the
extension method can be called.</param>
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches