Index: src/Common/DelftTools.Utils/Reflection/AssemblyUtils.cs
===================================================================
diff -u -r8f6ae890fed8e8eae3a32f9c0498a10f82e0ddf9 -r5fc71a385897af92ccb092f2f969b5709afab85a
--- src/Common/DelftTools.Utils/Reflection/AssemblyUtils.cs (.../AssemblyUtils.cs) (revision 8f6ae890fed8e8eae3a32f9c0498a10f82e0ddf9)
+++ src/Common/DelftTools.Utils/Reflection/AssemblyUtils.cs (.../AssemblyUtils.cs) (revision 5fc71a385897af92ccb092f2f969b5709afab85a)
@@ -13,8 +13,32 @@
///
public static class AssemblyUtils
{
- private static readonly ILog log = LogManager.GetLogger(typeof (AssemblyUtils));
+ private enum MachineType : ushort
+ {
+ IMAGE_FILE_MACHINE_UNKNOWN = 0x0,
+ IMAGE_FILE_MACHINE_AM33 = 0x1d3,
+ IMAGE_FILE_MACHINE_AMD64 = 0x8664,
+ IMAGE_FILE_MACHINE_ARM = 0x1c0,
+ IMAGE_FILE_MACHINE_EBC = 0xebc,
+ IMAGE_FILE_MACHINE_I386 = 0x14c,
+ IMAGE_FILE_MACHINE_IA64 = 0x200,
+ IMAGE_FILE_MACHINE_M32R = 0x9041,
+ IMAGE_FILE_MACHINE_MIPS16 = 0x266,
+ IMAGE_FILE_MACHINE_MIPSFPU = 0x366,
+ IMAGE_FILE_MACHINE_MIPSFPU16 = 0x466,
+ IMAGE_FILE_MACHINE_POWERPC = 0x1f0,
+ IMAGE_FILE_MACHINE_POWERPCFP = 0x1f1,
+ IMAGE_FILE_MACHINE_R4000 = 0x166,
+ IMAGE_FILE_MACHINE_SH3 = 0x1a2,
+ IMAGE_FILE_MACHINE_SH3DSP = 0x1a3,
+ IMAGE_FILE_MACHINE_SH4 = 0x1a6,
+ IMAGE_FILE_MACHINE_SH5 = 0x1a8,
+ IMAGE_FILE_MACHINE_THUMB = 0x1c2,
+ IMAGE_FILE_MACHINE_WCEMIPSV2 = 0x169,
+ }
+ private static readonly ILog log = LogManager.GetLogger(typeof(AssemblyUtils));
+
///
/// Return attributes for a specific assembly
///
@@ -24,7 +48,7 @@
{
AssemblyInfo info = new AssemblyInfo();
- if(assembly.Location == "")
+ if (assembly.Location == "")
{
return info;
}
@@ -36,9 +60,9 @@
{
info.Title = assemblyTitleAttribute.Title;
}
-
+
var assemblyDescriptionAttribute = GetAssemblyAttributeValue(assembly);
- if(assemblyDescriptionAttribute != null)
+ if (assemblyDescriptionAttribute != null)
{
info.Description = assemblyDescriptionAttribute.Description;
}
@@ -74,24 +98,15 @@
var stackTrace = new StackTrace(false);
if (stackTrace.ToString().ToLower().Contains("test."))
{
- return new AssemblyInfo { Company = "Deltares", Product = "Delta Shell", Version = "Tests Development" };
+ return new AssemblyInfo
+ {
+ Company = "Deltares", Product = "Delta Shell", Version = "Tests Development"
+ };
}
return GetAssemblyInfo(Assembly.GetExecutingAssembly());
}
- private static T GetAssemblyAttributeValue(Assembly assembly) where T : class
- {
- object[] attributes = assembly.GetCustomAttributes(typeof (T), true);
-
- if (attributes.Length == 0)
- {
- return null;
- }
-
- return (T) attributes[0];
- }
-
///
/// Gets types in a given assembly derived from a given type.
///
@@ -156,10 +171,16 @@
{
Type foundType = a.GetType(typeName);
if (foundType != null)
+ {
if (result == null)
+ {
result = foundType;
+ }
else
+ {
throw new Exception("Type found in multiple assemblies");
+ }
+ }
}
return result;
}
@@ -178,25 +199,7 @@
assembly.GetManifestResourceStream).First();
}
- #region Nested type: AssemblyInfo
-
///
- /// structure containing assembly attributes as strings.
- ///
- [Serializable]
- public struct AssemblyInfo
- {
- public string Company;
- public string Copyright;
- public string Description;
- public string Product;
- public string Title;
- public string Version;
- }
-
- #endregion
-
- ///
/// This method checks if a file is a managed dll. It's based on how the file command on linux works.
///
/// path of dll
@@ -222,7 +225,7 @@
int i2 = fs.ReadByte();
fs.Close();
-
+
var isManagedDll = i1 == 0x80 && i2 == 0x03;
//Debug.WriteLine(path + ": " + (isManagedDll?"managed":"unmanaged"));
@@ -261,7 +264,7 @@
}
var assemblyName = Path.GetFileNameWithoutExtension(filename);
-
+
//log.DebugFormat("Loading {0}", filename);
Assembly a;
@@ -279,6 +282,18 @@
}
}
+ private static T GetAssemblyAttributeValue(Assembly assembly) where T : class
+ {
+ object[] attributes = assembly.GetCustomAttributes(typeof(T), true);
+
+ if (attributes.Length == 0)
+ {
+ return null;
+ }
+
+ return (T) attributes[0];
+ }
+
private static MachineType GetDllMachineType(string dllPath)
{
//see http://www.microsoft.com/whdc/system/platform/firmware/PECOFF.mspx
@@ -292,35 +307,31 @@
fs.Seek(peOffset, SeekOrigin.Begin);
var peHead = br.ReadUInt32();
if (peHead != 0x00004550) // "PE\0\0", little-endian
+ {
throw new Exception("Can't find PE header");
- var machineType = (MachineType)br.ReadUInt16();
+ }
+ var machineType = (MachineType) br.ReadUInt16();
br.Close();
fs.Close();
return machineType;
}
- private enum MachineType : ushort
+ #region Nested type: AssemblyInfo
+
+ ///
+ /// structure containing assembly attributes as strings.
+ ///
+ [Serializable]
+ public struct AssemblyInfo
{
- IMAGE_FILE_MACHINE_UNKNOWN = 0x0,
- IMAGE_FILE_MACHINE_AM33 = 0x1d3,
- IMAGE_FILE_MACHINE_AMD64 = 0x8664,
- IMAGE_FILE_MACHINE_ARM = 0x1c0,
- IMAGE_FILE_MACHINE_EBC = 0xebc,
- IMAGE_FILE_MACHINE_I386 = 0x14c,
- IMAGE_FILE_MACHINE_IA64 = 0x200,
- IMAGE_FILE_MACHINE_M32R = 0x9041,
- IMAGE_FILE_MACHINE_MIPS16 = 0x266,
- IMAGE_FILE_MACHINE_MIPSFPU = 0x366,
- IMAGE_FILE_MACHINE_MIPSFPU16 = 0x466,
- IMAGE_FILE_MACHINE_POWERPC = 0x1f0,
- IMAGE_FILE_MACHINE_POWERPCFP = 0x1f1,
- IMAGE_FILE_MACHINE_R4000 = 0x166,
- IMAGE_FILE_MACHINE_SH3 = 0x1a2,
- IMAGE_FILE_MACHINE_SH3DSP = 0x1a3,
- IMAGE_FILE_MACHINE_SH4 = 0x1a6,
- IMAGE_FILE_MACHINE_SH5 = 0x1a8,
- IMAGE_FILE_MACHINE_THUMB = 0x1c2,
- IMAGE_FILE_MACHINE_WCEMIPSV2 = 0x169,
+ public string Company;
+ public string Copyright;
+ public string Description;
+ public string Product;
+ public string Title;
+ public string Version;
}
+
+ #endregion
}
}
\ No newline at end of file