public bool HasResource(object target, string propertyName) { var property = PropertyDescriptorBuilder.TryCreatePropertyDescriptor(target.GetType(), propertyName); if (property == null) { throw new Exception(string.Format("Property '{0}' is not found", propertyName)); } return(_targetsMap.ContainsKey(target) && _targetsMap[target].ContainsKey(property)); }
/// <summary> /// Применяет ресурс (переведенную строку) к объекту с заданным свойсвом. /// Ресурс определяется по ключу /// </summary> /// <param name="target">Объект, к которому применяется перевод</param> /// <param name="propertyName">Свойство объекта</param> /// <param name="resourceKey">Ключ, определяющий ресурс</param> /// <exception cref="ArgumentNullException"> /// <paramref name="resourceKey" /> must not be null. /// </exception> /// <exception cref="Exception"> /// <p>Property <paramref name="propertyName"/> is not found.</p> /// <p>- or - </p> /// <p>Property <paramref name="propertyName"/> is not string type.</p> /// </exception> public void ApplyResource(object target, string propertyName, string resourceKey) { if (!CultureValid) { LoadLangPack(); } var property = PropertyDescriptorBuilder.TryCreatePropertyDescriptor(target.GetType(), propertyName); if (property == null) { throw new Exception(string.Format("Property '{0}' is not found", propertyName)); } if (property.PropertyType != typeof(string)) { throw new Exception(string.Format("Property '{0}' is not string type", propertyName)); } if (resourceKey == null) { throw new ArgumentNullException("resourceKey"); } if (!_targetsMap.ContainsKey(target)) { _targetsMap.Add(target, new Dictionary <PropertyDescriptor, string>()); } if (!_targetsMap[target].ContainsKey(property)) { _targetsMap[target].Add(property, resourceKey); } else { _targetsMap[target][property] = resourceKey; } Update(target); }