You've already forked linux-packaging-mono
Imported Upstream version 6.0.0.172
Former-commit-id: f3cc9b82f3e5bd8f0fd3ebc098f789556b44e9cd
This commit is contained in:
parent
8016999e4d
commit
64ac736ec5
@ -1685,5 +1685,29 @@ namespace MonoTests.System.XmlSerialization
|
||||
Assert.AreEqual ("a", d.Extra[0]);
|
||||
Assert.AreEqual ("b", d.Extra[1]);
|
||||
}
|
||||
|
||||
[Test] // PR #11194
|
||||
public void TestDerrivedClassProperty ()
|
||||
{
|
||||
var data = "<layout width=\".25\" height =\".25\" x=\"0\" y=\"0\" id=\"portrait\" class=\"render\"><background color=\"white\"><div x=\".03\" y=\".05\" width=\".94\" height =\".9\" layout=\"proportional_rows\" paddingX=\".01\" paddingY=\".02\"><background color=\"black\"></background><background color=\"gray\" padding=\".1\"><label color=\"white\" font=\"emulogic.ttf\" fontSize=\"15\">Test UI</label></background><br brSize=\"1\" /><background class=\"back,Lab\" color=\"green\"><label class=\"Lab\" color=\"white\" font=\"emulogic.ttf\" fontSize=\"15\">GREEN</label></background><background color=\"red\"><label class=\"Lab\" color=\"white\" font=\"emulogic.ttf\" fontSize=\"15\">RED</label></background><background color=\"blue\"><label class=\"Lab\" color=\"white\" font=\"emulogic.ttf\" fontSize=\"15\">TLUE</label></background><background color=\"blue\"><label class=\"Lab\" color=\"white\" font=\"emulogic.ttf\" fontSize=\"15\">BLUE</label></background></div></background></layout>";
|
||||
|
||||
XmlAttributeOverrides overrides = PR11194.GenerateLayoutOverrides<PR11194ChildLo>();
|
||||
|
||||
var result = Deserialize(typeof(PR11194ChildLo), data, overrides) as PR11194ChildLo;
|
||||
|
||||
PR11194Parent2 child;
|
||||
Assert.IsNotNull(result, "#11194_1");
|
||||
Assert.AreEqual(1, result.children.Count, "#11194_2");
|
||||
child = result.children[0] as PR11194Parent2;
|
||||
Assert.IsNotNull(child, "#11194_3");
|
||||
Assert.AreEqual(1, child.children.Count, "#11194_4");
|
||||
child = child.children[0] as PR11194Parent2;
|
||||
Assert.IsNotNull(child, "#11194_5");
|
||||
Assert.AreEqual(7, child.children.Count, "#11194_6");
|
||||
child = child.children[1] as PR11194Parent2;
|
||||
Assert.IsNotNull(child, "#11194_7");
|
||||
Assert.AreEqual(1, child.children.Count, "#11194_8");
|
||||
Assert.AreEqual("PR11194ChildL", child.children[0].GetType().Name, "#11194_9");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
// (C) 2006 Novell
|
||||
//
|
||||
|
||||
#if !MOBILE && !MONOMAC
|
||||
#if !MOBILE && !XAMMAC_4_5
|
||||
|
||||
using System;
|
||||
using System.CodeDom;
|
||||
@ -45,10 +45,11 @@ namespace MonoTests.System.XmlSerialization
|
||||
ICodeGenerator generator = provider.CreateGenerator ();
|
||||
generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
|
||||
|
||||
var currentAssembly = Assembly.GetEntryAssembly ().GetName ();
|
||||
Assert.AreEqual (string.Format(CultureInfo.InvariantCulture,
|
||||
"{0}{0}" +
|
||||
"/// <remarks/>{0}" +
|
||||
"[System.CodeDom.Compiler.GeneratedCodeAttribute(\"nunit-lite-console\", \"0.0.0.0\")]{0}" +
|
||||
"[System.CodeDom.Compiler.GeneratedCodeAttribute(\"{1}\", \"{2}\")]{0}" +
|
||||
"[System.SerializableAttribute()]{0}" +
|
||||
"[System.Diagnostics.DebuggerStepThroughAttribute()]{0}" +
|
||||
"[System.ComponentModel.DesignerCategoryAttribute(\"code\")]{0}" +
|
||||
@ -66,7 +67,7 @@ namespace MonoTests.System.XmlSerialization
|
||||
" this.namesField = value;{0}" +
|
||||
" }}{0}" +
|
||||
" }}{0}" +
|
||||
"}}{0}", Environment.NewLine), sw.ToString (), "#2");
|
||||
"}}{0}", Environment.NewLine, currentAssembly.Name, currentAssembly.Version), sw.ToString (), "#2");
|
||||
|
||||
|
||||
codeNamespace = ExportCode (typeof (ArrayClass[]));
|
||||
|
@ -12,6 +12,8 @@
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -1203,6 +1205,159 @@ namespace MonoTests.System.Xml.TestClasses
|
||||
public ClassWithDefaultTextNotNull () {
|
||||
Value = DefaultValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#region PR_11194
|
||||
|
||||
#region PR_11194_GenerateOverrides
|
||||
public static class PR11194
|
||||
{
|
||||
public static XmlAttributeOverrides GenerateLayoutOverrides<T>()
|
||||
{
|
||||
Type tType = typeof(T);
|
||||
|
||||
TypeInfo tTypeInfo = tType.GetTypeInfo();
|
||||
|
||||
IEnumerable<PropertyInfo> props = tType.GetRuntimeProperties();
|
||||
|
||||
XmlAttributeOverrides overrides = new XmlAttributeOverrides();
|
||||
|
||||
foreach (PropertyInfo prop in props) {
|
||||
XmlDerrivedAttribute attr = prop.GetCustomAttribute<XmlDerrivedAttribute>();
|
||||
|
||||
if (attr == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Type dType = prop.DeclaringType;
|
||||
|
||||
Type pType = prop.PropertyType;
|
||||
TypeInfo pTypeInfo = pType.GetTypeInfo();
|
||||
|
||||
Type enumType = typeof(IEnumerable<>);
|
||||
|
||||
if (pTypeInfo.IsGenericType
|
||||
&& pTypeInfo.ImplementedInterfaces.Any(t =>
|
||||
(t.GetTypeInfo().IsGenericType && t.GetGenericTypeDefinition() == enumType))) {
|
||||
pType = pType.GenericTypeArguments[0];
|
||||
}
|
||||
|
||||
XmlAttributes overrideAttributes = GenerateOverrideAttributes(dType, pType, attr);
|
||||
|
||||
overrides.Add(dType, prop.Name, overrideAttributes);
|
||||
}
|
||||
|
||||
return overrides;
|
||||
}
|
||||
|
||||
private static XmlAttributes GenerateOverrideAttributes (Type declaringType, Type propertyType, XmlDerrivedAttribute attr)
|
||||
{
|
||||
XmlAttributes xAttrs = new XmlAttributes();
|
||||
|
||||
Assembly a = declaringType.GetTypeInfo().Assembly;
|
||||
TypeInfo interfaceType = propertyType.GetTypeInfo();
|
||||
IEnumerable<Type> types = a.ExportedTypes.Where(t => interfaceType.IsAssignableFrom(t.GetTypeInfo()) && !t.GetTypeInfo().IsAbstract);
|
||||
|
||||
foreach (Type t in types) {
|
||||
string name = NameBySourceType(t, attr.SrcType);// t.GetTypeInfo().GetCustomAttribute<XmlTypeAttribute>().TypeName;
|
||||
XmlElementAttribute xAttr = new XmlElementAttribute();
|
||||
xAttr.ElementName = name;
|
||||
xAttr.Type = t;
|
||||
xAttrs.XmlElements.Add(xAttr);
|
||||
}
|
||||
|
||||
return xAttrs;
|
||||
}
|
||||
|
||||
private static string NameBySourceType (Type derrivedType, XmlDerrivedSourceType srcType)
|
||||
{
|
||||
string name = null;
|
||||
switch (srcType)
|
||||
{
|
||||
case XmlDerrivedSourceType.ByXmlType:
|
||||
name = derrivedType.GetTypeInfo().GetCustomAttribute<XmlTypeAttribute>().TypeName;
|
||||
break;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region helperAttribute
|
||||
public enum XmlDerrivedSourceType
|
||||
{
|
||||
ByXmlType
|
||||
}
|
||||
|
||||
public class XmlDerrivedAttribute : Attribute
|
||||
{
|
||||
public XmlDerrivedSourceType SrcType { get; set; }
|
||||
|
||||
public XmlDerrivedAttribute(XmlDerrivedSourceType srcType)
|
||||
{
|
||||
SrcType = srcType;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
public abstract class PR11194Parent
|
||||
{
|
||||
[XmlIgnore]
|
||||
public PR11194Parent Parent { get; set; }
|
||||
}
|
||||
|
||||
public abstract class PR11194Parent2 : PR11194Parent
|
||||
{
|
||||
[XmlAttribute]
|
||||
public float width { get; set; }
|
||||
[XmlAttribute]
|
||||
public float height { get; set; }
|
||||
[XmlAttribute]
|
||||
public float x { get; set; }
|
||||
[XmlAttribute]
|
||||
public float y { get; set; }
|
||||
[XmlAttribute]
|
||||
public string id { get; set; }
|
||||
[XmlElement]
|
||||
[XmlDerrived(XmlDerrivedSourceType.ByXmlType)]
|
||||
public List<PR11194Parent> children { get; set; }
|
||||
}
|
||||
|
||||
[XmlType("background")]
|
||||
public class PR11194ChildB : PR11194Parent2
|
||||
{
|
||||
[XmlAttribute]
|
||||
public string image { get; set; }
|
||||
}
|
||||
|
||||
[XmlType("br")]
|
||||
public class PR11194ChildBr : PR11194Parent
|
||||
{
|
||||
[XmlAttribute("brSize")]
|
||||
public int breaks { get; set; }
|
||||
}
|
||||
|
||||
[XmlType("div")]
|
||||
public class PR11194ChildD : PR11194ChildLo
|
||||
{
|
||||
}
|
||||
|
||||
[XmlType("label")]
|
||||
public class PR11194ChildL : PR11194Parent2
|
||||
{
|
||||
[XmlAttribute]
|
||||
public string font { get; set; }
|
||||
[XmlAttribute]
|
||||
public int fontSize { get; set; }
|
||||
[XmlText]
|
||||
public string Text { get; set; }
|
||||
}
|
||||
|
||||
[XmlType("layout")]
|
||||
public class PR11194ChildLo : PR11194Parent2
|
||||
{
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user