私はValueInjectorを使用してASP.NETMVCプロジェクトのマッピングを管理していますが、これまでのところすばらしいです。ドメインには、データベースに標準のメートル単位として保存され、サービスレイヤーまで10進値として公開される長さ測定の概念があります。
測定対象のオブジェクト、ユーザーカルチャなどに応じて、UIコンテキスト固有の長さのレンダリング。ビューモデルタイプのプロパティの属性によって示されるコンテキストに関するヒント。Value Injectorを使用して、インジェクション時にこれらの属性を検査し、適切にフォーマットされた文字列を表示して、ソースプロパティが10進数で、ターゲットプロパティが上記の属性のいずれかで装飾された文字列である場合に表示したいと思います。
namespace TargetValueAttributes
{
public class Person
{
public decimal Height { get; set; }
public decimal Waist { get; set; }
}
public class PersonViewModel
{
[LengthLocalizationHint(LengthType.ImperialFeetAndInches)]
[LengthLocalizationHint(LengthType.MetricMeters)]
public string Height { get; set; }
[LengthLocalizationHint(LengthType.ImperialInches)]
[LengthLocalizationHint(LengthType.MetricCentimeters)]
public string Waist { get; set; }
}
public enum LengthType
{
MetricMeters,
MetricCentimeters,
ImperialFeetAndInches,
ImperialInches
}
[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
public class LengthLocalizationHintAttribute : Attribute
{
public LengthType SuggestedLengthType { get; set; }
public LengthLocalizationHintAttribute(LengthType suggestedLengthType)
{
SuggestedLengthType = suggestedLengthType;
}
}
public class LengthLocalizationInjection : FlatLoopValueInjection<decimal, string>
{
protected override void Inject(object source, object target)
{
base.Inject(source, target);//I want to be able to inspect the attributes on the target value here
}
protected override string SetValue(decimal sourceValues)
{
var derivedLengthType = LengthType.MetricMeters;//here would be even better
return sourceValues.ToLength(derivedLengthType);//this is an extension method that does the conversion to whatever the user needs to see
}
}