/// <summary> /// Implements Interfaces, allowing the specification of an export provider. /// </summary> /// <param name="node"></param> /// <param name="exports"></param> /// <returns></returns> static IEnumerable <T> Interfaces <T>(this XObject node, ExportProvider exports) { Contract.Requires <ArgumentNullException>(node != null); Contract.Requires <ArgumentNullException>(exports != null); return(node.AnnotationOrCreate <ExtensionQuery <T> >(() => exports.GetExportedValue <ExtensionQuery <T> >())); }
/// <summary> /// Implements Interfaces, allowing the specification of an export provider. /// </summary> /// <param name="node"></param> /// <param name="exports"></param> /// <returns></returns> static IEnumerable <object> Interfaces(this XObject node, Type type, ExportProvider exports) { Contract.Requires <ArgumentNullException>(node != null); Contract.Requires <ArgumentNullException>(type != null); Contract.Requires <ArgumentNullException>(exports != null); return((ExtensionQuery)node.AnnotationOrCreate(typeof(ExtensionQuery <>).MakeGenericType(type), () => exports.GetExportedValue(typeof(ExtensionQuery <>).MakeGenericType(type)))); }
/// <summary> /// Initializes a new instance. /// </summary> /// <param name="xml"></param> public ModelItem(XObject xml) { Contract.Requires <ArgumentNullException>(xml != null); this.xml = xml; this.model = new Lazy <Model>(() => xml.Document.Annotation <Model>()); this.instance = new Lazy <Instance>(() => xml.Document.Annotation <Instance>()); this.state = new Lazy <ModelItemState>(() => xml.AnnotationOrCreate <ModelItemState>()); }
/// <summary> /// Initializes a new instance. /// </summary> /// <param name="xml"></param> public ModelItem(XObject xml) { Contract.Requires<ArgumentNullException>(xml != null); this.xml = xml; this.model = new Lazy<Model>(() => xml.Document.Annotation<Model>()); this.instance = new Lazy<Instance>(() => xml.Document.Annotation<Instance>()); this.state = new Lazy<ModelItemState>(() => xml.AnnotationOrCreate<ModelItemState>()); }
/// <summary> /// Gets the unique identifier for the object. /// </summary> /// <param name="self"></param> /// <returns></returns> public static int GetObjectId(this XObject self) { Contract.Requires <ArgumentNullException>(self != null); Contract.Requires <ArgumentNullException>(self.Document != null); // gets the node id, or allocates a new one with the document return(self.AnnotationOrCreate <ObjectAnnotation>(() => new ObjectAnnotation( self.Document.AnnotationOrCreate <DocumentAnnotation>() .GetNextObjectId())).Id); }
/// <summary> /// Sets the BaseUri of the <see cref="XObject"/>. /// </summary> /// <param name="self"></param> /// <param name="baseUri"></param> public static void SetBaseUri(this XObject self, Uri baseUri) { Contract.Requires <ArgumentNullException>(self != null); if (baseUri != null) { self.AnnotationOrCreate <BaseUriAnnotation>().BaseUri = baseUri; } else { self.RemoveAnnotations <BaseUriAnnotation>(); } }
/// <summary> /// Gets the <see cref="ExportProvider"/> for the given <see cref="XObject"/>. /// </summary> /// <param name="self"></param> /// <returns></returns> public static ExportProvider Exports(this XObject self) { Contract.Requires <ArgumentNullException>(self != null); Contract.Ensures(Contract.Result <ExportProvider>() != null); // get or create the new object container annotation return(self.AnnotationOrCreate <ExportProvider>(() => { var document = self.Document.Annotation <Document>(); if (document == null) { throw new InvalidOperationException(); } // initialize new container var container = CompositionUtil.ConfigureContainer(new CompositionContainer( document.Configuration.ObjectCatalog, CompositionOptions.DisableSilentRejection, document.Container)); if (self is XObject) { container.WithExport <XObject>(self); } if (self is XDocument) { container.WithExport <XDocument>((XDocument)self); } if (self is XElement) { container.WithExport <XElement>((XElement)self); } if (self is XNode) { container.WithExport <XNode>((XNode)self); } if (self is XAttribute) { container.WithExport <XAttribute>((XAttribute)self); } return container; })); }
/// <summary> /// Gets the model item for the given <see cref="XObject"/>. /// </summary> /// <param name="obj"></param> /// <returns></returns> public static ModelItem Get(XObject obj) { return(obj.AnnotationOrCreate <ModelItem>(() => new ModelItem(obj))); }
/// <summary> /// Obtains the model item properties for <paramref name="obj"/>. /// </summary> /// <param name="obj"></param> /// <returns></returns> ModelItemState GetModelItem(XObject obj) { Contract.Requires<ArgumentNullException>(obj != null); return obj.AnnotationOrCreate<ModelItemState>(); }
/// <summary> /// Obtains the model item properties for <paramref name="obj"/>. /// </summary> /// <param name="obj"></param> /// <returns></returns> ModelItemState GetModelItem(XObject obj) { Contract.Requires <ArgumentNullException>(obj != null); return(obj.AnnotationOrCreate <ModelItemState>()); }
bool IsValid(XObject obj) { return obj.AnnotationOrCreate<ValidityAnnotation>(() => new ValidityAnnotation(true)).Valid; }
bool IsValid(XObject obj) { return(obj.AnnotationOrCreate <ValidityAnnotation>(() => new ValidityAnnotation(true)).Valid); }
/// <summary> /// Gets the model item for the given <see cref="XObject"/>. /// </summary> /// <param name="obj"></param> /// <returns></returns> public static ModelItem Get(XObject obj) { return obj.AnnotationOrCreate<ModelItem>(() => new ModelItem(obj)); }