问题
In C#, you can have more restrictive accessors on the accessors of a property like this:
public List<String> Name { get; protected set; }
How can I accomplish this when generating code using CodeDom?
回答1:
CodeDom doesn't directly support this. CodeDom dates from an era when C# and Visual Basic didn't support different accessibility on the get and set method, and hasn't been updated to support the new functionality. You will probably need to use a CodeSnippetTypeMember (though with a bit of ingenuity you could still use CodeDom to generate the getter and setter bodies).
来源:https://stackoverflow.com/questions/2414510/how-do-i-change-accessibility-on-an-accessor-using-codedom