CodeDom and Addressof

B

bluedude

Hi everyone! Is there a way to generate the Addressof keyword in vb
(or '&' in c#) using codedom? I haven't been able to figure it out.

Thanks!
-Zach
 
T

Tom Shelton

Hi everyone! Is there a way to generate the Addressof keyword in vb
(or '&' in c#) using codedom? I haven't been able to figure it out.

Thanks!
-Zach

I think your looking for CodeAttachEventStatement, I believe there is an
example in the documentation for this class.
 
B

bluedude

I think your looking for CodeAttachEventStatement, I believe there is an
example in the documentation for this class.

Close, but CodeAttachEventStatement made me reconsider using
CodeDelegateCreateExpression which I didn't think I needed but in fact
does the trick. FWIW, I wanted to create something like the following
in c#:

System.Array.ConvertAll<ProprietaryDateTime,
System.DateTime>(dtrange_pr.ToArray(), new
System.Converter<ProprietaryDateTime,
System.DateTime>(ProprietaryDateTime.ConvertProprietaryDateTimeToDateTime));

So to get there I ended up using something like the following in
codedom:

CodeMethodReferenceExpression arrayConvertAllGeneric = new
CodeMethodReferenceExpression(
new CodeTypeReferenceExpression(typeof(Array)),
"ConvertAll",
new
CodeTypeReference(typeof(ProprietaryDateTime)),
new CodeTypeReference(typeof(DateTime))
);
CodeMethodInvokeExpression dtrangeToArray = new
CodeMethodInvokeExpression(
new CodeVariableReferenceExpression("dtrange_pr"),
"ToArray"
);
CodeDelegateCreateExpression createDelegate = new
CodeDelegateCreateExpression(
new CodeTypeReference("System.Converter", new
CodeTypeReference(typeof(ProprietaryDateTime)), new
CodeTypeReference(typeof(DateTime))),
new
CodeTypeReferenceExpression(typeof(ProprietaryDateTime)),
"ConvertProprietaryDateTimeToDateTime"
);
CodeMethodInvokeExpression arrayConvert = new
CodeMethodInvokeExpression(
arrayConvertAllGeneric,
dtrangeToArray,
createDelegate
);

This produces the desired result in c# and vb. Thanks for the help!
 

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

Top