|
View:
New views
15 Messages
—
Rating Filter:
Alert me
|
|
|
Cecil - Getting the defined attributes propertiesHello. I am using Cecil to try to read my attributes properties: [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] public sealed class TraceMethodAttribute : Attribute { public TraceMethodAttribute() { MethodStart = true; MethodReturn = true; MethodMessages = true; } public bool MethodStart { get; set; } public bool MethodReturn { get; set; } public bool MethodMessages { get; set; } } [TraceMethod(MethodMessages = false)] static void Main(string[] args) { } ... if (attribute.Constructor.DeclaringType.FullName == typeof (TraceMethodAttribute).FullName) { if ((bool)attribute.Fields["MethodMessages"] == true) { EditMethodStart(assembly, method); } This is, I'd like this last block of code to check whenever the attribute applied to Main, for example, has MethodMessages set to true or false. From what I've seen, it seems like both attributes.Fields.Count and attributes.Properties.Count is set to 0. Why is it? Thanks --~--~---------~--~----~------------~-------~--~----~ -- mono-cecil -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: Cecil - Getting the defined attributes propertiesHello again. From what I've seen here http://evain.net/conf/Cecil-MonoMeeting07.pdf, there seems to really exist a bug in cecil with attributes, as the following code does not work:
// asm is an AssemblyDefinition ... foreach (CustomAttribute attribute in asm.CustomAttributes) { Console.WriteLine ( attribute.Constructor.DeclaringType.Name); foreach (object p in attribute.ConstructorParameters) { Console.WriteLine (“param: {0}”, p); } } // AssemblyTitleAttribute // param: Mono.Cecil // AssemblyDescriptionAttribute // param: Library for reading and writing CIL images // ... attribute.ConstructorParameters.Count seems to be always = 0. Any help or comment? On Fri, Aug 7, 2009 at 6:17 PM, Jorge Branco <rush.of.deliverance@...> wrote:
--~--~---------~--~----~------------~-------~--~----~ -- mono-cecil -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: Cecil - Getting the defined attributes propertiesHey, What version of Cecil are you using? On 8/9/09, Jorge Freitas Branco <rush.of.deliverance@...> wrote: > Hello again. From what I've seen here > http://evain.net/conf/Cecil-MonoMeeting07.pdf, there seems > to really exist a bug in cecil with attributes, as the following code does > not work: > > // asm is an AssemblyDefinition ... > foreach (CustomAttribute attribute in asm.CustomAttributes) { > Console.WriteLine ( > attribute.Constructor.DeclaringType.Name); > foreach (object p in attribute.ConstructorParameters) { > Console.WriteLine (“param: {0}”, p); > } > } > // AssemblyTitleAttribute > // param: Mono.Cecil > // AssemblyDescriptionAttribute > // param: Library for reading and writing CIL images > // ... > > attribute.ConstructorParameters.Count seems to be always = > 0. > > Any help or comment? > > > On Fri, Aug 7, 2009 at 6:17 PM, Jorge Branco > <rush.of.deliverance@...> wrote: > > > > > Hello. I am using Cecil to try to read my attributes properties: > > > > [AttributeUsage(AttributeTargets.Method, AllowMultiple = > false, > > Inherited = false)] > > public sealed class TraceMethodAttribute : Attribute { > > public TraceMethodAttribute() { > > MethodStart = true; > > MethodReturn = true; > > MethodMessages = true; > > } > > > > public bool MethodStart { get; set; } > > public bool MethodReturn { get; set; } > > public bool MethodMessages { get; set; } > > } > > > > [TraceMethod(MethodMessages = false)] > > static void Main(string[] args) { > > } > > > > ... > > > > if (attribute.Constructor.DeclaringType.FullName == > typeof > > (TraceMethodAttribute).FullName) { > > if ((bool)attribute.Fields["MethodMessages"] == true) { > > EditMethodStart(assembly, method); > > } > > > > This is, I'd like this last block of code to check whenever the > > attribute applied to Main, for example, has MethodMessages set to true > > or false. From what I've seen, it seems like both > > attributes.Fields.Count and attributes.Properties.Count is set to 0. > > Why is it? > > > > Thanks > > > > > > > > > -- Jb Evain <jb@...> --~--~---------~--~----~------------~-------~--~----~ -- mono-cecil -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: Cecil - Getting the defined attributes properties0.6.9.0
On Sun, Aug 9, 2009 at 12:09 PM, Jb Evain <jb@...> wrote:
--~--~---------~--~----~------------~-------~--~----~ -- mono-cecil -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: Cecil - Getting the defined attributes propertiesOn 8/9/09, Jorge Freitas Branco <rush.of.deliverance@...> wrote: > attribute.ConstructorParameters.Count seems to be always = > 0. > > Any help or comment? It depends on whether the attribute can be resolved or not. What does attribute.Resolved says, and what happens if you call attribute.Resolve () ? -- Jb Evain <jb@...> --~--~---------~--~----~------------~-------~--~----~ -- mono-cecil -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: Cecil - Getting the defined attributes propertiesAttribute.Resolve returns true, but ConstructorParameters.Count seems to be always = 0.
I feel maybe I dont understand well the working of ConstructorParameters. Its length should be the same as the number of properties of the attribute? Thanks On Sun, Aug 9, 2009 at 12:18 PM, Jb Evain <jb@...> wrote:
--~--~---------~--~----~------------~-------~--~----~ -- mono-cecil -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: Cecil - Getting the defined attributes propertiesAh! I guess it will return anything different than what are the default properties, right? I see that if I try it with different arguments on the attribute, after doing Resolve(), it'll show up > 1 on Properties.Count.
On Sun, Aug 9, 2009 at 12:21 PM, Jorge Freitas Branco <rush.of.deliverance@...> wrote: Attribute.Resolve returns true, but ConstructorParameters.Count seems to be always = 0. --~--~---------~--~----~------------~-------~--~----~ -- mono-cecil -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: Cecil - Getting the defined attributes propertiesAlso, what is the expected behaviour of the SaveAssembly() method if we don't actually change anything after loading the assembly? I've checked the checksums of my .exe, both after and before calling SaveAssembly() without having actually changed a thing and they're different. Is this expectable? It seems to be messing up with Visual Studio IDE Debugger, as it points out the wrong exception lines, etc. Maybe I am missnig something? Like in this attributes thing?
On Sun, Aug 9, 2009 at 12:11 PM, Jorge Freitas Branco <rush.of.deliverance@...> wrote: 0.6.9.0 --~--~---------~--~----~------------~-------~--~----~ -- mono-cecil -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: Cecil - Getting the defined attributes propertiesConstructorsParameters is a misnamed property which contains the actual arguments passed to the constructor. Properties and Fields are dictionaries containing the values passed to, well, attribute properties and fields, indexed by their name. So for a class: FooAttribute : Attribute { public string Bar; public string Baz { get; set; } public FooAttribute (string gazonk) {} } And its use: [Foo ("Gazonk", Bar = "bar", Baz = "baz")] ConstructorParameters will contain Gazonk. Fields will contain "Bar" => "bar", and Properties will contain "Baz" => "baz". That's something that is working, not well for some corner cases, but sufficiently enough for most cases. On 8/9/09, Jorge Freitas Branco <rush.of.deliverance@...> wrote: > Attribute.Resolve returns true, but ConstructorParameters.Count seems to be > always = 0. > > I feel maybe I dont understand well the working of ConstructorParameters. > Its length should be the same as the number of properties of the attribute? > > Thanks > > > On Sun, Aug 9, 2009 at 12:18 PM, Jb Evain <jb@...> wrote: > > > > > > On 8/9/09, Jorge Freitas Branco > <rush.of.deliverance@...> wrote: > > > attribute.ConstructorParameters.Count seems to be > always = > > > 0. > > > > > > Any help or comment? > > > > It depends on whether the attribute can be resolved or not. > > What does attribute.Resolved says, and what happens if you call > > attribute.Resolve () ? > > > > -- > > > > > > > > Jb Evain <jb@...> > > > > > > > > > > > -- Jb Evain <jb@...> --~--~---------~--~----~------------~-------~--~----~ -- mono-cecil -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: Cecil - Getting the defined attributes propertiesOn 8/9/09, Jorge Freitas Branco <rush.of.deliverance@...> wrote: > Also, what is the expected behaviour of the SaveAssembly() method if we > don't actually change anything after loading the assembly? I've checked the > checksums of my .exe, both after and before calling SaveAssembly() without > having actually changed a thing and they're different. Is this expectable? > It seems to be messing up with Visual Studio IDE Debugger, as it points out > the wrong exception lines, etc. Maybe I am missnig something? Like in this > attributes thing? Yes it is expected. Cecil has no way to know if you actually modified the assembly or not, so it will serialize it again. With possible changes. You can ask Cecil to read/write the debug symbols so the debugger doesn't get confused. Search the group, it's been covered multiple times. -- Jb Evain <jb@...> --~--~---------~--~----~------------~-------~--~----~ -- mono-cecil -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: Cecil - Getting the defined attributes propertiesI'll do that. Attributes now seem to be working. Thanks!
On Sun, Aug 9, 2009 at 12:28 PM, Jb Evain <jb@...> wrote:
--~--~---------~--~----~------------~-------~--~----~ -- mono-cecil -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: Cecil - Getting the defined attributes propertiesOk, everything seems to be fine now with the lines! Thanks again!
On Sun, Aug 9, 2009 at 12:29 PM, Jorge Freitas Branco <rush.of.deliverance@...> wrote: I'll do that. Attributes now seem to be working. Thanks! --~--~---------~--~----~------------~-------~--~----~ -- mono-cecil -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: Cecil - Getting the defined attributes properties>> That's something that is working, not well for some corner cases, but sufficiently enough for most cases. >> Can you tell an example of a case that fails. I want to reproduce it and if possible fix it - if indeed its fixable. On Aug 9, 4:47 pm, Jorge Freitas Branco <rush.of.delivera...@...> wrote: > Ok, everything seems to be fine now with the lines! Thanks again! > > On Sun, Aug 9, 2009 at 12:29 PM, Jorge Freitas Branco < > > rush.of.delivera...@...> wrote: > > I'll do that. Attributes now seem to be working. Thanks! > > > On Sun, Aug 9, 2009 at 12:28 PM, Jb Evain <j...@...> wrote: > > >> On 8/9/09, Jorge Freitas Branco <rush.of.delivera...@...> wrote: > >> > Also, what is the expected behaviour of the SaveAssembly() method if we > >> > don't actually change anything after loading the assembly? I've checked > >> the > >> > checksums of my .exe, both after and before calling SaveAssembly() > >> without > >> > having actually changed a thing and they're different. Is this > >> expectable? > >> > It seems to be messing up with Visual Studio IDE Debugger, as it points > >> out > >> > the wrong exception lines, etc. Maybe I am missnig something? Like in > >> this > >> > attributes thing? > > >> Yes it is expected. Cecil has no way to know if you actually modified > >> the assembly or not, so it will serialize it again. With possible > >> changes. > > >> You can ask Cecil to read/write the debug symbols so the debugger > >> doesn't get confused. Search the group, it's been covered multiple > >> times. > > >> -- > >> Jb Evain <j...@...> > > -- mono-cecil -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: Cecil - Getting the defined attributes propertiesWas that to me? I don't remember having wrote that.
On Tue, Aug 11, 2009 at 4:46 AM, JohnC <john.crowe6@...> wrote:
--~--~---------~--~----~------------~-------~--~----~ -- mono-cecil -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: Cecil - Getting the defined attributes propertiesSorry, no, that was for Jb. On Aug 11, 9:11 am, Jorge Freitas Branco <rush.of.delivera...@...> wrote: > Was that to me? I don't remember having wrote that. > > On Tue, Aug 11, 2009 at 4:46 AM, JohnC <john.cro...@...> wrote: > > > That's something that is working, not well for some corner cases, but > > sufficiently enough for most cases. > > > Can you tell an example of a case that fails. I want to reproduce it > > and if possible fix it - if indeed its fixable. > > > On Aug 9, 4:47 pm, Jorge Freitas Branco > > <rush.of.delivera...@...> wrote: > > > Ok, everything seems to be fine now with the lines! Thanks again! > > > > On Sun, Aug 9, 2009 at 12:29 PM, Jorge Freitas Branco < > > > > rush.of.delivera...@...> wrote: > > > > I'll do that. Attributes now seem to be working. Thanks! > > > > > On Sun, Aug 9, 2009 at 12:28 PM, Jb Evain <j...@...> wrote: > > > > >> On 8/9/09, Jorge Freitas Branco <rush.of.delivera...@...> > > wrote: > > > >> > Also, what is the expected behaviour of the SaveAssembly() method if > > we > > > >> > don't actually change anything after loading the assembly? I've > > checked > > > >> the > > > >> > checksums of my .exe, both after and before calling SaveAssembly() > > > >> without > > > >> > having actually changed a thing and they're different. Is this > > > >> expectable? > > > >> > It seems to be messing up with Visual Studio IDE Debugger, as it > > points > > > >> out > > > >> > the wrong exception lines, etc. Maybe I am missnig something? Like > > in > > > >> this > > > >> > attributes thing? > > > > >> Yes it is expected. Cecil has no way to know if you actually modified > > > >> the assembly or not, so it will serialize it again. With possible > > > >> changes. > > > > >> You can ask Cecil to read/write the debug symbols so the debugger > > > >> doesn't get confused. Search the group, it's been covered multiple > > > >> times. > > > > >> -- > > > >> Jb Evain <j...@...> > > -- mono-cecil -~----------~----~----~----~------~----~------~--~--- |
| Free embeddable forum powered by Nabble | Forum Help |