public void LoadFromXml(XmlAttributeCollection childNodeAttributes) { PropertyInfo[] props = this.GetType().GetAllProperties(); foreach (PropertyInfo propertyInfo in props) { AssetAttribute attr = propertyInfo.GetCustomAttribute <AssetAttribute>(); if (attr != null) { if (childNodeAttributes.GetNamedItem(attr.XMLName)?.Value != null) { string temp = childNodeAttributes.GetNamedItem(attr.XMLName)?.Value; if (temp != null) { DataboundValue temp2 = DataboundAssetExtensions.GetDBValue(temp, propertyInfo.PropertyType.GenericTypeArguments.First()); propertyInfo.SetValue(this, temp2); } } } else { string name = propertyInfo.Name; string temp = childNodeAttributes.GetNamedItem(name)?.Value; if (temp != null) { DataboundValue temp2 = DataboundAssetExtensions.GetDBValue(temp, propertyInfo.PropertyType.GenericTypeArguments.First()); propertyInfo.SetValue(this, temp2); } } } }
public void FixBinds() { //PropertyInfo[] props = this.GetType().GetAllProperties(); PropertyInfo[] props = this.GetType().GetProperties(); foreach (PropertyInfo propertyInfo in props) { if (propertyInfo.PropertyType.Name.StartsWith("DataboundValue")) { DataboundValue tmp = (DataboundValue)propertyInfo.GetValue(this); tmp.ParentAsset = this; } } if (this is DataboundContainterAsset containerAsset) { if (containerAsset.Children != null && containerAsset.Children.Value != null) { foreach (DataboundAsset databoundAsset in containerAsset.Children.Value) { databoundAsset.FixBinds(); } } } }
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 bool Set <T>(ref T input, T newValue, [CallerMemberName] string callerMemberName = "") { if (!input.Equals(newValue)) { var db = DataBindings.FirstOrDefault(t => t != null && t.Value.Key == callerMemberName); if (db == null) { throw new Exception("Binding not found"); } DataboundValue <T> dbv = (DataboundValue <T>)db.Value.Value; dbv.Value = newValue; return(true); } else { return(false); } }
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); }