Interface Get Property Values

Hello and I am sure I am missing something. I have implemented an interface from third party assembly and I want to know the Interface property values before I either change them or do anything else I just want to know their values. I implemented the interface and did a get on one of the properties but all the values are blank. Am I missing something, do I need reflections to do something like this? Thanks

Who is Participating?
tariqpahmedConnect With a Mentor Commented:
just fyi... an Interface by design can not set any default values... and relies on you to do all the setting... so the DataType defaults should be the only thing you have to deal with.

With an "abstract" class, the third party API could have set default values, but not with an "Interface"... Interfaces only ensure that any instances of an object have a pre-determined interface.
You should be able to access the property values defined in the interface assuming the class instance the interface referrs to is initialized and actually has those values set.
Can you paste some code in so we can work with it? :)
Corey_819Author Commented:
I thought so as well okay here you go I really must be missing something.
 class Program : IComUserIdentity
        static void Main(string[] args)
                IComUserIdentity SCMUser = new Program();
                System.Console.WriteLine("User Name: " + SCMUser.Context);


 private String m_Context;
        private int m_DirType;
        String IComUserIdentity.Context
            get { return m_Context; }
            set { m_Context = value; }


        int IComUserIdentity.DirType
            get { return m_DirType; }
            set { m_DirType = value; }

Open in new window

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

have you set a debug.breakpoint on each of the properties, and added a watch for each of the properties, so that you can see their default values at run time?

based purely on the datatypes the
String IComUserIdentity.Context should default to null or string.Empty and the
int IComUserIdentity.DirType should default to 0

Corey_819Author Commented:
Tarigpahmed and yeah based on the dataTypes this is excatly what keeps returning as values.
so, I am assuming that these values are not being set during the Third Party Class or app. I will put on the breakpoints and watch the values during runtime and find out if these values are event being populated.
Ignacio Soler GarciaSolution Architech & Technical LeadCommented:
Implementing the IComUserIdentity does nothing with the properties values. The typical usage would be to pass an instance of the class Program to someone that know how to handle IComUserIdentity.

Your class just create two variables (m_Context and m_DirType) and never assign a value to them so you will always get Nothing and 0.

As I said, implementing IComUserIdentity will never put a value on those variables (how would it be?)

Feel free to ask more if you need.
Corey_819Author Commented:
Thank you this makes sense.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.