c# 4.0 - Converting to a specific type from a string value by passing the required type as parameter -


I am using the following method to convert string types to a common type

  Public stable Tea Parse & lt; T & gt; (String Value) {// or Convertform InvoertString If you are returning the serialization (T) type TypeDescriptor.GetConverter (typef (T)). ConvertFromString (value); }   

I have to call it like this

  parse < int32 & gt; (Some string value); Parse & lt; DateTime & gt; (Some string value);   

I'm trying to instead of giving that result clearly , I

 < Code> Pars & lt; Type.GetType ("Int32") & gt; (Some string value); The primary problem is that you are  type identifier    

are trying to take a shortcut around a type of name not is just a type of name that you use in a program, that name space is also included in it , The display name of the assembly in which it is stored, the assembly number and assembly of the assembly Strong name received the public key token. In other words, type.edudoodquilified name

For who you would like to write your code like this:

  Pars (type gatetype ("System.INT32, MScorril, version = 4.0.0.0, culture = neutral , Public key token = b77a5c561934e089 "", some string value);   

This will work just fine. But I think you will not enjoy writing otherwise you will be given insights about a compiler When you read "int. 32" in your program, In which the reference assemblies that you have started with started and note that the potential match can be found in that table. The use of instructions is in effect.

In the same way, the compiler's symbol table has a dictionary that is , type>; . You can populate it with a type of type that you A small string Prefer to use the name.

  LookupTable.Add ( "int32", typeof (int)); add Lukaptabl ( "string", Taipf (string)); // etc ...   

Now you can type:

  pars (lookaptal ["int 32"], some string value);   

It will work just fine but I think you will not enjoy writing. The compiler is very difficult to beat.

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -