public void FireEvent(DataboundValue <string> eventBinding, object[] paramsToSend) { string eventName = eventBinding.Value(); if (!string.IsNullOrWhiteSpace(eventName)) { VirtualizedDataContext context = this.VirtualizedDataContext; MethodInfo methodInDataContext = context.GetType().GetMethod(eventName); if (methodInDataContext != null) { methodInDataContext.Invoke(context, paramsToSend); } else { MethodInfo methodInScreen = context.Screen.GetType().GetMethod(eventName); methodInScreen?.Invoke(context.Screen, paramsToSend); } } }
public static DataboundAsset CreateFromXml(XmlAttributeCollection childNodeAttributes, Type type, DataboundAsset parentAsset, BaseScreen baseScreen) { DataboundAsset asset = (DataboundAsset)Activator.CreateInstance(type); var assetType = asset.GetType(); PropertyInfo[] tprops = assetType.GetProperties(); PropertyInfo[] props = tprops.Where(propertyInfo => propertyInfo.GetMethod.ReturnType.AssemblyQualifiedName.Contains("DataboundValue")).ToArray(); List <string> childNodeNames = new List <string>(); foreach (object childNodeAttribute in childNodeAttributes) { childNodeNames.Add(((XmlAttribute)childNodeAttribute).Name); } Dictionary <string, PropertyInfo> prps = new Dictionary <string, PropertyInfo>(); foreach (PropertyInfo propertyInfo in props) { AssetAttribute attr = propertyInfo.GetCustomAttribute <AssetAttribute>(); string name = propertyInfo.Name; if (attr != null) { name = attr.XMLName; } prps.Add(name, propertyInfo); } Breeze.VirtualizedDataContext embeddedDataContext = new VirtualizedDataContext(); foreach (string s in childNodeNames) { if (prps.ContainsKey(s)) { PropertyInfo p = prps[s]; string temp = childNodeAttributes.GetNamedItem(s)?.Value; if (temp != null) { DataboundValue temp3 = (DataboundValue)DataboundAssetExtensions.GetDBerValue(temp, p.PropertyType.GenericTypeArguments.First()); p.SetValue(asset, temp3); } } else { if (s.StartsWith("x_")) { string propName = s.Substring(2); string temp = childNodeAttributes.GetNamedItem(s)?.Value; string propType = temp.Split('|').First(); string value = temp.Split('|').Last(); Type deftype = Type.GetType(propType) ?? Type.GetType("System." + propType); if (temp != null) { DataboundValue temp3 = (DataboundValue)DataboundAssetExtensions.GetDBerValue(value, deftype); embeddedDataContext.Store.Add(propName, value); } } else { throw new Exception("Could not find prop: " + s); } } } if (embeddedDataContext.Store.Count > 0) { asset.VirtualizedDataContext = embeddedDataContext; asset.VirtualizedDataContext.Screen = baseScreen; } return(asset); }