문제

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()); }
}
도움이 되었습니까?

해결책

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)

다른 팁

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
{
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top