Example #1
0
        object fetchObject(Type t, Func <object, int, bool> test, string src)
        {
            IList objects = null;

            if (src != null)
            {
                var containerType = PluginManager.LocateType(src);
                if (containerType != null)
                {
                    objects = (IList)ComponentSettings.GetCurrent(containerType);
                }
            }

            if (objects == null)
            {
                objects = ComponentSettingsList.GetContainer(t);
            }

            var exact = objects.Cast <object>().Where(test).Where(o => o.GetType().DescendsTo(t)).FirstOrDefault();

            if (exact != null)
            {
                return(exact);
            }

            return(objects.Cast <object>().FirstOrDefault(x => x.GetType().DescendsTo(t)));
        }
Example #2
0
        /// <summary> Deserialization implementation. </summary>
        public override bool Deserialize(XElement element, ITypeData t, Action <object> setter)
        {
            if (t.DescendsTo(TypeData.FromType(typeof(IConstResourceProperty))))
            {
                if (element.IsEmpty)
                {
                    return(true);                 // Dont do anything with a <port/>
                }
                var name = element.Attribute("Name");
                if (name == null)
                {
                    return(true);
                }
                Serializer.Deserialize(element.Element("Device"), obj =>
                {
                    var resource = obj as IResource;

                    if (obj is ComponentSettings)
                    {  // for legacy support. type argument was a component settings, not a device. In this case used index to get the resource.
                        obj     = ComponentSettings.GetCurrent(obj.GetType());
                        var lst = (IList)obj;
                        var dev = element.Element("Device");
                        if (dev != null && int.TryParse(dev.Value, out int index) && index >= 0 && lst.Count > index)
                        {
                            resource = ((IList)obj)[index] as IResource;
                        }
                    }
                    if (resource == null)
                    {
                        return;
                    }


                    foreach (var resProp in resource.GetConstProperties())
                    {
                        if (TypeData.GetTypeData(resProp).DescendsTo(t) && resProp.Name == name.Value)
                        {
                            setter(resProp);
                            return;
                        }
                    }
                }, typeof(IResource));
                return(true);
            }
            return(false);
        }