Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm pretty new to .NET and learning the things. I have a class from a camera library which gives the property value when we call GetValue() method as below.
C#
camera.Parameters[PLCamera.Width].GetValue();
I'm unsure how does that work. Is that PLCamera.Width given in two square braces is an enum? What essentially happening in this statement? When I saw PLCamera class, it has numerous such properties. I want to create a public function which gives any property given as argument.

What I have tried:

I have tried the code camera.Parameters[PLCamera.Width].GetValue(); and it gets the PLCamera.Width. I want to know how this essentially works?

CHM library doc can be found at Pylon - Google Drive[^]
Posted
Updated 8-Jan-18 6:00am
v3
Comments
Kenneth Haugland 8-Jan-18 11:58am    
Are you sure these are not dependency properties?
https://docs.microsoft.com/en-us/dotnet/framework/wpf/advanced/dependency-properties-overview
digiajay 8-Jan-18 12:32pm    
Maybe they are dependency properties. Let me look at how dependency properties work. Thanks for suggestion.!
Kenneth Haugland 8-Jan-18 13:13pm    
Those are only used in WPF applications though.

1 solution

Without looking at the source code - which I assume you can do, but I don't which to download - I would assume that camera.Parameters is an array or a Dictionary, so the value inside the square brackets evaluates to an integer (and thus could be a enum) or a different type, like a string.
It's unlikely that PLCamera is an enum, as there is no implicit conversion from an enum to an int, so it's more likely that it's a class / struct of const int values, or Parameters is a Dictionary.

For a dictionary, it could be something like this:
C#
public static class PLCamera
    {
    public static const string Width = "Width";
    ...
    }
public class ParameterBlock
    {
    public int GetValue() { return 0; }
    ...
    }
private Dictionary<string, ParameterBlock> Parameters = new Dictionary<string, ParameterBlock>();
...
    int x = Parameters[PLCamera.Width].GetValue();

If it's an enum, then it could be done like this:
C#
private  Dictionary<PLCamera, ParameterBlock> Parameters = new Dictionary<PLCamera, ParameterBlock>();
...
    int x = Parameters[PLCamera.Width].GetValue();
 
Share this answer
 
Comments
digiajay 8-Jan-18 12:40pm    
I have added the source code at the same google drive https://goo.gl/KAaq4K under folder "Pylon Development.zip"
OriginalGriff 8-Jan-18 13:57pm    
If you've got it, you look at it!
What do you see?
Richard Deeming 9-Jan-18 12:18pm    
It's perfectly possible for PLCamera to be an enum. Index parameters aren't restricted to numbers or strings! :)
OriginalGriff 9-Jan-18 13:58pm    
It is - but you'd have to cast it to an int before that code would compile.
Richard Deeming 9-Jan-18 14:06pm    
No you wouldn't:
enum Person { Ford, Arthur, Zaphod }

class Answer
{
    public int this[Person index]
    {
        get 
        { 
            switch (index)
            {
                case Person.Ford:
                case Person.Arthur:
                case Person.Zaphod:
                {
                    return 42; 
                }
                default:
                {
                    throw new BowlOfPetuniasException("Not again!");
                }
            }
        }
    }
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900