private void UpdateStringFromResource(System.ComponentModel.ITypeDescriptorContext context, DynStandardValue sv) { ResourceAttribute ra = null; if (context != null && context.PropertyDescriptor != null) { ra = (ResourceAttribute)context.PropertyDescriptor.Attributes.Get(typeof(ResourceAttribute)); } if (ra == null) { ra = (ResourceAttribute)System.ComponentModel.TypeDescriptor.GetAttributes(typeof(bool)).Get(typeof(ResourceAttribute)); } if (ra == null) { return; } ResourceManager rm = null; // construct the resource manager using the resInfo try { if (String.IsNullOrEmpty(ra.BaseName) == false && String.IsNullOrEmpty(ra.AssemblyFullName) == false) { rm = new ResourceManager(ra.BaseName, Assembly.ReflectionOnlyLoad(ra.AssemblyFullName)); } else if (String.IsNullOrEmpty(ra.BaseName) == false) { rm = new ResourceManager(ra.BaseName, typeof(bool).Assembly); } else if (String.IsNullOrEmpty(ra.BaseName) == false) { rm = new ResourceManager(ra.BaseName, typeof(bool).Assembly); } } catch (Exception ex) { Console.WriteLine(ex.Message); return; } if (rm == null) { return; } // update the display and description string from resource using the resource manager string keyName = ra.KeyPrefix + sv.Value + "_Name"; // display name string keyDesc = ra.KeyPrefix + sv.Value + "_Desc"; // description string dispName = string.Empty; string description = string.Empty; try { dispName = rm.GetString(keyName); } catch (Exception ex) { Console.WriteLine(ex.Message); } if (string.IsNullOrEmpty(dispName) == false) { sv.DisplayName = dispName; } try { description = rm.GetString(keyDesc); } catch (Exception ex) { Console.WriteLine(ex.Message); } if (string.IsNullOrEmpty(description) == false) { sv.Description = description; } }
private void UpdateStringFromResource(PropertyDescriptorCollection pdc) { ResourceAttribute ra = (ResourceAttribute)GetAttributes().Get(typeof(ResourceAttribute), true); ResourceManager rm; if (ra == null) { return; } try { if (string.IsNullOrEmpty(ra.BaseName) == false && String.IsNullOrEmpty(ra.AssemblyFullName) == false) { rm = new ResourceManager(ra.BaseName, Assembly.ReflectionOnlyLoad(ra.AssemblyFullName)); } else if (string.IsNullOrEmpty(ra.BaseName) == false) { rm = new ResourceManager(ra.BaseName, m_instance.GetType().Assembly); } else { rm = new ResourceManager(m_instance.GetType()); } } catch (Exception ex) { Console.WriteLine(ex.Message); return; } string sKeyPrefix = (ra.KeyPrefix); foreach (DynPropertyDescriptor pd in pdc) { LocalizableAttribute la = (LocalizableAttribute)pd.Attributes.Get(typeof(LocalizableAttribute), true); if (la != null && !pd.IsLocalizable) { continue; } if (pd.LCID == CultureInfo.CurrentUICulture.LCID) { continue; } //al = pd.AttributeList; string sKey; string sResult; // first category if (!string.IsNullOrEmpty(pd.CategoryResourceKey)) { sKey = sKeyPrefix + pd.CategoryResourceKey; try { sResult = rm.GetString(sKey); if (!string.IsNullOrEmpty(sResult)) { pd.Attributes.Add(new CategoryAttribute(sResult), true); } } catch (Exception) { Console.WriteLine("Key '{0}' does not exist in the resource.", sKey); } } // now display name sKey = sKeyPrefix + pd.Name + "_Name"; try { sResult = rm.GetString(sKey); if (!string.IsNullOrEmpty(sResult)) { pd.Attributes.Add(new DisplayNameAttribute(sResult), typeof(DisplayNameAttribute)); } } catch (Exception) { Console.WriteLine("Key '{0}' does not exist in the resource.", sKey); } // and now description sKey = sKeyPrefix + pd.Name + "_Desc"; try { sResult = rm.GetString(sKey); if (!string.IsNullOrEmpty(sResult)) { pd.Attributes.Add(new DescriptionAttribute(sResult), true); } } catch (Exception) { Console.WriteLine("Key '{0}' does not exist in the resource.", sKey); } } }