[Mono-devel-list] [PATCH] Check for assembly attributes
Marek Safar
marek.safar at seznam.cz
Thu Aug 4 03:09:30 EDT 2005
Hello Carlos,
>A patch is attached, containing a check for InternalsVisibleToAttribute,
>when it is applied to an assembly. It reports a warning or shows an
>error, just like csc does.
>
>
>
>
+ if (a == null)
+ throw new ArgumentNullException ("a");
This will never happen.
+ if (t.Equals (typeof (System.Runtime.CompilerServices.InternalsVisibleToAttribute))) {
Please use direct comparison with type declared in TypeManager. See how it's used elsewhere.
+ string [] args = a.GetString ().Trim ().Split (new char [] {','});
a.GetString () can return null.
+ CheckAttributeValid (a);
Could you rename the method to be more explicit ?
+ Report.Warning (1700, a.Location, "Assembly reference '" + a.GetString () + "' is invalid and cannot be resolved");
Here you are missing warning level (2nd parameter)
Do you have tests for this ?
Marek
>------------------------------------------------------------------------
>
>Index: ChangeLog
>===================================================================
>--- ChangeLog (revisión: 47987)
>+++ ChangeLog (copia de trabajo)
>@@ -1,3 +1,9 @@
>+2005-08-03 Carlos Alberto Cortez <calberto at gmail.com>
>+
>+ * codegen.cs
>+ (AssemblyClass.CheckAttributeValid): New method to check
>+ validity in assembly attributes.
>+
> 2005-08-03 Martin Baulig <martin at ximian.com>
>
> Make iterators in generic methods work; see gtest-191.cs.
>Index: codegen.cs
>===================================================================
>--- codegen.cs (revisión: 47987)
>+++ codegen.cs (copia de trabajo)
>@@ -1186,6 +1186,45 @@
> Report.Error (1548, "Error during assembly signing. " + text);
> }
>
>+ void CheckAttributeValid (Attribute a)
>+ {
>+ if (a == null)
>+ throw new ArgumentNullException ("a");
>+
>+ Type t = a.Type;
>+ if (t.Equals (typeof (System.Runtime.CompilerServices.InternalsVisibleToAttribute))) {
>+ string [] args = a.GetString ().Trim ().Split (new char [] {','});
>+
>+ bool is_name_valid = true;
>+ bool version = false, culture = false, key_token = false;
>+ for (int i = 1; i < args.Length; i++) {
>+ string [] values = args [i].Split (new char [] {'='});
>+ if (values.Length < 2 || values [1] == String.Empty) {
>+ is_name_valid = false;
>+ break;
>+ }
>+
>+ if (String.Compare (values [0], "Version", true) == 0)
>+ version = true;
>+ else if (String.Compare (values [0], "Culture", true) == 0)
>+ culture = true;
>+ else if (String.Compare (values [0], "PublicKeyToken", true) == 0)
>+ key_token = true;
>+ // PublicKey is the only valid entry
>+ else if (String.Compare (values [0], "PublicKey", true) != 0) {
>+ is_name_valid = false;
>+ break;
>+ }
>+ }
>+
>+ // If the name is invalid, report CS1700
>+ if (!is_name_valid || args [0] == "")
>+ Report.Warning (1700, a.Location, "Assembly reference '" + a.GetString () + "' is invalid and cannot be resolved");
>+ else if (culture || key_token || version)
>+ throw new Exception ("Friend assembly '" + a.GetString () + "' is invalid. InternalsVisibleTo cannot have version, culture or key token specified.");
>+ }
>+ }
>+
> public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder customBuilder)
> {
> if (a.Type.IsSubclassOf (TypeManager.security_attr_type) && a.CheckSecurityActionValidity (true)) {
>@@ -1196,6 +1235,7 @@
> return;
> }
>
>+ CheckAttributeValid (a);
> Builder.SetCustomAttribute (customBuilder);
> }
>
>
>
>------------------------------------------------------------------------
>
>_______________________________________________
>Mono-devel-list mailing list
>Mono-devel-list at lists.ximian.com
>http://lists.ximian.com/mailman/listinfo/mono-devel-list
>
>
More information about the Mono-devel-list
mailing list