נשלח בתאריך: 07 August 2005 בשעה 00:17 | | IP רשוּם
|
|
|
|
Hi all,
I'm trying to generate the folowing code with System.CodeDom namespace:
קוד:
namespace CodeDomTest { public class DerivedClass : AbstractClass { }
[System.Xml.Serialization.XmlType("AbstractClass")] [System.Xml.Serialization.XmlInclude(typeof(DerivedClass))] public abstract class AbstractClass { } }
The code behind:
CodeNamespace codeNamespace = new CodeNamespace("CodeDomTest");
CodeTypeDeclaration derivedClass = new CodeTypeDeclaration(); derivedClass.Name = "DerivedClass"; derivedClass.Attributes = MemberAttributes.Public; derivedClass.IsClass = true;derivedClass.BaseTypes.Add("AbstractClass"); codeNamespace.Types.Add(derivedClass);
CodeTypeDeclaration abstractClass = new CodeTypeDeclaration(); abstractClass.Name = "AbstractClass"; abstractClass.IsClass = true; abstractClass.TypeAttributes = System.Reflection.TypeAttributes.Abstract | System.Reflection.TypeAttributes.Public;
abstractClass.CustomAttributes.Add( new CodeAttributeDeclaration("System.Xml.Serialization.XmlType", new CodeAttributeArgument(new CodePrimitiveExpression(abstractClass.Name))));
//Return [System.Xml.Serialization.XmlInclude(null)] //Type type = Type.GetType("DerivedClass"); //abstractClass.CustomAttributes.Add( // new CodeAttributeDeclaration("System.Xml.Serialization.XmlInclude", // new CodeAttributeArgument(new CodePrimitiveExpression(type))));
//Return [System.Xml.Serialization.XmlInclude("typeof(DerivedClass)")] //abstractClass.CustomAttributes.Add( // new CodeAttributeDeclaration("System.Xml.Serialization.XmlInclude", // new CodeAttributeArgument(new CodePrimitiveExpression("typeof(DerivedClass)"))));
//Return Exception //abstractClass.CustomAttributes.Add( // new CodeAttributeDeclaration("System.Xml.Serialization.XmlInclude", // new CodeAttributeArgument(new CodePrimitiveExpression(type))));
codeNamespace.Types.Add(abstractClass);
|
|
|
I can't add a XmlInclude attribute since it needs the type as parameter and the type is only in the CodeNamespace. Any suggestions ?
|