public ParameterList Aggregate(ParameterList list1, ParameterList list2) { var list = new ParameterList {Name = list1.Name}; foreach (var p in list1.Parameters()) list.Add(p); foreach (var p in list2.Parameters()) list.Add(p); foreach (var m in list1.Methods) list.Methods.Add(m); foreach (var m in list2.Methods) list.Methods.Add(m); return list; }
public override object Read(BinaryReader reader, byte version) { var list = new ParameterList(); list.Name = reader.ReadString(); int pCount = reader.ReadInt32(); int mCount = reader.ReadInt32(); for (int i = 0; i < pCount; i++) list.Add(StreamerManager.Deserialize(reader) as Parameter); for (int j = 0; j < mCount; j++) list.Methods.Add(reader.ReadString()); return list; }
public ParameterList GetStrategyParameters(string name, object obj) { var list = new ParameterList {Name = name}; var pred = new Predicate<Attribute>(a => { var t = a.GetType(); return t.FullName.Contains("ComponentModel") && t.Name != "PropertyTabAttribute" && t.Name != "ToolboxItemAttribute"; }); var properties = obj.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Where(p => p.GetCustomAttributes(typeof(ParameterAttribute), true).Any()); foreach(var param in properties.Select(p => new Parameter(p.Name, p.GetValue(obj), p.PropertyType.AssemblyQualifiedName, p.GetCustomAttributes().Where(a => pred(a)).ToArray()))) list.Add(param); var fields = obj.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Where(f => f.GetCustomAttributes(typeof(ParameterAttribute), true).Any()); foreach (var param in fields.Select(f => new Parameter(f.Name, f.GetValue(obj), f.FieldType.AssemblyQualifiedName, f.GetCustomAttributes().Where(a => pred(a)).ToArray()))) list.Add(param); var methods = obj.GetType().GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public).Where(m => m.GetCustomAttributes(typeof (StrategyMethodAttribute), true).Any() && m.GetParameters().Length == 0); foreach (var m in methods) list.Methods.Add(m.Name); return list; }
public void SetStrategyParameters(ParameterList parameters, object obj) { foreach (var p in parameters) SetStrategyParameter(p.Name, obj, p.Value); }
public ParameterList GetParameters(string name, object obj) { var parameterList = new ParameterList() {Name = name}; var pred = new Predicate<Attribute>(a => { var t = a.GetType(); return t.FullName.Contains("ComponentModel") && t.Name != "PropertyTabAttribute" && t.Name != "ToolboxItemAttribute"; }); foreach (var info in obj.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public)) { if (info.CanRead && info.GetCustomAttribute(typeof(TypeConverterAttribute)) == null) { var list = info.GetCustomAttributes().Where(p => pred(p)).ToList(); if (!info.CanWrite) { var item = new ReadOnlyAttribute(true); if (!list.Contains(item)) list.Add(item); } parameterList.Add(new Parameter(info.Name, info.GetValue(obj), info.PropertyType.AssemblyQualifiedName, list.ToArray())); } } var fields = obj.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public).Where(f => f.GetCustomAttribute(typeof(TypeConverterAttribute)) == null); foreach (var param in fields.Select(f => new Parameter(f.Name, f.GetValue(obj), f.FieldType.AssemblyQualifiedName, f.GetCustomAttributes().Where(a => pred(a)).ToArray()))) parameterList.Add(param); return parameterList; }