c# - How can i hide "setters" from all but one assembly? -
i have alluded issue in my other question, think it's worthwhile breaking out own question, it's not dependant on other scenarios mentioned.
anyways - onto q, don't know if possible. looking solution/workaround.
i have class library, nothing poco's:
mycompany.myproject.domain.poco
this assembly has poco this:
public class post { public int postid { get; set; } public int name { get; set; } ... }
now, have class library, dal/repository, , uses entity framework 4.0 persistence:
mycompany.myproject.repositories
this assembly has reference poco project, needs perform crud operations on poco's (grab db objects, project poco's, return, modify poco's).
now, have web application, has reference both poco , repository assembly.
if this:
somepoco.postid = 10;
i sqlexception, postid identity field in database, , hence should not explicity set.
is there way can hide setter these special properties, repository has access setter?
i can't think of way regular accessibility modifiers (as none of them suit scenario), can guys think of workaround?
you make setter internal, , make internals visible repository assembly
[assembly: internalsvisibleto("mylibrary.repositories")] public class post { public int postid { get; internal set; } public int name { get; internal set; } ... }
this means can 'get' properties, assembly, , assembly containing repository, can 'set'
Comments
Post a Comment