本文整理汇总了C#中ITranslation.TranslateItem方法的典型用法代码示例。如果您正苦于以下问题:C# ITranslation.TranslateItem方法的具体用法?C# ITranslation.TranslateItem怎么用?C# ITranslation.TranslateItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITranslation
的用法示例。
在下文中一共展示了ITranslation.TranslateItem方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TranslateProperty
public static void TranslateProperty(string category, object obj, string propName, ITranslation translation)
{
if (obj == null)
return;
var propertyInfo = obj.GetType().GetProperty(propName,
BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static |
BindingFlags.NonPublic | BindingFlags.SetProperty);
if (propertyInfo == null)
{
return;
}
Func<string> provideDefaultValue = () => "";
string value = translation.TranslateItem(category, propName, "Text", provideDefaultValue);
if (!String.IsNullOrEmpty(value))
{
if (propertyInfo.CanWrite)
propertyInfo.SetValue(obj, value, null);
}
}
示例2: TranslateItemsFromList
public static void TranslateItemsFromList(string category, ITranslation translation, IEnumerable<Tuple<string, object>> items)
{
Action<string, object, PropertyInfo> action = delegate(string item, object itemObj, PropertyInfo propertyInfo)
{
string value = translation.TranslateItem(category, item, propertyInfo.Name, null);
if (!String.IsNullOrEmpty(value))
{
if (propertyInfo.CanWrite)
propertyInfo.SetValue(itemObj, value, null);
}
else if (propertyInfo.Name == "ToolTipText" && !String.IsNullOrEmpty((string)propertyInfo.GetValue(itemObj, null)))
{
value = translation.TranslateItem(category, item, "Text", null);
if (!String.IsNullOrEmpty(value))
{
if (propertyInfo.CanWrite)
propertyInfo.SetValue(itemObj, value, null);
}
}
};
ForEachItem(items, action);
}
示例3: TranslateItemsFromList
public static void TranslateItemsFromList(string category, ITranslation translation, IEnumerable<Tuple<string, object>> items)
{
foreach (var item in items)
{
string itemName = item.Item1;
object itemObj = item.Item2;
foreach (var propertyInfo in GetItemPropertiesEnumerator(item))
{
var property = propertyInfo; // copy for lambda
string propertyName = property.Name;
if (propertyName == "Items" && typeof(IList).IsAssignableFrom(property.PropertyType))
{
var list = (IList) property.GetValue(itemObj, null);
for (int index = 0; index < list.Count; index++)
{
propertyName = "Item" + index;
var listValue = list[index] as string;
if (listValue != null)
{
Func<string> provideDefaultValue = () => listValue;
string value = translation.TranslateItem(category, itemName, propertyName,
provideDefaultValue);
if (!string.IsNullOrEmpty(value))
{
list[index] = value;
}
}
}
}
else if (property.PropertyType.IsEquivalentTo(typeof(string)))
{
Func<string> provideDefaultValue = () => (string)property.GetValue(itemObj, null);
string value = translation.TranslateItem(category, itemName, propertyName, provideDefaultValue);
if (!string.IsNullOrEmpty(value))
{
if (property.CanWrite)
property.SetValue(itemObj, value, null);
}
else if (property.Name == "ToolTipText" &&
!string.IsNullOrEmpty((string)property.GetValue(itemObj, null)))
{
value = translation.TranslateItem(category, itemName, "Text", provideDefaultValue);
if (!string.IsNullOrEmpty(value))
{
if (property.CanWrite)
property.SetValue(itemObj, value, null);
}
}
}
}
}
}