[英]Emit mapper and Generic method
I have some problem with Emit mapper when I try to save in database properties. 尝试保存数据库属性时,Emit映射器出现一些问题。
In first I mapped this class (it work good): 首先,我映射了这个类(效果很好):
[Serializable]
public class ProfileProperty
{
public string PropertyValue { get; set; }
public bool IsVisible { get; set; }
public ProfileProperty(string value, bool isVisible = true)
{
this.PropertyValue = value;
this.IsVisible = isVisible;
}
public ProfileProperty()
{
this.IsVisible = true;
}
}
I mapped here: 我在这里映射:
var mapper = ObjectMapperManager.DefaultInstance.GetMapper<PollmericaProfile, ProfileModel>();
ProfileModel prof = new ProfileModel();
if (x.User != null)
{
prof = mapper.Map(x);
}
But some of the requirements need not a string
property. 但是某些要求不需要
string
属性。 That's why I decided to write this: 这就是为什么我决定这样写的原因:
[Serializable]
public class ProfileProperty
{
public object PropertyValue { get; set; }
public bool IsVisible { get; set; }
public ProfileProperty(object value, bool isVisible = true)
{
this.PropertyValue = value;
this.IsVisible = isVisible;
}
public ProfileProperty()
{
this.IsVisible = true;
}
public T GetValue<T>()
{
return (T)this.PropertyValue;
}
}
And all mapping is not worked =( 而且所有映射都不起作用=(
If you ccan, help me please. 如果可以,请帮助我。 If you want I can provide the necessary information.
如果您愿意,我可以提供必要的信息。
PS To be honest, I want to transfer to a string and back, so at least works PS老实说,我想转移到弦上并返回,所以至少可以
UPD: I tried without method public T GetValue<T>()
... It works... UPD:我尝试了没有方法
public T GetValue<T>()
。
Sorry for this, but I find answer very quicly. 对此感到抱歉,但是我发现答案很简单。
in mapping I must to write this: 在映射中,我必须这样写:
var mapper = ObjectMapperManager
.DefaultInstance
.GetMapper<PollmericaProfile, ProfileModel>( new DefaultMapConfig()
.IgnoreMembers<PollmericaProfile, ProfileModel>(new string[] { "GetValue" }));
ProfileModel prof = new ProfileModel();
if (x.User != null)
{
prof = mapper.Map(x);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.