private T GetFixedWebPartProperty <T>(FixedWebPart webPart, string name, T defaultValue) { var property = webPart.Property.Where(p => p.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault(); if (property != null) { if (property.Value.StartsWith("$Resources:")) { property.Value = CacheManager.Instance.GetResourceString(this.cc, property.Value); } if (property.Value is T) { return((T)(object)property.Value); } try { return((T)Convert.ChangeType(property.Value, typeof(T))); } catch (InvalidCastException) { return(defaultValue); } } return(defaultValue); }
private Dictionary <string, string> CastAsPropertiesDictionary(FixedWebPart webPart) { Dictionary <string, string> props = new Dictionary <string, string>(StringComparer.InvariantCultureIgnoreCase); foreach (var prop in webPart.Property) { props.Add(prop.Name, prop.Value); } return(props); }