Hi!
I'm working with Cecil and .NET CF to implement an OR-Mapper for a
practical exercise during my academic studies.
Everything worked fine, but now I encountered a Problem:
I want to extract all CustomAttributes of an Method, but
MethodDefinition.CustomAttributes always returns an empty
Collection...
Here is what I have done
AttributeClass:
[AttributeUsage(AttributeTargets.Property, AllowMultiple=true)]
public class ColumnAttribute : Attribute
{
public const string DEFAULTTARGET =
"e6e8fc76-9939-40a2-9ee9-168b8a52bc93";
private string _columnMapping;
private string _target;
public ColumnAttribute() {
_target = DEFAULTTARGET;
_columnMapping = null;
}
/// <summary>
/// Initializes a new instance of the <see
cref="ColumnAttribute"/> class.
/// </summary>
/// <param name="columnMapping">The name of the column in the
data base.</param>
public ColumnAttribute(string columnMapping) {
_target = DEFAULTTARGET;
ColumnMapping = columnMapping;
}
public string Target { get { return _target; } set { _target =
value; } }
public string ColumnMapping { get { return
this._columnMapping; } internal set { this._columnMapping = value; } }
}
A Type Using the Attribute:
public class CollectionEvent : SerializableObject
{
...
[Column(Target="replication")]
[Column]
public int? SeriesID { get { return _SeriesID; } set
{ _SeriesID = value; } }
...
}
And now the Fragment using Cecil
...
_assemby = AssemblyFactory("DivMobi Collection Data Layer.dll");
foreach(TypeDefinition typeDef in _assembly.MainModule.Types) {
if(typeDef.Name != "<Module>")
{
foreach(MethodDefinition mDef in typeDef.Methods)
{
foreach(CustomAttribute ca in
mDef.CustomAttributes)
{
//do something with ca ....
}
}
}
}
The problem is that no CustomAttribute is returned...
Extracting CustomAttributes of Assemblies and TypeDefinitions works
fine ...
Thanks in advance,
storki!
--~--~---------~--~----~------------~-------~--~----~
--
mono-cecil
-~----------~----~----~----~------~----~------~--~---