In my ideal world, what I’m looking for would exist as something along the lines of this:
public string UserDefinedField { get { return _userDefinedField; } internal set { _userDefinedField = value; } set { _userDefinedField = value; ChangedFields.Add(Fields.UserDefinedField); } }
Where one statement is executed regardless of the access modifier, and another statement is executed if it’s called from an external assembly or class.
I’m sure I could code something by using reflection and checking up the current call stack to see if the caller is in the same assembly, but I’m looking to see if there’s a more elegant approach than that.
You could get the caller information by examining the calling stack but that is extremely slow (compared to the above) and I wouldn’t recommend it.