Exemplo n.º 1
0
        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);
                    }
                }
            }
        }
Exemplo n.º 2
0
        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);
        }