Question about dynamic way to create a type

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have web service always return a string in Xml format, and I have the code
at client side translates this return string into correct value. For example:
my web service returns a <ret type=â€System.intâ€>1</ret>.
So my client logic will translate this into integer value of one by using
Type.GetType() function. Likewise, if my web service returns a <ret
type=â€System.Stringâ€>abc</ret>, my client again translates this into string
type. My problem is when I try to return a System.Data.DataTable in my return
Xml string, and Type.GetType()can not return a System.Data.DataTable type for
me due to System.Data is not in mscorlib. I like to know is there other way
to create a Type based on return string.
 
I have web service always return a string in Xml format, and I have the code
at client side translates this return string into correct value. For example:
my web service returns a <ret type=â€System.intâ€>1</ret>.
So my client logic will translate this into integer value of one by using
Type.GetType() function. Likewise, if my web service returns a <ret
type=â€System.Stringâ€>abc</ret>, my client again translates this into string
type. My problem is when I try to return a System.Data.DataTable in my return
Xml string, and Type.GetType()can not return a System.Data.DataTable type for
me due to System.Data is not in mscorlib. I like to know is there other way
to create a Type based on return string.

You also need the assembly of the type. I'm using the
following method for the type lookup. It simply assumes
that the assembly with the type is already loaded.

public static Type GetType(string typeName)
{
foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies())
{
Type t = a.GetType(typeName);
if (t != null) return t;
}
return null;
}

bye
Rob
 
I have web service always return a string in Xml format, and I have the code
at client side translates this return string into correct value. For example:
my web service returns a <ret type=?System.int?>1</ret>.
So my client logic will translate this into integer value of one by using
Type.GetType() function. Likewise, if my web service returns a <ret
type=?System.String?>abc</ret>, my client again translates this into string
type. My problem is when I try to return a System.Data.DataTable in my return
Xml string, and Type.GetType()can not return a System.Data.DataTable type for
me due to System.Data is not in mscorlib. I like to know is there other way
to create a Type based on return string.

Please see the responses to your post from September 30th.

If you're actually wanting to specify a value as well, it strikes me
you're likely to need a fixed set of types you support - in which case
you don't need to use reflection at all.
 
Back
Top