CodeDOM question


C

Clu

Hi all !

I've got a simple CodeDOM question.

I've defined the following types:

[ClsCompliant (true)]
enum CustomValues {
Value1,
Value2
}

and MyCustomAttribute, which is CLSCompliant too and has
some property, some of which are of primitive type and
some of cutom types, like for example the CustomValues
enum.

I need to generate the following code:

[MyCustomAttribute ("ConstructionString", Name="xx",
CustomValue=CustomValues.Value1)]
public class MyClass {
}

My problem is how to generate the attribute.
More precisely, i do not know
1. how to generate the attribute arguments if they are of
custom types.
2. how to pass an argument to the attribute constructor

I've done something like this:

°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
// once for each argument i want to pass
CodeAttributeArgument attrArg = new CodeAttributeArgument
();
attrArg.Name = <i put here my attribute property's name>
attrArg.Value = <what expression do i put here?> }

// finally
CodeAttributeArgument[] attrs = new CodeAttributeArgument
[<# of arguments>];
CodeAttributeDeclaration attrDecl = new
CodeAttributeDeclaration (
"MyNamespace.MyCustomAttribute",attrs);

// Add the clas
CodeTypeDeclaration classDeclaration = new
CodeTypeDeclaration ("MyClass");
classDeclaration.BaseTypes.Add (typeof (Object));
classDeclaration.IsClass = true;
classDeclaration.TypeAttributes = TypeAttributes.Public;
classDeclaration.CustomAttributes.Add (attrDecl);
°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°

Do you have any suggestion ?

Thanks a lot in advance.

Hi

Clu
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

CodeDom Question 3
CodeDOM question 0
CodeDom and @ 0
slow CodeDom 0
EnvDTE of CodeDom 1
CodeDom and enums 0
Doing "&&" in codeDOM 2
CodeDOM question: explicit conversion operator generation 1

Top