Anyone know how to get a Type object from a FullName?
Eg.
string fullName = typeof(string).FullName; Type stringType = <INSERT CODE HERE> Assert.AreEqual(stringType, typeof(string)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
However, note that this only searches the calling assembly and core MS assemblies. It is better to use either the
AssemblyQualifiedName, of find theAssemblyfirst, and useAssembly.GetType(fullName).Either:
or
Update re comments; note that
AssemblyQualifiedNameincludes versioning information; this is fine for use in things like configuration files, but if (as is the case here) you are using this for persistance, it is often better to use an implementation independent contract. For example, xml (viaXmlSerializerorDataContractSerializer) is not concerned about the specific types, as long as the layout is correct.If space is an issue, binary formats are often shorter – but
BinaryFormatterincludes type metadata, and isn’t platform independent (try consuming it from java, for example). In such cases, you might want to look at custom serializers such as protobuf-net, which is contract-based, but using Google’s ‘protocol buffers’ cross-platform wire format.