Reputation: 3922
From what I've been reading online, if the field is private
it can start with a leading _
. However when I do the following it complains? Is it because I'm returning the private field? Doesn't make sense to me since anything consuming this has no idea about _myObject so why would it matter?
private MyBusinessObject _myObjectBO;
protected MyBusinessObject MyObjectBO
{
get { return _myObjectBO ?? (_myObjectBO= new MyBusinessObject()); }
}
Upvotes: 1
Views: 1052
Reputation: 888283
The message is stating that the property's type is not compliant.
Check the MyBusinessObject
class; many developers forgot to add [assembly: CLSCompliant(true)]
(unfortunately, it isn't part of the standard template)
Upvotes: 5
Reputation: 51344
Nothing about this is inherently not CLS Compliant. What does MyObject look like? I tested with the following code, and got no CLS compliance warnings at compile time:
[CLSCompliant(true)]
public class Program
{
private MyObject _myObject;
[CLSCompliant(true)]
public MyObject ComplaintTypeBO
{
get { return _myObject ?? (_myObject = new MyObject()); }
}
static void Main(string[] args)
{
}
}
[CLSCompliant(true)]
public class MyObject
{
}
Upvotes: 1