473,385 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Passing references to CodeDom

Hello,

I was wondering if anyone could tell me how I can pass a reference of an object(lets pretend a MemoryStream) to CodeDom's generated code in memory?

So basically I would like to create CodeDom code that gets a reference as a parameter to an object in Form1. Then I would like to call the CodeDom code with Reflection, and have CodeDom access the object reference that was passed as a parameter. Thusly in my CodeDom code, I could have "memorystream.WriteByte(44)", and then back in Form1 I could see that memorystream has a new byte written to it...

Thanks...
Oct 22 '08 #1
1 2001
Nevermind, got it:

If you set up a barebones CodeDom configuation, using this....

List<string> stringlist = new List<string>();

public CodeNamespace myNamespace = new CodeNamespace("MyNamespace");
public CodeTypeDeclaration myFunctions = new CodeTypeDeclaration("MyFunctions");

public string code = @"public static string StringTest(System.Collections.Generic.List<string> mystrings)

mem = new CodeSnippetTypeMember(code);
myFunctions.Members.Add(mem);
myNamespace.Types.Add(myFunctions);


Then create a method for Reflection like this:

Type t = results.CompiledAssembly.GetType("MyNamespace.MyFu nctions");
System.Reflection.MethodInfo info = t.GetMethod("StringTest");
object o;
object[] objarray = new object[1]; //Could substitue 1 with stringlist.Count
objarray[0] = stringlist; // Could use for loop here to write out stringlist[x] to objarray[y]

o = info.Invoke(null, objarray);
string test = o.ToString();// o is holding the result of whatever happend with Invoke on "StringTest"... which can be whatever you want!
Oct 22 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Ron Bullman | last post by:
Hi, I havent been able to find any documentation about @ in the CodeDom context. The problem is when generating C# code from CodeDom it will associate a @-tag with all C# specific types. Why?...
2
by: Guillaume | last post by:
I don't think I'm the only one with this challenge so… I made code with the CodeDom classes and made code to create a new solution and a new project Now I want to get the codedom code in the new...
1
by: John Livermore | last post by:
Hello, We have an application that uses CodeDom for dynamic in-memory compilation of code. The same code (library) is used by both an ASP.net web site and a Windows Service. The code runs fine...
11
by: John Pass | last post by:
Hi, In the attached example, I do understand that the references are not changed if an array is passed by Val. What I do not understand is the result of line 99 (If one can find this by line...
3
by: Alexey Lavnikov | last post by:
I'm playing with CodeDOM and CSharpCodeProvider. I've found the following possibilities: CodeDOM -> Assembly C# Source code -> Assembly I miss the C# Source code -> CodeDOM only. Is it there?...
9
by: lee.chappers | last post by:
How can I make the CodeDom generate the following C# method? protected sealed override void Test() { } I've tried using: domMethod.Attributes = MemberAttributes.Override |...
6
by: moondaddy | last post by:
will CodeDom create XAML windows or just regular windows forms? If so, how to I tell it to create a xaml window instead of a windows form? thanks -- moondaddy@noemail.noemail
5
by: Kurt Jakobsen | last post by:
Hello, I have a utility class that do some db queries that are used by independent pages. From one of the utility functions I would like to return variables back to the aspx page. In old C this...
1
by: =?Utf-8?B?QU1lcmNlcg==?= | last post by:
I may have painted myself into a corner with GenerateInMemory=true. My app need a custom user step. Users want to code (sort of - they are not programmers) some refinements to a search...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.