ReadOnly vs Property in Assembly Question / Conundrum

How can I create the ReadOnly property outside the assembly (DLL) for people using the DLL, but still be able to populate this property from the assembly to read them?

For example, if I have a Transaction object that needs to populate a property in the Document object (which is a child of the Transaction strong> class) when something happens in the Transaction object , but I just want the developer to use my DLL to be able to read this property and do not change it (it should be changed only from the DLL itself).

+3
source share
4 answers

FROM#

public object MyProp {
   get { return val; }
   internal set { val = value; }
}

B. B.

Public Property MyProp As Object
   Get
      Return StoredVal
   End Get
   Friend Set(ByVal value As Object) 
      StoredVal = value
   End Set
End Property
+7
source

If you use C #, you may have different access modifiers on getand set, for example. The following should achieve what you want:

public int MyProp { get; internal set; }

VB.NET also has this feature: http://weblogs.asp.net/pwilson/archive/2003/10/28/34333.aspx

+6
source

FROM#

public bool MyProp {get; internal set;} //Uses "Automatic Property" sytax

B. B.

private _MyProp as Boolean
Public Property MyProp as Boolean
   Get
      Return True
   End Get
   Friend Set(ByVal value as Boolean)
      _MyProp = value
   End Set
End Property
+3
source

What language? In VB, you mark the installer as "Friend", in C # you use the internal one.

+1
source

All Articles