473,729 Members | 2,344 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(ushor t port);

But fxcop says i need to write like a property rather than method to this:

public void CallFuncA(ushor t 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 1770
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(ushor t 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******** *************** ***********@mic rosoft.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(ushor t port);

But fxcop says i need to write like a property rather than method to this:

public void CallFuncA(ushor t 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(ushor t port) {}

---

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

private ushort port;

public void CallFuncA(ushor t 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(ushor t 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******** *************** ***********@mic rosoft.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(ushor t port);

But fxcop says i need to write like a property rather than method to this:

public void CallFuncA(ushor t 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******** *************** ***********@mic rosoft.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(ushor t port) {}

---

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

private ushort port;

public void CallFuncA(ushor t 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(ushor t 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******** *************** ***********@mic rosoft.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(ushor t port);

But fxcop says i need to write like a property rather than method to this:
public void CallFuncA(ushor t 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(ushor t port) {}

---

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

private ushort port;

public void CallFuncA(ushor t 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******** *************** ***********@mic rosoft.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(ushor t port) {}

---

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

private ushort port;

public void CallFuncA(ushor t 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(ushor t 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******** *************** ***********@mic rosoft.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(ushor t port);

But fxcop says i need to write like a property rather than method to this:
public void CallFuncA(ushor t 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
1309
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, let me explain how i see that problem: I had a C program that does this:
1
1959
by: Sharon | last post by:
In the report of the FxCop analysis: CriticalError, Certainty 95, for "TypesThatOwnDisposableFieldsShouldBeDisposable" { Target : "Receiver" (IntrospectionTargetType) Resolution : "Implement IDisposable on 'Receiver' as it instantiates members of the following IDisposable types: System.Net.Sockets.Socket" Help :...
8
1895
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
1391
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
0
1000
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 assigned to. I can't find anything on what this is, but it's in every vb.net file I create. Along with the warning:
4
379
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
5091
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....
3
4380
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, compiler complains that sealed can't be used because method is not overrideable. I believe sealed isn't applicable here at all. And this rule shouldn't be public virtual in this case.
1
2203
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: http://www.c-sharpcorner.com/UploadFile/mahesh/VS2005ProjectPropertoes07232005081339AM/VS2005ProjectPropertoes.aspx?ArticleID=c88756d3-cd2b-4919-8e1f-11aabf430ee7 However, in my IDE, there is no checkbox with the caption 'Enable FxCop' in my copy of VS 2005 Pro as the article...
0
8761
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
9426
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...
0
9142
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
6022
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
4525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3238
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2680
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2163
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.