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 :)