Short question: is there a way to access the datatypes available in .net application as a group (and hence query them with LINQ). Like this …
Dim myType = from l in myapplication.availabledatatypes where l.name="name of type I want" select l
Longer explanation:
I’m trying to move lots of old records from tables into identical ‘archive’ tables with Linq to SQL. As a part of that process, I need to select records from the live table and convert them to the (identical) archive type. I’m trying to do this cleanly with a single method that can be used for all the different table/archive table pairs by using reflection, following this excellent guide
http://michaelmerrell.com/2010/08/converting-a-linq-object-to-a-similar-object/
My conversion method will take an input of type object and convert it to an output of type object, which I then plan to cast to the required output type in the method that calls the converting method. I am able to get the property of datacontext which has the same name as the type I want to convert to, but I can’t seem to programatically pull the type with the same name.
Dim typeIamLookingFor as propertyInfo= from l in mydatacontext.getproperties where l.name.contains("archive") and l.name.contains(input.gettype.name) select l
How do I pick, from the types available in my namespace, the one whose name equals that of typeIamLookingFor. Obviously .getType returns the type PropertyInfo, but what I really want is the type with the name = typeiamlookingfor.name
Edit
Thanks for suggestions. Type.GetType gets me closer, but compiler now saying Object Must Implement IConvertible. I am going to investigate this different error and accept this answer.
Dim output as object
Dim typeName as string = "namespace." & inputObject.gettype.name & "_Archive"
output = output = Convert.ChangeType(output, Type.GetType(typeName)) //generates error: Object Must Implement IConvertible
I think you are over-complicating your solution. Based on your description, you probably just need
Type.GetType():Is there more to it?