c# - Different access to property for different classes -
c# - Different access to property for different classes -
i have base of operations (abstract) class component
. want command access properties of derived classes such gets read access, write access allowed classes.
those 'certain classes' implements abstract base of operations class messagehandler<tmessage>
. ideally i'd class implementing imessagehandler
able access, think makes requirement bit tougher.
this run on xbox , want avoid creating temporary objects (such read-only copies). want minimise number of method calls @ value that's read/written to.
the component
class , messagehandler<tmessage>
classes in own assemblies, both of referenced other projects when using api.
i'm guessing i'm going have alter model somehow, can't head around it.
public abstract class component { } public class derivedcomponenta : component { int property {get; set;} } public abstract class messagehandler<tmessage> { } public class intmsghandler : messagehandler<int> { void dothing(derivedcomponenta derivedcomponenta) { derivedcomponenta.property = 5; // allowed } } public class anyclass // doesn't inherit messagehandler, or implement imessagehandler { void dothing(derivedcomponenta derivedcomponenta) { derivedcomponenta.property = 5; // not allowed } }
the isolation (based on question made , understood) made based on base of operations class definition (if any). means isolation should start it.
or, if say, if class x
implements messagehandler
should able deed in several way on class y
type objects. that, imo, means there tough relation between class y
, messagehandler
.
this leads think me can somehting this:
only publicget
on properties of derivedcomponenta
in messagehandler
define generic protected setproperty(component compo, string propertyname, object propertyvalue)
, set required property reflection. in way possible way set property on any component
derived class using messagehandler
method, available ones derive it. rest of available types provide only public get
(readonly) poperty reading data.
hope helps.
c# access-modifiers
Comments
Post a Comment