468,133 Members | 1,181 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,133 developers. It's quick & easy.

FXCop - had problems with it, example the needs of Object.Equals()

Hi there,

I am super confuse on this recommendation by FxCop.

1)
http://www.gotdotnet.com/team/fxcop/...Overridel.html

First of all, let me explain how i see that problem:

I had a C program that does this:

typedef unsigned char uint8;
typedef uint8 *puint8;

typedef struct TagStructure
{
uint8 var1;
uint8 var2;
puint8 HeaderIN;
puint8 HeaderOut;
}

I try to code this in C#:

public class PortExample : IDisposable
{
private bool disposed = false;

public PortExample()
{

}

~PortExample()
{
Dispose(false);
}

[StructLayout(LayoutKind.Sequential)]
public struct TagStructure
{
private int field;

private byte var1;
private byte var2;
public TagInstruction(int value)
{
field = value;
}

public byte Var1
{
get
{
return var1;
}
set
{
this.var1 = value;
}
}

public byte Var2
{
get
{
return var2;
}
set
{
this.var2 = value;
}
}
public readonly IntPtr HeaderIN;
public readonly IntPtr HeaderOut;
}

#region IDisposable Members

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing)
{

if (!disposed)
{
if (disposing)
{
// Release managed resources
}
disposed = true;
}
}

#endregion

The problems is i had no idea why should i placed Object.Equals() here, why? I don't even compare an object with another object. Also it mentions that something related to value type. I am confuse.

2)
I also declare this in my structure. FXcop recommends me to use readonly or private. Well my other class (different file) needs to call this structure, and use this pointer. If i use private, i don't think it will work. But if i use readonly, i can't point to any other address, as I believe readonly, you can't change the value. How do i solve this issue?

public readonly IntPtr HeaderIN;
public readonly IntPtr HeaderOut;

3) FxCop also recommends me to use a non parameterless constructor inside the struct.

public TagInstruction(int value)
{
field = value;
}

The problem, i don't see why i should place the constructor in there for? I don't need it.

Any help please? Thanks.
--
Regards,
Chua Wen Ching :)
Nov 16 '05 #1
0 1093

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Raymond Lewallen | last post: by
4 posts views Thread by - Steve - | last post: by
8 posts views Thread by hansiman | last post: by
2 posts views Thread by Eric Sabine | last post: by
5 posts views Thread by Peter Ritchie [C# MVP] | last post: by
27 posts views Thread by didacticone | last post: by
1 post views Thread by gcdp | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.