T CreateObject <T> (string filter, XPathNavigator navigator) where T : Object { navigator.MoveToChild("class", Schemas.UpnpSchema); var type = ClassManager.GetTypeFromClass(navigator.Value); navigator.MoveToParent(); if (type == null || (type != typeof(T) && !type.IsSubclassOf(typeof(T)))) { return(null); } var @object = (T)Activator.CreateInstance(type, true); using (var reader = navigator.ReadSubtree()) { reader.Read(); @object.Deserialize(this, reader); } if (container_update_ids.ContainsKey(@object.ParentId)) { @object.ParentUpdateId = container_update_ids[@object.ParentId]; } object_cache[filter][@object.Id] = new WeakReference(@object); return(@object); }
static bool IsValidType <T> (IList <ClassReference> classes, bool allowSuperClasses) where T : Object { if (classes.Count == 0) { return(true); } var type = ClassManager.GetClassFromType <T> (); foreach (var @class in classes) { var class_name = @class.Class.FullClassName; var compare = type.CompareTo(class_name); if (compare == 0) { return(true); } else if (allowSuperClasses && class_name.StartsWith(type)) { return(true); } else if (compare == 1) { return(false); } else if (type.StartsWith(class_name) && @class.IncludeDerived) { return(true); } } return(false); }
protected virtual IEnumerable <T> Deserialize <T> (string xml) { var types = new List <Type> (); foreach (var @object in Deserialize <Object> (xml, Deserializers())) { types.Add(ClassManager.GetTypeFromClassName(@object.Class.FullClassName)); } return(Deserialize <T> (xml, Deserializers <T> (types))); }
public Object(string id, string parentId, ObjectOptions options) { if (id == null) { throw new ArgumentNullException("id"); } else if (parentId == null) { throw new ArgumentNullException("parentId"); } else if (options == null) { throw new ArgumentNullException("options"); } Id = id; ParentId = parentId; Title = options.Title; Creator = options.Creator; WriteStatus = options.WriteStatus; IsRestricted = options.IsRestricted; Resources = Helper.MakeReadOnlyCopy(options.Resources); Class = new Class(ClassManager.GetClassNameFromType(GetType())); }
public Results <T> SearchForType <T> (ResultsSettings settings) where T : Object { var class_name = ClassManager.GetClassFromType <T> (); return(Search <T> (string.Format(@"upnp:class derivedfrom ""{0}""", class_name), settings)); }