Le 2011-03-11 à 00:44, Brian <[email protected]> a écrit :

> Excellent -- thanks Sebastien.  Daniel -- I ended up doing pretty much
> what was in the interop rules like PInvokeShouldNotBeVisible... that
> seemed to be really close to what I want to do.
>
> The last thing I'm trying to accomplish is see if the user has
> implemented a constructor, other than the default ctor.

The default ctor has no parameters, so something like:

bool is_non_default = method.IsConstructor && method.HasParameters;

should do. Of course this will be false for a static constructor
(.cctor) and you likely want to know/check the visibility of the ctors
too.


>  I realize it
> sounds a bit strange, but there's a situation where it would be
> helpful to see if, in a class, the developer has actually implemented
> a ctor.

The above should work for "non default" ctors - both .ctor() and .cctor()


> Guessing this could could accomplished by determining the
> number of instructions with the ctor?

The number of IL instruction will vary. E.g. depending on the fields
being initialized in the type. So you'll need a bit more code if you
take this approach.

> (Since I don't think it's
> possible to determine if there's an empty ctor vs the default ctor
> added automatically.)

Not that I know of (they are not decorated with any generated code
attribute). Anyway that's compiler specific (and the content is
subject to change between compiler versions).

Sebastien

>
>
> On Mar 7, 8:27 am, Sebastien Pouliot <[email protected]>
> wrote:
>> Hello Brian,
>>
>> On Mar 5, 5:33 pm, Brian <[email protected]> wrote:
>>
>>> Hi folks,
>>
>>> I'm brand new to Gendarme -- basically looking at creating some quick
>>> rules to catch a few in house rules on .NET assemblies --
>>> specifically, was looking how to block entire namespaces like
>>> System.Reflection (I think this one is easy but was having issues
>>> doing this -- I figured out how to catch specific classes, but I'm
>>> doing something wrong on the entire namespace).  Also, was trying to
>>> detect unsafe and/or P/Invoke callsbut not quite getting it.
>>
>>> Any tips?
>>
>> Since source code for all Gendarme (>250) rules is available your best
>> bet is to find something similar and adapt it to your specific needs.
>> Most of them are really small and easy to read/understand.
>>
>> E.g. "was looking how to block entire namespaces like
>> System.Reflection"
>>
>> that sounds a bit like
>> Gendarme.Rules.BadPractice.AvoidCallingProblematicMethodsRule
>> doc @https://github.com/spouliot/gendarme/wiki/Gendarme.Rules.BadPractice....
>> sources 
>> @https://github.com/mono/mono-tools/blob/master/gendarme/rules/Gendarm...
>>
>> E.g. "detect unsafe and/or P/Invoke calls"
>>
>> Pinvoke are easy to find, see
>> Gendarme.Rules.Interoperability.PInvokeShouldNotBeVisibleRule
>> doc @https://github.com/spouliot/gendarme/wiki/Gendarme.Rules.Interoperabi...
>> sources 
>> @https://github.com/mono/mono-tools/blob/master/gendarme/rules/Gendarm...
>>
>> However there is no metadata properties that will tell you if you're
>> dealing with unsafe code or not. You'll need to provide your own code
>> to detect this (e.g. some instructions are unverifiable, uses of
>> pointers...). You can look at Cecil's archive mails (or ask on it's
>> mailing-list), I'm pretty sure there's someone who already has some
>> code for doing so.
>>
>> Sebastien
>>
>> p.s. link to sources are against Gendarme 'master' which has new API
>> splitting the Name and Namespace parameters (instead of using
>> FullName). Either use/build Gendarme from GIT (futureproof) or look at
>> the source code from mono-2-10 branch (for Gendarme 2.10).
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Gendarme" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/gendarme?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Gendarme" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/gendarme?hl=en.

Reply via email to