private ResourceTypeCode FindTypeCode(object value, List<string> types)
{
if (value == null)
return ResourceTypeCode.Null;
Type type = value.GetType();
if (type == typeof(string))
return ResourceTypeCode.String;
else if (type == typeof(int))
return ResourceTypeCode.Int32;
else if (type == typeof(bool))
return ResourceTypeCode.Boolean;
else if (type == typeof(char))
return ResourceTypeCode.Char;
else if (type == typeof(byte))
return ResourceTypeCode.Byte;
else if (type == typeof(sbyte))
return ResourceTypeCode.SByte;
else if (type == typeof(short))
return ResourceTypeCode.Int16;
else if (type == typeof(long))
return ResourceTypeCode.Int64;
else if (type == typeof(ushort))
return ResourceTypeCode.UInt16;
else if (type == typeof(uint))
return ResourceTypeCode.UInt32;
else if (type == typeof(ulong))
return ResourceTypeCode.UInt64;
else if (type == typeof(float))
return ResourceTypeCode.Single;
else if (type == typeof(double))
return ResourceTypeCode.Double;
else if (type == typeof(decimal))
return ResourceTypeCode.Decimal;
else if (type == typeof(DateTime))
return ResourceTypeCode.DateTime;
else if (type == typeof(TimeSpan))
return ResourceTypeCode.TimeSpan;
else if (type == typeof(byte[]))
return ResourceTypeCode.ByteArray;
else if (type == typeof(StreamWrapper))
return ResourceTypeCode.Stream;
// This is a user type, or a precanned resource. Find type
// table index. If not there, add new element.
string typeName;
if (type == typeof(PrecannedResource)) {
typeName = ((PrecannedResource)value).TypeName;
if (typeName.StartsWith("ResourceTypeCode.", StringComparison.Ordinal)) {
typeName = typeName.Substring(17); // Remove through '.'
ResourceTypeCode typeCode = (ResourceTypeCode)Enum.Parse(typeof(ResourceTypeCode), typeName);
return typeCode;
}
}
else
{
typeName = MultitargetingHelpers.GetAssemblyQualifiedName(type, TypeNameConverter);
}
int typeIndex = types.IndexOf(typeName);
if (typeIndex == -1) {
typeIndex = types.Count;
types.Add(typeName);
}
return (ResourceTypeCode)(typeIndex + ResourceTypeCode.StartOfUserTypes);
}