我有一个类如下......想法是做一些逻辑处理并返回一个只读对象.
public class Test
{
public object property1 { get; private set; }
public string property2 { get; private set; }
private Test(){}
public static Test GetTest(XDocument document)
{
if (document== null)
return null;
return new Test
{
property1 = l_document.Element("something").value,
property2 = l_document.Element("anotherthing").value,
};
}
}
Run Code Online (Sandbox Code Playgroud)
如果我在函数中使用上面的测试对象作为参数,我得到一条消息Argument Type不符合CLS ......有什么建议吗?我可以通过其他任何方式实现只读对象吗?
谢谢,Kamar
Jon*_*eet 10
编辑:(删除了以前的答案.)
我自己尝试过这个,我强烈怀疑这只是你没有[assembly:CLSCompliant(true)]参加宣布Test课程的集会的问题.那样做,一切都应该是桃子的.
| 归档时间: |
|
| 查看次数: |
4054 次 |
| 最近记录: |