private static void GetActiveEffects(IGraphicsEffectSource effectSource, List <Type> typesSeen) { // Record this node if it is an IGraphicsEffect. IGraphicsEffect effect = effectSource as IGraphicsEffect; if (effect != null) { typesSeen.Add(effect.GetType()); foreach (var property in effect.GetType().GetRuntimeProperties()) { if (property.PropertyType == typeof(IGraphicsEffectSource)) { // Recurse into any source properties that could themselves be effects. var source = (IGraphicsEffectSource)property.GetValue(effect); GetActiveEffects(source, typesSeen); } else if (property.PropertyType == typeof(IList <IGraphicsEffectSource>)) { // Recurse into any array source properties. var sources = (IList <IGraphicsEffectSource>)property.GetValue(effect); foreach (var source in sources) { GetActiveEffects(source, typesSeen); } } } } }
public void SetProperty(string property, object value) { PropertyInfo info = _effect.GetType().GetProperties().FirstOrDefault(x => x.Name == property); if (info != null) { object currentValue = info.GetValue(_effect); if (!currentValue.Equals(value)) { info.SetValue(_effect, value); Layer?.InvalidateLayer("Effect"); } } }
private void EffectToString(StringBuilder sb, int indent, IGraphicsEffect effect, CompositionEffectBrush brush) { const int indentIncrement = 4; Type type = effect.GetType(); sb.AppendFormat("{0}{1}\r\n{0}{{\r\n", Indent(indent), type.Name); Dictionary <string, object> expandedProperties = new Dictionary <string, object>(); indent += indentIncrement; foreach (PropertyInfo info in effect.GetType().GetProperties()) { string propertyName = info.Name.ToLower(); if (propertyName == "cacheoutput" || propertyName == "bufferprecision" || propertyName == "colorhdr" || propertyName == "issupported" || propertyName == "clampoutput" || propertyName == "name" || propertyName == "alphamode") { continue; } object obj = info.GetValue(effect); if (obj != null) { if (obj is IGraphicsEffect || obj is IList <IGraphicsEffectSource> ) { expandedProperties.Add(info.Name, obj); } else { if (obj is CompositionEffectSourceParameter) { CompositionEffectSourceParameter param = (CompositionEffectSourceParameter)obj; CompositionBrush sourceBrush = brush.GetSourceParameter(param.Name); string s = String.Format("{0}{1} :\r\n{0}{{\r\n", Indent(indent), info.Name); sb.Append(s); BrushToString(sb, indent + indentIncrement, sourceBrush); sb.AppendFormat("{0}}}\r\n", Indent(indent)); } else { sb.AppendFormat("{0}{1} : {2}\r\n", Indent(indent), info.Name, Helpers.ToString(obj)); } } } } // Moved all of the nested source properties to the end of the list foreach (KeyValuePair <string, object> entry in expandedProperties) { string name = entry.Key; object obj = entry.Value; if (obj is IGraphicsEffect) { string s = String.Format("{0}{1} :\r\n{0}{{\r\n", Indent(indent), name); sb.Append(s); EffectToString(sb, indent + indentIncrement, (IGraphicsEffect)obj, brush); sb.AppendFormat("{0}}}\r\n", Indent(indent)); } else if (obj is IList <IGraphicsEffectSource> ) { IList <IGraphicsEffectSource> list = (IList <IGraphicsEffectSource>)obj; sb.AppendFormat("{0}{1} :\r\n{0}[\r\n", Indent(indent), name); foreach (IGraphicsEffectSource source in list) { EffectToString(sb, indent + indentIncrement, (IGraphicsEffect)source, brush); } sb.AppendFormat("{0}]\r\n", Indent(indent)); } } indent -= indentIncrement; sb.AppendFormat("{0}}}\r\n", Indent(indent)); }