Scenario:
We want to edit model before further processing. The model is passed to a Generic method. Also name of Datamember of the model has to be different than property name.
Solution:
1
2
3
4
5
6
7
8
9
10
| public interface IModel
{
string Filename { get; set; }
}
public class Model : IModel
{
[DataMember(Name = "fileName")]
public string FileName { get; set; }
}
|
| |
1
2
3
4
5
6
7
8
9
10
| public abstract class Client<T> : IClient where T : class
{
private void Process(T model)
{
if (model is IModel model)
{
model.Filename = application.FileName;
}
}
}
|
| |
No comments:
Post a Comment