By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,837 Members | 1,206 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,837 IT Pros & Developers. It's quick & easy.

Parameters for CodeDom compiled code can't convert

P: 2
I'm having problems passing a variable to a method which is executed and compiled using CodeDom. The situation is I have a List<CellData> with cells, each containing a formula (like Excel). I am trying to pass this list to an executable section of code which is compiled during run-time. The formulas are calculated in CodeDom and the result is returned on the same List<CellData> object I passed.

The user-defined class which holds the cell data is defined here:

Expand|Select|Wrap|Line Numbers
  1. public class CellData
  2. {
  3. private int row;
  4. private int level;
  5. private int column;
  6. private string formula;
  7. private object result;
  8. private List<CellData> children;
  9.  
  10. public int Row { get { return row; } set { row = value; } }
  11. public int Column { get { return column; } set { column = value; } }
  12. public int Level { get { return level; } set { level = value; } }
  13. public string Formula { get { return formula; } set { formula = value; } }
  14. public object Result { get { return result; } set { result = value; } }
  15. public List<CellData> Children { get { return children; } set { children = value; } }
  16.  
  17. // Constructor
  18. public CellData(int CellRow, int CellColumn, int CellLevel, string CellFormula)
  19. {
  20. row = CellRow;
  21. column = CellColumn;
  22. formula = CellFormula;
  23. level = CellLevel;
  24.  
  25. children = new List<CellData>();
  26. }
  27. }

Since I needed the compiled CodeDom code to know what a CellData object was, I replicated that within the CodeDom code. The compiled code looks something like this:

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4.  
  5. namespace C_Tech_Programmer
  6. {
  7. public class Code
  8. {
  9. // Calculate all of the formulas
  10. public List<CellData> Calculate(List<CellData> calcList)
  11. {
  12. calcList[0].Result = 7 * 7 * 9;
  13. return calcList;
  14. }
  15. }
  16.  
  17. public class CellData
  18. {
  19. private int row;
  20. private int level;
  21. private int column;
  22. private string formula;
  23. private object result;
  24. private List<CellData> children;
  25. public int Row { get { return row; } set { row = value; } }
  26. public int Column { get { return column; } set { column = value; } }
  27. public int Level { get { return level; } set { level = value; } }
  28. public string Formula { get { return formula; } set { formula = value; } }
  29. public object Result { get { return result; } set { result = value; } }
  30. public List<CellData> Children { get { return children; } set { children = value; } }
  31.  
  32. // Constructor
  33. public CellData(int CellRow, int CellColumn, int CellLevel, string CellFormula)
  34. {
  35. row = CellRow;
  36. column = CellColumn;
  37. formula = CellFormula;
  38. level = CellLevel;
  39.  
  40. children = new List<CellData>();
  41. }
  42. }
  43. }
To executed the compiled code, I pass my list of CellData objects to the Invoke method for the CodeDom code.

Expand|Select|Wrap|Line Numbers
  1. List<CellData> result = new List<CellData>();
  2.  
  3. result = (List<CellData>)mi.Invoke(assemblyInstance, new object[] { calcOrder });

The problem is that it won't make the conversion from the CellData class in my normal code to the CellData class in the CodeDom compiled code. This is the error that comes up:

{"Object of type 'System.Collections.Generic.List`1[C_Tech_Programmer.CellData]' cannot be converted to type 'System.Collections.Generic.List`1[C_Tech_Programmer.CellData]'."}

I have checked both classes over and they look exactly the same to me. If there is some sort of way to convert these, or even a better way to go about doing this, I would be much obliged to know how.

Thanks,
Dan
Aug 1 '07 #1
Share this Question
Share on Google+
2 Replies


Plater
Expert 5K+
P: 7,872
Why use two different declarations of the class?
Define the class once and then allow it to be used by both sides?
Aug 1 '07 #2

P: 2
Since I'm using CodeDom, it takes a source file as a string and compiles and executes that code within the application you are running. So it's pretty much in a complete different instance of what the application itself is. It can't reference the class if I put it in a design time.
Aug 1 '07 #3

Post your reply

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