Interface Get Property Values

Posted on 2009-12-29
Last Modified: 2013-11-07
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

Question by:Corey_819
    LVL 12

    Expert Comment

    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? :)
    LVL 1

    Author Comment

    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


    Expert Comment

    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

    LVL 1

    Author Comment

    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.

    Accepted Solution

    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.
    LVL 5

    Expert Comment

    by:Ignacio Soler Garcia
    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.
    LVL 1

    Author Closing Comment

    Thank you this makes sense.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now