interface property copy in c#

后端 未结 8 2212
一生所求
一生所求 2021-02-07 08:13

I\'ve been working with C# for many years now, but just come across this issue that\'s stumping me, and I really don\'t even know how to ask the question, so, to the example!

8条回答
  •  花落未央
    2021-02-07 09:04

    You could build an extension method:

    public static void CopyAddress(this IAddress source, IAddress destination)
    {
        if (source is null) throw new ArgumentNullException("source");
        if (destination is null) throw new ArgumentNullException("destination");
    
        //copy members:
        destination.Address1 = source.Address1;
        //...
    }
    

提交回复
热议问题