ObsoleteAttribute Compiler bug?

  • Thread starter Thread starter cody
  • Start date Start date
C

cody

public decimal Wert
{
get{return this.wert;}
[Obsolete]
set{this.wert=value;}
}

This doesn't compile. It gives me error CS0592 and says that obsolete cannot
be applied to that elemet.
 
That's not a bug - you can't apply attributes to an individual "set" or
"get". Methods can have attributes specified prior to the method header and
prior to individual parameters.

David Anton
Tangible Software Solutions Inc.
www.tangiblesoftwaresolutions.com
Home of the Instant C# VB.NET to C# converter and the Instant VB C# to
VB.NET converter
 
You know that set and get accessors *are* individual methods? I see no
reason why I can't put attributes on individual accessor methods.

David Anton said:
That's not a bug - you can't apply attributes to an individual "set" or
"get". Methods can have attributes specified prior to the method header and
prior to individual parameters.

David Anton
Tangible Software Solutions Inc.
www.tangiblesoftwaresolutions.com
Home of the Instant C# VB.NET to C# converter and the Instant VB C# to
VB.NET converter

cody said:
public decimal Wert
{
get{return this.wert;}
[Obsolete]
set{this.wert=value;}
}

This doesn't compile. It gives me error CS0592 and says that obsolete cannot
be applied to that elemet.
 
They are individual methods in the IL, but not at the C# level.
I understand your angst, especially when you *can* do what you want in
VB.NET (!) - that is kind of odd.

cody said:
You know that set and get accessors *are* individual methods? I see no
reason why I can't put attributes on individual accessor methods.

David Anton said:
That's not a bug - you can't apply attributes to an individual "set" or
"get". Methods can have attributes specified prior to the method header and
prior to individual parameters.

David Anton
Tangible Software Solutions Inc.
www.tangiblesoftwaresolutions.com
Home of the Instant C# VB.NET to C# converter and the Instant VB C# to
VB.NET converter

cody said:
public decimal Wert
{
get{return this.wert;}
[Obsolete]
set{this.wert=value;}
}

This doesn't compile. It gives me error CS0592 and says that obsolete cannot
be applied to that elemet.
 
Really??? So it is really a bug or "missing feature" in the c# compiler.


David Anton said:
They are individual methods in the IL, but not at the C# level.
I understand your angst, especially when you *can* do what you want in
VB.NET (!) - that is kind of odd.

cody said:
You know that set and get accessors *are* individual methods? I see no
reason why I can't put attributes on individual accessor methods.

That's not a bug - you can't apply attributes to an individual "set" or
"get". Methods can have attributes specified prior to the method
header
and
prior to individual parameters.

David Anton
Tangible Software Solutions Inc.
www.tangiblesoftwaresolutions.com
Home of the Instant C# VB.NET to C# converter and the Instant VB C# to
VB.NET converter

:

public decimal Wert
{
get{return this.wert;}
[Obsolete]
set{this.wert=value;}
}

This doesn't compile. It gives me error CS0592 and says that
obsolete
cannot
be applied to that elemet.
 
Cody,

Yes, the C# compiler geenrates set and get methods to handle a property.
However, during design time, these methods are called accessors and belong
to a single property. Attributes can only be applied to a class or members
of a class. The property is a member of a class. Accessors are members of
the property, therefore, they cannot have attributes.

Telmo Sampaio
MCT

cody said:
You know that set and get accessors *are* individual methods? I see no
reason why I can't put attributes on individual accessor methods.

Newsbeitrag
That's not a bug - you can't apply attributes to an individual "set" or
"get". Methods can have attributes specified prior to the method header and
prior to individual parameters.

David Anton
Tangible Software Solutions Inc.
www.tangiblesoftwaresolutions.com
Home of the Instant C# VB.NET to C# converter and the Instant VB C# to
VB.NET converter

cody said:
public decimal Wert
{
get{return this.wert;}
[Obsolete]
set{this.wert=value;}
}

This doesn't compile. It gives me error CS0592 and says that obsolete cannot
be applied to that elemet.
 
Why would it be a compiler bug if the compiler generates a clear error
message?
Obsolete is allowed on "... and Property only" and as you probably know a
'Property accessor' is not the same as a property.

Willy.
 
For me it is a bug bcause it prevents me from using attributes with property
accessors. Didn't they think about that? And as someone else said, it is
allowed in VB.NET.

Willy Denoyette said:
Why would it be a compiler bug if the compiler generates a clear error
message?
Obsolete is allowed on "... and Property only" and as you probably know a
'Property accessor' is not the same as a property.

Willy.


cody said:
public decimal Wert
{
get{return this.wert;}
[Obsolete]
set{this.wert=value;}
}

This doesn't compile. It gives me error CS0592 and says that obsolete
cannot
be applied to that elemet.
 
Back
Top