将方法的返回公开到属性中

发布于 2024-12-06 11:21:44 字数 957 浏览 1 评论 0原文

如何将我的方法的返回公开到类属性中?

public class BIContactLib: ContactLib
{

   //Expose it here.. to replace the code below

    public IEnumerable<BIContactLib> GetContactLibs 
    {
        get { return (BIContactLib) GetAll}
        set { ; }
    }
}

public class BIContactLibService : IBIRequirement, IDisposable
{
    private ClientContext context = new ClientContext();

  //The return of the method here is the one I would like to expose

    public IEnumerable<BIContactLib> GetAll()
    {
        var contactslib = context.ContactLibs;
        return contactslib.ToList();
    }
}

这背后的原因是我想创建一个包含联系人库列表的视图模型...顺便说一句,这是我的视图模型..

public class PersonInformation
{
    public BIPerson Person { get; set; }
    public BIAddress Address { get; set; }

    //This is where i want to use it

    public IEnumerable<BIContactLib> GetAll { get; set; }
}

或者有其他方法可以做到这一点?

此致,

How can i expose the return of my method in to a class property?

public class BIContactLib: ContactLib
{

   //Expose it here.. to replace the code below

    public IEnumerable<BIContactLib> GetContactLibs 
    {
        get { return (BIContactLib) GetAll}
        set { ; }
    }
}

public class BIContactLibService : IBIRequirement, IDisposable
{
    private ClientContext context = new ClientContext();

  //The return of the method here is the one I would like to expose

    public IEnumerable<BIContactLib> GetAll()
    {
        var contactslib = context.ContactLibs;
        return contactslib.ToList();
    }
}

The reason behind this, is I want to create a view model with have the list of contacts library... heres my view model by the way..

public class PersonInformation
{
    public BIPerson Person { get; set; }
    public BIAddress Address { get; set; }

    //This is where i want to use it

    public IEnumerable<BIContactLib> GetAll { get; set; }
}

Or any other way to do this?

Best regards,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

离不开的别离 2024-12-13 11:21:44

像这样的事情怎么样

public IEnumerable<BIContactLib> GetContactLibs 
    {
        get { 
             BiContractLib lib = new BiContractLib();
             return lib.GetAll();
            }        
    }

How about something like this

public IEnumerable<BIContactLib> GetContactLibs 
    {
        get { 
             BiContractLib lib = new BiContractLib();
             return lib.GetAll();
            }        
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文