Access of shared member, constant member, etc. warning

W

William O''Connor

I have a piece of code which I'm upgrading from .Net 1.1 to .Net 3.5. I'm
getting the ubiquitous Access of shared member, etc. warning for a particular
section and I haven't been able to figure a way around the problem.

The code in question:

Private _LogFile As Logger
Public Property LogFile() As String
Get
Return _LogFile.LogFile
End Get
Set(ByVal Value As String)
_LogFile.LogFile = Value
End Set
End Property

Logger is a class written in C Sharp. The code being accessed by the above
property is:

public static string LogFile
{
get
{
return appender.File;
}
set
{
appender.File = value;
appender.ActivateOptions();
}
}

The Logger class is contained in a separate DLL which is imported into the
appropriate namespace. All the references seem to be correct, except that
it's violating a rule within .Net.

Any assistance will be greatly appreciated.
 
P

Phill W.

William said:
I have a piece of code which I'm upgrading from .Net 1.1 to .Net 3.5. I'm
getting the ubiquitous Access of shared member, etc. warning for a particular
section and I haven't been able to figure a way around the problem.

OK, so given ...
class Logger
public static string LogFile

... you need to access the Shared (static) property LogFile.
You do that via the Class Name, rather than an Object [reference]
variable, as in:

Private _LogFile As Logger ' <- Class Name
Public Property LogFile() As String
Get
Return Logger.LogFile ' <- Class Name
End Get
Set(ByVal Value As String)
Logger.LogFile = Value ' <- Class Name
End Set
End Property

HTH,
Phill W.
 
A

Armin Zingler

William said:
I have a piece of code which I'm upgrading from .Net 1.1 to .Net 3.5.
I'm getting the ubiquitous Access of shared member, etc. warning for
a particular section and I haven't been able to figure a way around
the problem.

The code in question:

Private _LogFile As Logger
Public Property LogFile() As String
Get
Return _LogFile.LogFile
End Get
Set(ByVal Value As String)
_LogFile.LogFile = Value
End Set
End Property

Logger is a class written in C Sharp. The code being accessed by the
above property is:

public static string LogFile
{
get
{
return appender.File;
}
set
{
appender.File = value;
appender.ActivateOptions();
}
}

The Logger class is contained in a separate DLL which is imported
into the appropriate namespace. All the references seem to be
correct, except that it's violating a rule within .Net.

Any assistance will be greatly appreciated.


_LogFile can reference an object. You don't need an object to access the
Logfile member because it's a static member.

New syntax:

Return Logger.LogFile
and
Logger.LogFile = Value


In addition, is it necessary to write a property just in order to change the
static member of another class?


Armin
 
W

William O''''Connor

That did it. Thank you very, very much.


--
William J. O''''Connor - Software Systems Engineer, SAIC, Inc.


Phill W. said:
William said:
I have a piece of code which I'm upgrading from .Net 1.1 to .Net 3.5. I'm
getting the ubiquitous Access of shared member, etc. warning for a particular
section and I haven't been able to figure a way around the problem.

OK, so given ...
class Logger
public static string LogFile

... you need to access the Shared (static) property LogFile.
You do that via the Class Name, rather than an Object [reference]
variable, as in:

Private _LogFile As Logger ' <- Class Name
Public Property LogFile() As String
Get
Return Logger.LogFile ' <- Class Name
End Get
Set(ByVal Value As String)
Logger.LogFile = Value ' <- Class Name
End Set
End Property

HTH,
Phill W.
 
W

William O''''Connor

Thanks for responding, Armin. The answer to your question is "probably not".
Right now, though, I don't want to make too many changes to this since my
current task is to just convert the code and make it work with as few changes
to code as possible. When I am done with converting and testing everything, I
will revisit the code with an eye towards optimizing its operation and
getting it up to standards.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top