public void NamespacePrefixValidationTest()
        {
            string xaml = @"
<NamespacePrefixValidation xmlns=""clr-namespace:Test.Elements;assembly=XamlTestClasses"" xmlns:s=""clr-namespace:System;assembly=mscorlib"">
    <NamespacePrefixValidation.BarContainer>
        <BarContainer xmlns:st=""clr-namespace:System.Threading;assembly=System"" xmlns:scg=""clr-namespace:System.Collection.Generic;assembly=System"" >
            <BarContainer.Bar>1</BarContainer.Bar>
        </BarContainer>
    </NamespacePrefixValidation.BarContainer>
    <NamespacePrefixValidation.FooContainer>
        <FooContainer xmlns:sx=""clr-namespace:System.Xaml;assembly=System.Xaml"" xmlns:s=""clr-namespace:System.Collections.Generic;assembly=System"">
            <FooContainer.Foo>4</FooContainer.Foo>
        </FooContainer>
    </NamespacePrefixValidation.FooContainer>
    <NamespacePrefixValidation.FooContainerTemplate>
        <FooContainer xmlns:sx=""clr-namespace:System.Xaml;assembly=System.Xaml"" xmlns:st=""clr-namespace:System.Threading;assembly=System"" xmlns:scg=""clr-namespace:System.Collection.Generic;assembly=System"">
            <FooContainer.Foo>6</FooContainer.Foo>
        </FooContainer>
    </NamespacePrefixValidation.FooContainerTemplate>
</NamespacePrefixValidation>
";
            NamespacePrefixValidation npv = XamlServices.Parse(xaml) as NamespacePrefixValidation;

            FooContainer container1 = npv.FooContainerTemplate();
            FooContainer container2 = npv.FooContainerTemplate();
        }
    public static void Run()
    {
        var f = new FooContainer()
        {
            new SomeGenericClass <string> {
                Name = "firstParam", Description = "First Paramater Serialized", Value = "Foobar"
            },
            new SomeGenericClass <int>  {
                Name = "nextParam", Description = "Second Serialized parameter", Value = 10000
            }
        };

        f.FooName = "DoSomething";

        XmlSerializer serializer = new XmlSerializer(f.GetType());
        StringBuilder sb         = new StringBuilder();

        // Serialize
        using (StringWriter writer = new StringWriter(sb))
        {
            serializer.Serialize(writer, f);
        }

        Console.WriteLine(sb);

        // Deserialize
        using (StringReader reader = new StringReader(sb.ToString()))
        {
            FooContainer f2 = (FooContainer)serializer.Deserialize(reader);
        }
    }
        public void RunWrappedCollectionTest()
        {
            FooContainer fooContainer = new FooContainer(), cloneContainer;
            Foo foo = GetFullFoo(), clone;
            fooContainer.Foo = foo;

            cloneContainer = Serializer.DeepClone(fooContainer);
            clone = cloneContainer.Foo;
            Assert.IsNotNull(cloneContainer, "Clone Container");
            Assert.IsTrue(CompareFoos(foo, clone));
        }
        public void RunWrappedCollectionTest()
        {
            FooContainer fooContainer = new FooContainer(), cloneContainer;
            Foo          foo = GetFullFoo(), clone;

            fooContainer.Foo = foo;

            cloneContainer = Serializer.DeepClone(fooContainer);
            clone          = cloneContainer.Foo;
            Assert.NotNull(cloneContainer); //, "Clone Container");
            Assert.True(CompareFoos(foo, clone));
        }
Exemple #5
0
    static void Main(string[] args)
    {
        XmlSerializer s = new XmlSerializer(typeof(FooContainer));

        var str = new StringWriter();
        var fc  = new FooContainer();

        var lst = new List <Foo>()
        {
            new Foo(), new Foo(), new Foo()
        };

        fc.lst.Add(lst);

        s.Serialize(str, fc);
    }
Exemple #6
0
        public void SerializeFooContainerTest()
        {
            var value = new FooContainer
            {
                Foo = new FooBar
                {
                    Id          = 1,
                    Description = "test"
                }
            };

            var serializer = GetSerializer();
            var actual     = serializer.ToXml(value);
            var expected   = @"<fooContainer xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""><foo xsi:type=""NetBike.Xml.Tests.Samples.FooBar""><description>test</description><id>1</id></foo></fooContainer>";

            Assert.That(actual, IsXml.Equals(expected).WithIgnoreDeclaration());
        }
Exemple #7
0
        public void SerializeFooContainerWithoutTypeHandlingTest()
        {
            var value = new FooContainer
            {
                Foo = new FooBar
                {
                    Id          = 1,
                    Description = "test"
                }
            };

            var serializer = GetSerializer();

            serializer.Settings.TypeHandling = XmlTypeHandling.None;
            var actual   = serializer.ToXml(value);
            var expected = @"<fooContainer xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""><foo><id>1</id></foo></fooContainer>";

            Assert.That(actual, IsXml.Equals(expected).WithIgnoreDeclaration());
        }
Exemple #8
0
        public void SerializeFooContainerWithReferenceExpansionFirstAccessed()
        {
            var value = new FooContainer
            {
                ReferenceA = new FooReference(),
                ReferenceB = new FooReference()
            };

            value.ReferenceA.Reference = value.ReferenceB;

            var serializer = GetSerializer();

            serializer.Settings.ReferenceHandling  = XmlReferenceHandling.Handle;
            serializer.Settings.ReferenceExpansion = XmlReferenceExpansion.FirstAccessed;

            var actual   = serializer.ToXml(value);
            var expected = @"<fooContainer id=""1""><referenceA id=""2""><reference id=""3"" /></referenceA><referenceB ref=""3"" /></fooContainer>";

            Assert.That(actual, IsXml.Equals(expected).WithIgnoreDeclaration());
        }
 public FooContainerSerializable(FooContainer serializationTarget)
 {
     this.SerializationTarget = serializationTarget;
 }