'How to assign fields to class that implements an interaface, using an interface as input?
Say I have a class that implements interface IInterfaceOne and IInterfaceTwo.
Those interfaces have different properties, which I don't want to set individually.
Now I have a class that looks something like this:
public class SomeClass : IInterfaceOne, IInterfaceTwo
{
// From IInterfaceOne
public Field1 { get; set; }
public Field2 { get; set; }
// From IInterfaceTwo
public Field3 { get; set; }
public Field4 { get; set; }
}
Say I have an instance of 'SomeClass' in 'SomeOtherClass' like so and I wanted to assign values to 'SomeClass' using a parameter that implements 'IInterfaceOne'
public class SomeOtherClass
{
private SomeClass someClass = new SomeClass();
public void DoSomething(IInterfaceOne someParameter)
{
// Is there a way to say
// someClass = someParameter
// and copy the values from 'someParameter' to 'someClass'
// with out creating a new instance of 'someClass'?
}
}
I get that I can make a method to assign these individually and just call that each time, but I am wondering if there is a better, quicker or a cleaner way to do this (such as someClass = (SomeClass)someParameter, without destroying the original instance of 'someClass').
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
