Shadow.Quack IProxy Implementation for initialisation from an XML string
$ dotnet add package Shadow.Quack.XmlThis package allows the easy population of values directly from a XML string to a dynamically implemented immutable interface with the help of the base Shadow Quack package.
This means that there is almost no effort in deserialising from XML to an interface with no need for concrete implementations or additional code.
public interface IWithSimpleDictionary
{
public IDictionary<int, string> TestDic { get; }
}
XmlProxy source = @"
<xml>
<TestDic>
<Item>
<Key>1</Key>
<Value>One</Value>
</Item>
<Item>
<Key>2</Key>
<Value>Two</Value>
</Item>
</TestDic>
</xml>";
var target = Duck.Implement<IWithSimpleDictionary>(source);
Interface
public interface ITestTarget
{
public IAddress Address { get; }
public ITestTargetSub Sub { get; }
public ICustomer Customer { get; }
public string Name { get; }
public int Number { get; }
public IEnumerable<string> Hobbies { get; }
public IEnumerable<ITestTargetSub> Subs { get; }
public IEnumerable<IAddress> Addresses { get; }
public IEnumerable<int> Ids { get; }
}
public interface ITestTargetSub
{
string Name { get; }
}
public interface IAddress
{
}
public interface ICustomer
{
IEmployment Employment { get; }
string CustomerType { get; }
}
public interface IEmployment
{
string Employer { get; }
}
IEnumerable Example
XmlProxy source = @"
<xml>
<Name>NameValue</Name>
<number>10</number>
<Hobbies>
<Item>Item1</Item>
<Item>item2</Item>
</Hobbies>
</xml>";
var target = Duck.Implement<ITestTarget>(source);
IEnumerable<T> Example
XmlProxy source = @"
<xml>
<Name>NameValue</Name>
<number>10</number>
<Subs>
<Item>
<Name>Value1</Name>
</Item>
<Item>
<Name>Value2</Name>
</Item>
</Subs>
</xml>";
var target = Duck.Implement<ITestTarget>(source);
Sub Interface Example
XmlProxy source = @"
<xml>
<Name>NameValue</Name>
<number>10</number>
<Customer>
<CustomerType>Value2</CustomerType>
<Employment>
<Employer>Employer</Employer>
</Employment>
</Customer>
</xml>";
var target = Duck.Implement<ITestTarget>(source);