Apperent ambiguity within class

Hello

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?

Thanks

I found the error.

Really weird, when I use

Folders.Value(f.Name) = f

It works.

Quote from the Dictionary documentation:

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)

Can anybody explain why this is the case?

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).

Hello Eli Ott.

My mistake indeed, I was unaware of what the Assigns keyword meant and read over it.
I was misguided by this sentence in the documentation:

It made no sense to me that the assignement operator was mandatory because this is an extension method.

Thank you for your answer!

Sorry about that! I’ve corrected those unfortunate typos.

No problem! Glad I could help finding this!