I’m going to store Type.FullName, i.e. ‘System.String’ in a database field. Type names that will be stored are arbitrary, not under my control. What is the max length for a type name?
EDIT: I will not be using this info to create instances of the type, it is just used for filtering/sorting/grouping, so storing just FullName instead of AssemblyQualifiedName is OK.
There’s no maximum length I’m aware of… so you should probably go for a maximum sensible length. Something like 256 should be adequate for anything sensible, IMO. 128 may well be fine, but if you have a deep namespace hierarchy and a long outer class name and a long nested class name, I guess it’s possible that a real type name would go over 128…
Are you definitely okay with just the type name without assembly information? If you need to be able to get the type using
Type.GetType(string)you will need assembly information unless it’s in the currently executing assembly or mscorlib. Obviously that adds a considerable length to the string involved…EDIT: As noted in your comment, if you use a constructed generic type, the names could get long very quickly. So whereas
typeof(List<>).FullNameis quite short,typeof(List<string>).FullNameis not.If you’re going to be storing constructed generic types, it’s probably worth giving a pretty large limit. Still, I’d hope that something like 4096 should be enough in most cases 🙂