Hello -
You can read module-level attributes from J# code, but you can't write
them. Module-level attributes are not currently supported.
Have you confirmed that the attribute is actually there at the module
level? It should be listed in the .module section of the assembly manifest
for the module(s) in question. You can use the ildasm tool in the .NET SDK
to view the manifest.
For Example:
module CSCustAttribute.dll
// MVID: {24A00368-13CB-41BE-B9AA-EEA9F7113147}
custom instance void
ReflectionModule_Examples.MySimpleAttribute::.ctor(string) = ( 01 00 0C 6D
6F 64 75 6C 65 2D 6C 65 76 65 6C 00 // ...module-level.
00 )
imagebase 0x11000000
subsystem 0x00000003
file alignment 4096
corflags 0x00000001
// Image base: 0x06c40000
When I use Assembly.LoadFile to load a CSharp assembly that I know has a
module level custom attribute, I am able to read that from J# code.
import System.*;
import System.Reflection.*;
class MyMainClass
{
public static void main(String[] args)
{
Module[] moduleArray;
//moduleArray = Assembly.GetExecutingAssembly().GetModules(false);
moduleArray = Assembly.LoadFile(<FullPathToFile>).GetModules();
Module myModule = moduleArray[0];
Object[] attributes;
attributes = myModule.GetCustomAttributes(true);
for (int i = 0; i < attributes.length; i++)
{
Console.WriteLine("Found this attribute on myModule: {0}",
attributes[i].ToString());
}
}
}
>hello,
I want to get Custom Attributes of a module.So i have used
GetCustomAttributes function as follows
Module moduleArray[];
moduleArray = Assembly.GetExecutingAssembly().GetModules(false);
Module myModule = (Module)moduleArray.get_Item(0);
bject attributes[];
attributes = myModule.GetCustomAttributes(true);
But I am not getting arributes in the variable attributes.
Can any one help me out.
Thanks,
Xyz
Bob LaCasse
Microsoft Developer Support - Visual J#.NET
This posting is provided AS IS with no warranties, and confers no rights.
Xyz - 14 Feb 2004 05:01 GMT
Hi
The module level attribute is defined in the same code itself .The whole code is
//Define a module-level attribute
/** @module ReflectionModule_Examples.MySimpleAttribute("module-level"
* *
class MyMainClas
public static void main(String[] args
Module moduleArray[]
moduleArray = Assembly.GetExecutingAssembly().GetModules(false)
// In a simple project with only one module, the module at inde
// 0 will be the module containing these classes
Module myModule = (Module)moduleArray.get_Item(0)
Object attributes[]
attributes = myModule.GetCustomAttributes(true)
for (int i = 0; i < attributes.length; i++
Object o = attributes[i]
Console.WriteLine("Found this attribute on myModule: {0}.", o.toString())
} //Mai
} //MyMainClas
//A very simple custom attribute
/** @attribute AttributeUsage(AttributeTargets.Class | AttributeTargets.Module
* *
public class MySimpleAttribute extends Attribut
private String name
public MySimpleAttribute(String newName
name = newName
} //MySimpleAttribut
} //MySimpleAttribute
// </snippet1
But still i am not getting the custom attributes.
Thanks,
Bob LaCasse [MSFT] - 18 Feb 2004 20:43 GMT
Hello - I will have another look at this, but what I think is happening is
that the compiler is ignoring your @module directive as just a comment.
That is why I would suggest you confirm the existence of the attribute in
the metadata. If it is not there, the compiler has skipped it. What is
confusing about this is that this directive shows up in the IntelliSense,
and I am asking about that ... but, there is no documentation about support
for this directive and it is not included in the docs for other like-kind
directives ...
The module level attribute is defined in the same code itself .The whole
code is
//Define a module-level attribute.
/** @module ReflectionModule_Examples.MySimpleAttribute("module-level")
* */
class MyMainClass
{
public static void main(String[] args)
{
Module moduleArray[];
moduleArray = Assembly.GetExecutingAssembly().GetModules(false);
// In a simple project with only one module, the module at index
// 0 will be the module containing these classes.
Module myModule = (Module)moduleArray.get_Item(0);
Object attributes[];
attributes = myModule.GetCustomAttributes(true);
for (int i = 0; i < attributes.length; i++)
{
Object o = attributes[i];
Console.WriteLine("Found this attribute on myModule: {0}.",
o.toString());
}
} //Main
} //MyMainClass
//A very simple custom attribute.
/** @attribute AttributeUsage(AttributeTargets.Class |
AttributeTargets.Module)
* */
public class MySimpleAttribute extends Attribute
{
private String name;
public MySimpleAttribute(String newName)
{
name = newName;
} //MySimpleAttribute
} //MySimpleAttribute
// </snippet1>
But still i am not getting the custom attributes.
Thanks,
Bob LaCasse
Microsoft Developer Support - Visual J#.NET
This posting is provided AS IS with no warranties, and confers no rights.