>>>>Hi everybody,
>>>>
>>>>In the base class I defined a public property with simple
>>>>
>>>>Public InvokeString {get;set;}
>>>>
>>>>I have two classes that inherit from that main class. In one of the classes I have a method where I can set this property. My problem is that I want another class to be able to read that new property value.
>>>>
>>>>Is there a way to solve it? Should I use static keyword here for the property only?
>>>
>>>Not sure I understand your requirement but I don't see how 'static' would help. Maybe something like this?:
public class ClassA
>>> {
>>> protected virtual string InvokeString { get; set; }
>>> }
>>>
>>> public class ClassB : ClassA
>>> {
>>> public void SetInvokeString(string s)
>>> {
>>> base.InvokeString = s;
>>> }
>>>
>>> public new string InvokeString
>>> {
>>> get { return base.InvokeString; }
>>> }
>>> }
>>
>>This doesn't seem to work for me. I implemented it this same way and added the methods SetInvokeString and new String InvokeString in both classes. However, after I set the property in one class, the same property in another class is still null.
>>
>>Here is what I have in the base class:
>>
>>
>> protected virtual String InvokeString { get; set; }
>>
>>I have two separate classes that inherit from this one. In both I added the exact same code as you showed.
>>
>>One of them has
>>
>>
>> public String Invoke(String input)
>> {
>> Dictionary<String, String> parameters = new Dictionary<String, String>(StringComparer.OrdinalIgnoreCase);
>>
>> this.SetInvokeString(input);
>>
>>
>>And in the other class I added also both methods and I have this code:
>>
>>
>>Logging.Log(String.Format("Calling Remote VoidPaymentPlanPass On {0} with: ", ip, this.InvokeString));
>>
>>When I debug my test I see that this.InvokeString is null.
>>
>>What did I do wrong?
>
>Works for me
I noticed when I was debugging the message about base class. In other words, I was trying to see it while debugging and I even tried to put in the immediate window
base.InvokeString
and I got a message that you can not access it while debugging. So, I am not 100% sure it's not working, but I can not see it while debugging my test.
If it's not broken, fix it until it is.
My Blog