473,416 Members | 1,858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

Why FXCop recommends me not to do this way of method calling?

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:

public void CallFuncA(ushort port)
{
this.port = port;
}

Any idea? Is it a must and best practices for us to follow what fxcop says? I had so many errors in there. Sigh... i didn't know i code so bad. :(
--
Regards,
Chua Wen Ching :)
Nov 16 '05 #1
5 1741
You have here ambiguous variable name (port). Try not to use the same name
for external and internal variables. eg. change you function to "public void
CallFuncA(ushort Port);" This should solve the problem
--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "
"Chua Wen Ching" <ch************@nospam.hotmail.com> wrote in message
news:49**********************************@microsof t.com...
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:

public void CallFuncA(ushort port)
{
this.port = port;
}

Any idea? Is it a must and best practices for us to follow what fxcop says? I had so many errors in there. Sigh... i didn't know i code so bad. :( --
Regards,
Chua Wen Ching :)

Nov 16 '05 #2
Hi Tamir Khason,

This is what i normally will do.

private ushort port;

public ushort Port
{
get { return port; }
set { this.port = port; }
}

public void CallFuncA(ushort port) {}

---

Does it means, now i just ignore the code above and just do this:

private ushort port;

public void CallFuncA(ushort Port) {}

Just to confirm. Thanks again.
--
Regards,
Chua Wen Ching :)
"Tamir Khason" wrote:
You have here ambiguous variable name (port). Try not to use the same name
for external and internal variables. eg. change you function to "public void
CallFuncA(ushort Port);" This should solve the problem
--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "
"Chua Wen Ching" <ch************@nospam.hotmail.com> wrote in message
news:49**********************************@microsof t.com...
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:

public void CallFuncA(ushort port)
{
this.port = port;
}

Any idea? Is it a must and best practices for us to follow what fxcop

says? I had so many errors in there. Sigh... i didn't know i code so bad. :(
--
Regards,
Chua Wen Ching :)


Nov 16 '05 #3
OK,
The only thing it notice, that if you have method return void it'll better
to make it property with things you want to do in get/set area. However me
too prefer void method rather then complicated property even for user
friendly reflection of things, however there are people prefer properties
rather then methods.

You choose...

The only best practice I can think about in your case is avoiding of using
many member variables and declaration of local variables and pass it to
methods instead of sharing a member variable between methods. If you share a
member variable between methods, it will be difficult to track which method
changed the value and when.

As I said - you choose, maybe I'm wrong

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "
"Chua Wen Ching" <ch************@nospam.hotmail.com> wrote in message
news:90**********************************@microsof t.com...
Hi Tamir Khason,

This is what i normally will do.

private ushort port;

public ushort Port
{
get { return port; }
set { this.port = port; }
}

public void CallFuncA(ushort port) {}

---

Does it means, now i just ignore the code above and just do this:

private ushort port;

public void CallFuncA(ushort Port) {}

Just to confirm. Thanks again.
--
Regards,
Chua Wen Ching :)
"Tamir Khason" wrote:
You have here ambiguous variable name (port). Try not to use the same name
for external and internal variables. eg. change you function to "public void CallFuncA(ushort Port);" This should solve the problem
--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "
"Chua Wen Ching" <ch************@nospam.hotmail.com> wrote in message
news:49**********************************@microsof t.com...
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:
public void CallFuncA(ushort port)
{
this.port = port;
}

Any idea? Is it a must and best practices for us to follow what fxcop

says? I had so many errors in there. Sigh... i didn't know i code so

bad. :(
--
Regards,
Chua Wen Ching :)


Nov 16 '05 #4
CallFuncA has a parameter with the same name as one of the fields of
the class. You might want to consider using a different convention to
avoid possible confusion, or take another look at the class design to
see if you really need to pass a port to the method at all.

--
Scott
http://www.OdeToCode.com

On Mon, 5 Jul 2004 02:15:01 -0700, "Chua Wen Ching"
<ch************@nospam.hotmail.com> wrote:
Hi Tamir Khason,

This is what i normally will do.

private ushort port;

public ushort Port
{
get { return port; }
set { this.port = port; }
}

public void CallFuncA(ushort port) {}

---

Does it means, now i just ignore the code above and just do this:

private ushort port;

public void CallFuncA(ushort Port) {}

Just to confirm. Thanks again.


Nov 16 '05 #5
Can you clarify something -- you mentioned an IAnimal, which to me implies
an interface -- which has no implementation, so I don't see where there's
room for fxcop to suggest use of a property.

But looking at what you've written below, the set accessor in the code you
gave is effectively a no-op as it just assigns a value to itself.

Try to follow this pattern (note capitalization):

private ushort port;

public ushort Port
{
get { return this.port; }
set { this.port = value; }
}

Note the use of 'this.' even where it's not technically needed (thus does
'this.' function much as the 'm_' or whatever from the days of old). If you
get into this habit, you will help avoid errors and make your code easier to
read.

Are you saying that the above code would cause fxcop to warn on

public void FuncA(ushort port) {}

as a class method? Seems odd if that's the case.
"Chua Wen Ching" <ch************@nospam.hotmail.com> wrote in message
news:90**********************************@microsof t.com...
Hi Tamir Khason,

This is what i normally will do.

private ushort port;

public ushort Port
{
get { return port; }
set { this.port = port; }
}

public void CallFuncA(ushort port) {}

---

Does it means, now i just ignore the code above and just do this:

private ushort port;

public void CallFuncA(ushort Port) {}

Just to confirm. Thanks again.
--
Regards,
Chua Wen Ching :)
"Tamir Khason" wrote:
You have here ambiguous variable name (port). Try not to use the same name
for external and internal variables. eg. change you function to "public void CallFuncA(ushort Port);" This should solve the problem
--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "
"Chua Wen Ching" <ch************@nospam.hotmail.com> wrote in message
news:49**********************************@microsof t.com...
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:
public void CallFuncA(ushort port)
{
this.port = port;
}

Any idea? Is it a must and best practices for us to follow what fxcop

says? I had so many errors in there. Sigh... i didn't know i code so

bad. :(
--
Regards,
Chua Wen Ching :)


Nov 16 '05 #6

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

Similar topics

0
by: Chua Wen Ching | last post by:
Hi there, I am super confuse on this recommendation by FxCop. 1) http://www.gotdotnet.com/team/fxcop/docs/rules/UsageRules/OperatorEqualsOverridesRequireEqualsOverridel.html First of all,...
1
by: Sharon | last post by:
In the report of the FxCop analysis: CriticalError, Certainty 95, for "TypesThatOwnDisposableFieldsShouldBeDisposable" { Target : "Receiver" (IntrospectionTargetType) Resolution : "Implement...
8
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...
2
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...
0
by: IGotNothin | last post by:
I'm running FxCop on one of my vb.net projects. One of the items is recommends is removing: Private designerPlaceholderDeclaration As System.Object ....as it is never used or is only ever...
4
by: Bruce One | last post by:
Given a project with some .cs files, Is there a way to block some of these files to be read by FxCop ?
5
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...
3
by: AlexS | last post by:
When I implement Dispose pattern in object implementing IDisposable, current fxcop recommends: Ensure that Wrapper.Dispose():Void is declared as public and sealed. However, if I do as it asks,...
1
by: Water Cooler v2 | last post by:
I am trying to add FxCop to work inside Visual Studio 2005 Professional Edition. I believe there are two approaches. The first is outlined in this short article: ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...
0
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...

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.