I have a class like this
internal class Report
{
public Company TargetCompany { get; private set; }
.... // other stuff
}
I do not want any one to be able to do this
Report r = GetReport();
Company c = r.TargetCompany;
but instead always use
r.TargetCompany
when they want access to the Company variable.
Is that possible? Does that even make sense?
No, it's not possible.
And no, it really doesn't make sense either. Maybe if you explain your reasoning we'll understand a little better.
No, that is not possible. The closest thing you can do is to provide wrappers to only allow access to the members within TargetCompany (not the company reference itself), or to return a copy of your internal TargetCompany member, preventing the internal one from being referenced (which has no real value).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With