Can Fxcop realize to analysis unmanaged Code?

Hi All:

May I ask tow questions about Fxcop?

1.Now I want to realize the function that i want to analysis the unmanaged code such as

DLLImportAttibute.SetLastError . I want to check if SetLastError is set 'true'.

2.I want to check whether there is hard code in the codes? can you give me some suggestions?

[340 byte] By [sammychen] at [2007-12-28]
# 1

1) Is actually represented as managed code. This attribute is not actually represented as a 'real' attribute within the Method.Attributes collection.

To check for this, you first need to determine if the method you are looking at is a P/Invoke and then you check the PInvokeFlags property:



public ProblemCollection Check(Member member)
{
Method method = member as Method;
if (method == null)
return null;

// Make sure we have a p/invoke
if ((method.Flags & MethodFlags.PInvokeImpl) != MethodFlags.PInvoke.Impl)
return null;

if ((method.PInvokeFlags & PInvokeFlags.SupportsLastError) == PInvokeFlags.SupportsLastError))
{
// SetLastError = true
// Add Problems
}
}

With regards to your second question, I'm not sure what you are after. You are going to have to clarify.

Regards

David

DavidM.Kean-MSFT at 2007-9-4 > top of Msdn Tech,Visual Studio Team System,Visual Studio Code Analysis and Code Metrics...
# 2

Thanks for your reply.

I managed to realize it .

thanks .

The Second question i mean that

for example

string str1 = "sammy";

"sammy" is called hard code in our country.

the right statement should be like that

string str1 = CosntClass.Sammy;

sammychen at 2007-9-4 > top of Msdn Tech,Visual Studio Team System,Visual Studio Code Analysis and Code Metrics...
# 3

Sammy,

Unfortunately, constant assignments are stored as literals within IL.

That means that:



string str1 = "sammy";

Looks the same as (if ConstClass.Sammy is a constant):



string str1 = ConstClass.Sammy.1

You could look to see if there was a constant within the class with the same value, but this wouldn't catch the situation above. There isn't a good way to do this.

Regards

David

DavidM.Kean-MSFT at 2007-9-4 > top of Msdn Tech,Visual Studio Team System,Visual Studio Code Analysis and Code Metrics...
# 4
Ok. Thanks For your reply.
sammychen at 2007-9-4 > top of Msdn Tech,Visual Studio Team System,Visual Studio Code Analysis and Code Metrics...

Visual Studio Team System

Site Classified