Context:
I have a class that contains a dictionary, accessible via methods (dictionary is private).
Think about a folder hierarchy. That’s about what I am making.
Names are a little bit changed for ease of reading.
Class Folder
Properties:
-Folders As Dictionary
Methods:
-Constructor: Folders = New Dictionary
-AddFolder(f As Folder): Folders.Value(f.Name, f)
Now the debugger is protesting and throws this error:
[quote]There is more than one item with this name and it’s not clear to which it refers.
Folders.Value(f.Name, f)[/quote]
When I search in the editor, there is only 1 object named Folders, and that is the Dictionary.
Where is my logic flawed?
Why are extension methods used with the assignement operator? While I think it looks better, it makes no sense to not be able to do it the ‘normal’ method way Value(param, param)
I do not really understand your question. The Assigns keyword is not related to extension methods (keyword Extends). They can be combined but this is not the case here.
The Assigns keyword is syntactic sugar only. The compiler will change such a statement to a profane method call. So
obj.Something = “abc” will become obj.Something(“abc”)
if the method is defined as cls.Something(Assigns s As String), and
obj.Something(1) = “abc” will become obj.Something(1, “abc”)
if the method is defined as cls.Something(i As Integer, Assigns s As String), and
obj.Something(1, 123.456) = “abc” will become obj.Something(1, 123.456, “abc”)
if the method is defined as cls.Something(i As Integer, d As Double, Assigns s As String)
My guess is that it was introduced because computed properties cannot be typed to arrays. You can “fake” computed property assignment of arrays with method calls by using the Assigns keyword.
You say it yourself: it looks better. This also means it is more readable when reading source code (at least it is in my opinion).