Tuesday, December 18, 2007

Debug o Release?

. Tuesday, December 18, 2007

Tramite la reflection è possibile conoscere se un determinato assembly è stato compilato in modalità debug o release, andando a spulciare nella lista degli attributi:

   1: Private Function VerifyDebug() As Boolean
   2:   Dim assembly As Assembly = Reflection.Assembly.LoadFile("path assembly")
   3:   Dim attributes() As Object = assembly.GetCustomAttributes(True)
   4:   If Not (attributes Is Nothing) AndAlso (attributes.Length > 0) Then
   5:     For i As Integer = 0 To attributes.Length - 1
   6:       If (attributes(i).GetType() Is GetType(System.Diagnostics.DebuggableAttribute)) Then
   7:         Return True
   8:       End If
   9:     Next
  10:   End If
  11:   Return False
  12: End Function

Con il ciclo sugli attributi vado a verificare se è presente l'attributo DebuggableAttribute, attributo non presente se l'assembly è stato generato in modalità release.

0 commenti:

Post a Comment