public void TypeId_Get_ReturnsExcepted(string serializerBaseTypeName, object expected) { var attribute = new RootDesignerSerializerAttribute("SerializerType", serializerBaseTypeName, reloadable: true); Assert.Equal(expected, attribute.TypeId); Assert.Same(attribute.TypeId, attribute.TypeId); }
public void Ctor_SerializerTypeName_BaseSerializerType(string serializerTypeName, string baseSerializerTypeName, bool reloadable) { var attribute = new RootDesignerSerializerAttribute(serializerTypeName, baseSerializerTypeName, reloadable); Assert.Equal(serializerTypeName, attribute.SerializerTypeName); Assert.Equal(baseSerializerTypeName, attribute.SerializerBaseTypeName); Assert.Equal(reloadable, attribute.Reloadable); }
public void Ctor_SerializerType_BaseSerializerType(Type serializerType, Type baseSerializerType, bool reloadable) { var attribute = new RootDesignerSerializerAttribute(serializerType, baseSerializerType, reloadable); Assert.Equal(serializerType.AssemblyQualifiedName, attribute.SerializerTypeName); Assert.Equal(baseSerializerType.AssemblyQualifiedName, attribute.SerializerBaseTypeName); Assert.Equal(reloadable, attribute.Reloadable); }
public void TypeId_NullBaseSerializerTypeName_ReturnsExpected() { var attribute = new RootDesignerSerializerAttribute("SerializerType", (string)null, reloadable: true); if (!PlatformDetection.IsFullFramework) { Assert.Equal("System.ComponentModel.Design.Serialization.RootDesignerSerializerAttribute", attribute.TypeId); } else { Assert.Throws <NullReferenceException>(() => attribute.TypeId); } }
public override void Flush() { if (this.dirty) { XmlDocument document = new XmlDocument(); document.AppendChild(document.CreateElement("DOCUMENT_ELEMENT")); IComponent root = this.host.RootComponent; Hashtable nametable = new Hashtable(this.host.Container.Components.Count); document.DocumentElement.AppendChild(this.WriteObject(document, nametable, root)); foreach (IComponent comp in this.host.Container.Components) { if (!((comp == root) || nametable.ContainsKey(comp))) { document.DocumentElement.AppendChild(this.WriteObject(document, nametable, comp)); } } CodeCompileUnit code = new CodeCompileUnit(); CodeNamespace ns = new CodeNamespace(root.Site.Name + "Namespace"); ns.Imports.Add(new CodeNamespaceImport("System")); SampleTypeResolutionService strs = this.host.GetService(typeof(ITypeResolutionService)) as SampleTypeResolutionService; foreach (Assembly assm in strs.RefencedAssemblies) { ns.Imports.Add(new CodeNamespaceImport(assm.GetName().Name)); } RootDesignerSerializerAttribute a = TypeDescriptor.GetAttributes(root)[typeof(RootDesignerSerializerAttribute)] as RootDesignerSerializerAttribute; CodeDomSerializer cds = Activator.CreateInstance(this.host.GetType(a.SerializerTypeName)) as CodeDomSerializer; IDesignerSerializationManager manager = this.host.GetService(typeof(IDesignerSerializationManager)) as IDesignerSerializationManager; CodeTypeDeclaration td = cds.Serialize(manager, root) as CodeTypeDeclaration; CodeConstructor con = new CodeConstructor(); con.Attributes = MemberAttributes.Public; con.Statements.Add(new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(new CodeThisReferenceExpression(), "InitializeComponent"), new CodeExpression[0])); td.Members.Add(con); CodeEntryPointMethod main = new CodeEntryPointMethod(); main.Name = "Main"; main.Attributes = MemberAttributes.Public | MemberAttributes.Static; main.CustomAttributes.Add(new CodeAttributeDeclaration("System.STAThreadAttribute")); main.Statements.Add(new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(new CodeTypeReferenceExpression(typeof(Application)), "Run"), new CodeExpression[] { new CodeObjectCreateExpression(new CodeTypeReference(root.Site.Name), new CodeExpression[0]) })); td.Members.Add(main); ns.Types.Add(td); code.Namespaces.Add(ns); this.dirty = false; this.xmlDocument = document; this.codeCompileUnit = code; this.UpdateCodeWindows(); } }
public void TypeId_NullBaseSerializerTypeName_ThrowsNullReferenceException() { var attribute = new RootDesignerSerializerAttribute("SerializerType", (string)null, reloadable: true); Assert.Throws <NullReferenceException>(() => attribute.TypeId); }