Ask a Question related to ASP.NET Building Controls, Design and Development.
-
mnowosad #1
How to use custom DesignerSerializer to generate a class declarati
I am trying to use a custom DesignerSerializer to generate a class
declaration based on the properties of a custom control which is used by a
page. The idea is that whenever the user changes the values of the control
properties, the class declaration is modified accordingly (like a simplified
code generation wizard).
However, I have been having problems to make it work. The issue is that I
can not make the Serialize method of the custom DesignerSerializer to
incorporate the class declaration.
First I tried to add the class declaration to the same namespace block of
the page class. But whenever I make this call:
public override object Serialize(IDesignerSerializationManager manager,
object value)
{
CodeNamespace namespaceBlock = (CodeNamespace)
manager.Context[typeof(CodeNamespace)];
/* Code that tries to use the namespaceBlock */
}
the variable namespaceBlock returns "null". So it seems that you can not
generate code outside the page class in the design-time.
As a result, I changed my strategy to generate a nested class inside the
page class. However, that did not work either. The strange thing is that I am
able to add method declaration to the page class. However, any attempt to a
add a nested class is ignored.
Here is the code:
public override object Serialize(IDesignerSerializationManager manager,
object value)
{
CodeDomSerializer baseSerializer = (CodeDomSerializer)
manager.GetSerializer(typeof(MyCustomControl).Base Type,
typeof(CodeDomSerializer));
object codeObject = baseSerializer.Serialize(manager, value);
// Get reference to the page Class code
CodeTypeDeclaration pageClassCode = (CodeTypeDeclaration)
manager.Context[typeof(CodeTypeDeclaration)];
// Generating the method declaration.
CodeMemberMethod myMethod = new CodeMemberMethod();
myMethod.Name = "MyMethod";
myMethod.Attributes = MemberAttributes.Family | MemberAttributes.Final;
myMethod.ReturnType = new CodeTypeReference(typeof(void));
// Generating the class declaration.
CodeTypeDeclaration myClass = new CodeTypeDeclaration("MyClass");
myClass.Attributes = MemberAttributes.Family | MemberAttributes.Final;
myClass.TypeAttributes = TypeAttributes.Class |
TypeAttributes.NestedFamily;
// This works beautifully. :-)
// Method declaration is added to the page class code.
pageClassCode.Members.Add(myMethod);
// This does not work. :-(
// No nested class declaration is added to the page class code.
pageClassCode.Members.Add(myClass);
return codeObject;
}
Thanks in advance for any help in this issue.
Marcos
mnowosad Guest
-
Pending Class onResult in custom class.
Ok, I have a custom class with private field: private var test:Stringint the constructor I load the web service: pws = new... -
How can i generate a instence of Class by transfer aString of Class name?
How can i generate a instance of Class by transfer a String of Class name in actionscript 3.0? like in java: Class aclass =... -
InvalidOperationException: Unable to generate a temporary class
I have a web services on my development system (localhost), here the unit tests work. I deployed the web service to a server on our intranet,... -
Attributes on a class to generate parameter values inside XML node
I might have the terms wrong, I'm an XML newbie, but here is what I need to do: I am returning an object in a webservice. public class Profile... -
How to dynamically generate functions in a class
I am having to be tasked with a rather painful task of updating an existing class by adding a dynamic amount of database field values; for each...



Reply With Quote

