public void Apply(StyleOptions opt) { foreach (var pair in _variants) { var type = opt.GetType(); var prop = type.GetProperty(pair.Key); prop.SetValue(opt, pair.Value, null); } }
/// <summary> /// return true, when applying variant to this style options has no effect (still same) /// </summary> /// <param name="opt"></param> public bool IsNoEffect(StyleOptions opt) { foreach (var pair in _variants) { if (pair.Key.Equals("OptionName") || pair.Value is bool) { continue; } var type = opt.GetType(); var prop = type.GetProperty(pair.Key); var optValue = prop.GetValue(opt, null); if (!pair.Value.Equals(optValue)) { return false; } } return true; }
/// <summary> /// Copy corresponding variant info from the given style /// </summary> public StyleVariants Copy(StyleOptions opt, string givenOptionName = null) { var newVariants = new Dictionary<string, object>(); foreach (var pair in _variants) { if (pair.Key.Equals("OptionName")) { newVariants["OptionName"] = givenOptionName ?? "Reloaded"; } else { var type = opt.GetType(); var prop = type.GetProperty(pair.Key); var optValue = prop.GetValue(opt, null); newVariants[pair.Key] = optValue; } } return new StyleVariants(newVariants); }
/// <summary> /// return true, when applying variant to this style options has no effect (still same) /// </summary> /// <param name="opt"></param> public bool IsNoEffect(StyleOptions opt) { foreach (var pair in _variants) { if (pair.Key.Equals("OptionName") || pair.Value is bool) { continue; } var type = opt.GetType(); var prop = type.GetProperty(pair.Key); var optValue = prop.GetValue(opt, null); if (!pair.Value.Equals(optValue)) { return(false); } } return(true); }
/// <summary> /// Copy corresponding variant info from the given style /// </summary> public StyleVariants Copy(StyleOptions opt, string givenOptionName = null) { var newVariants = new Dictionary <string, object>(); foreach (var pair in _variants) { if (pair.Key.Equals("OptionName")) { newVariants["OptionName"] = givenOptionName ?? "Reloaded"; } else { var type = opt.GetType(); var prop = type.GetProperty(pair.Key); var optValue = prop.GetValue(opt, null); newVariants[pair.Key] = optValue; } } return(new StyleVariants(newVariants)); }
private StyleOptions ConstructStyleFromShapeInfo(Shape shape) { var opt = new StyleOptions(); var props = opt.GetType().GetProperties(); foreach (var propertyInfo in props) { var valueInStr = shape.Tags[Service.Effect.Tag.ReloadPrefix + propertyInfo.Name]; if (string.IsNullOrEmpty(valueInStr)) { continue; } if (propertyInfo.PropertyType == typeof(string)) { propertyInfo.SetValue(opt, valueInStr, null); } else if (propertyInfo.PropertyType == typeof(int)) { var valueInInt = int.Parse(valueInStr); propertyInfo.SetValue(opt, valueInInt, null); } else if (propertyInfo.PropertyType == typeof(bool)) { var valueInBool = bool.Parse(valueInStr); propertyInfo.SetValue(opt, valueInBool, null); } } return opt; }
public List<PowerPoint.Shape> EmbedStyleOptionsInformation(string originalImageFile, string croppedImageFile, string imageContext, Rect rect, StyleOptions opt) { if (originalImageFile == null) return new List<PowerPoint.Shape>(); var originalImage = AddPicture(originalImageFile, EffectName.Original_DO_NOT_REMOVE); originalImage.Visible = MsoTriState.msoFalse; var croppedImage = AddPicture(croppedImageFile, EffectName.Cropped_DO_NOT_REMOVE); croppedImage.Visible = MsoTriState.msoFalse; var result = new List<PowerPoint.Shape>(); result.Add(originalImage); result.Add(croppedImage); // store source image info AddTag(originalImage, Tag.ReloadOriginImg, originalImageFile); AddTag(originalImage, Tag.ReloadCroppedImg, croppedImageFile); AddTag(originalImage, Tag.ReloadImgContext, imageContext); AddTag(originalImage, Tag.ReloadRectX, rect.X.ToString(CultureInfo.InvariantCulture)); AddTag(originalImage, Tag.ReloadRectY, rect.Y.ToString(CultureInfo.InvariantCulture)); AddTag(originalImage, Tag.ReloadRectWidth, rect.Width.ToString(CultureInfo.InvariantCulture)); AddTag(originalImage, Tag.ReloadRectHeight, rect.Height.ToString(CultureInfo.InvariantCulture)); // store style info var type = opt.GetType(); var props = type.GetProperties(); foreach (var propertyInfo in props) { try { AddTag(originalImage, Tag.ReloadPrefix + propertyInfo.Name, propertyInfo.GetValue(opt, null).ToString()); } catch (Exception e) { PowerPointLabsGlobals.LogException(e, "EmbedStyleOptionsInformation"); } } return result; }