Discussion:
How to get initial value of fields when value is a string?
earlz
2012-11-12 02:45:56 UTC
Permalink
Hi, I'm trying to use Mono.Cecil to track down every single string in a
.Net application. One of the problems I'm having is I can't seem to get the
value of an initial field value when it's a string.
Example:

class Foo {
public string Bar="foobar"; //how to get foobar?
}

When I iterate over the Fields member of the Mono.Cecil type for Foo, I can
get a reference to Bar, but it says it has an initial value of byte[0].

Any ideas how to get this?
--
--
mono-cecil
Greg Young
2012-11-12 02:47:22 UTC
Permalink
There is a constructor that's generated that sets it...
Post by earlz
Hi, I'm trying to use Mono.Cecil to track down every single string in a
.Net application. One of the problems I'm having is I can't seem to get the
value of an initial field value when it's a string.
class Foo {
public string Bar="foobar"; //how to get foobar?
}
When I iterate over the Fields member of the Mono.Cecil type for Foo, I
can get a reference to Bar, but it says it has an initial value of byte[0].
Any ideas how to get this?
--
--
mono-cecil
--
Le doute n'est pas une condition agréable, mais la certitude est absurde.
--
--
mono-cecil
earlz
2012-11-12 02:59:18 UTC
Permalink
Ah, just now thought to actually analyze the IL. I had assumed that there
was some kind of special metadata for strings. Guess it's just another
object when it boils down to IL level.
Post by Greg Young
There is a constructor that's generated that sets it...
Post by earlz
Hi, I'm trying to use Mono.Cecil to track down every single string in a
.Net application. One of the problems I'm having is I can't seem to get the
value of an initial field value when it's a string.
class Foo {
public string Bar="foobar"; //how to get foobar?
}
When I iterate over the Fields member of the Mono.Cecil type for Foo, I
can get a reference to Bar, but it says it has an initial value of byte[0].
Any ideas how to get this?
--
--
mono-cecil
--
Le doute n'est pas une condition agréable, mais la certitude est absurde.
--
--
mono-cecil
Loading...