473,625 Members | 2,733 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(La youtKind.Sequen tial)]
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.SuppressFina lize(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 1303

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1505
by: Raymond Lewallen | last post by:
I know FxCop has its own board on the FxCop website, but I wanted to reach a larger audience. Has anyone here written any custom rules based on the Introspection engine? Even if you have some based on the Reflection engine, I suppose I would like to talk to you about that too, even though the Reflection engine is being phased out. I'm trying to write a simple rule that looks for string comparisons using A = B and make suggestions to...
6
2996
by: Omar | last post by:
Hi, In a JSP I have the next: .... codigo = "<select name='" + nombre + "'>\n<option selected value='default'>Escoge</option><option value='todos'>Todos</option>"; if (miRS != null) while (miRS.next()) {
10
2401
by: BBFrost | last post by:
We just recently moved one of our major c# apps from VS Net 2002 to VS Net 2003. At first things were looking ok, now problems are starting to appear. So far ... (1) ComboBox.SelectedValue = db_value; If the db_value was not included in the ComboBox value list the ComboBox.SelectedIndex used to return -1, Now the very same code is
5
1764
by: Chua Wen Ching | last post by:
I had use fxcop to check my code. I had 1 confusion here. I would normally call a method by this way in my IAnimal: Example: public void CallFuncA(ushort port); But fxcop says i need to write like a property rather than method to this:
4
1395
by: - Steve - | last post by:
I have a cs file I use in an ASP.NET form. The class has several member variables. If I assign a value to those variables in a method, when I get to another method the variable no longer equals what it was assigned. For example: namespace test { public class testClass : Page {
8
1892
by: hansiman | last post by:
Just beginning using FxCop in my asp.net projects... I get a lot of error messages under the header: AvoidUnusedParameters for funtions and routines lik: Sub isUserAuthenticated(ByVal blnLoggedIn As Boolean) If Not (blnLoggedIn) Then System.Web.HttpContext.Current.Response.Redirect(pcPageLogin) End If
2
1383
by: Eric Sabine | last post by:
I'm running FX Cop on my assembly and on a form, tons of my labels and buttons are being flagged with this error. I don't really get the error and what I am supposed to do to resolve the error. I know that even the form generated code isn't FxCop "safe" in the 1.1 DNF but apparently 2.0 will be. Until then... can someone explan to me what needs to be fixed? The button in this example is a simple one called cmdClear. thanks Eric
5
5081
by: Peter Ritchie [C# MVP] | last post by:
I've purposely been ignoring a CA2122 warning in some C++ interop code I've been working on for quite some time. I've just recently had the cycles to investigate the warning. The warning message is as follows Warning CA2122 : Microsoft.Security : MyClass.Method():Void calls into Marshal.GetExceptionPointers():IntPtr which has a LinkDemand. By making this call, Marshal.GetExceptionPointers():IntPtr is indirectly exposed to user code....
6
1368
by: John Wright | last post by:
I ran FxCop against a program and was pleased with the security review except I get the following error: Do not indirectly expose methods How would I fix this code so this error goes away. I think I understand the error, but not the fix. I really need to fix this as it is called from other programs and I do not want code elevating privileges in this function. Thanks.
0
8189
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8692
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8354
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8497
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7182
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6116
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4192
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1499
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.