internal NormalizedSerializer(Type t) : base(t) { SqlUserDefinedTypeAttribute udtAttr = SerializationHelperSql9.GetUdtAttribute(t); _normalizer = new BinaryOrderedUdtNormalizer(t, true); _isFixedSize = udtAttr.IsFixedLength; _maxSize = _normalizer.Size; }
private static object[] GetCustomAttributes(Type t) { object[] attrs = t.GetCustomAttributes(typeof(SqlUserDefinedTypeAttribute), false); // If we don't find a Microsoft.Data.SqlClient.Server.SqlUserDefinedTypeAttribute, // search for a Microsoft.SqlServer.Server.SqlUserDefinedTypeAttribute from the // old System.Data.SqlClient assembly and copy it to our // Microsoft.Data.SqlClient.Server.SqlUserDefinedTypeAttribute for reference. if (attrs == null || attrs.Length == 0) { object[] attr = t.GetCustomAttributes(false); attrs = new object[0]; if (attr != null && attr.Length > 0) { for (int i = 0; i < attr.Length; i++) { if (attr[i].GetType().FullName.Equals("Microsoft.SqlServer.Server.SqlUserDefinedTypeAttribute")) { SqlUserDefinedTypeAttribute newAttr = null; PropertyInfo[] sourceProps = attr[i].GetType().GetProperties(); foreach (PropertyInfo sourceProp in sourceProps) { if (sourceProp.Name.Equals("Format")) { newAttr = new SqlUserDefinedTypeAttribute((Format)sourceProp.GetValue(attr[i], null)); break; } } if (newAttr != null) { foreach (PropertyInfo targetProp in newAttr.GetType().GetProperties()) { if (targetProp.CanRead && targetProp.CanWrite) { object copyValue = attr[i].GetType().GetProperty(targetProp.Name).GetValue(attr[i]); targetProp.SetValue(newAttr, copyValue); } } } attrs = new object[1] { newAttr }; break; } } } } return(attrs); }
internal static SqlUserDefinedTypeAttribute GetUdtAttribute(Type t) { SqlUserDefinedTypeAttribute udtAttr = null; object[] attr = GetCustomAttributes(t); if (attr != null && attr.Length == 1) { udtAttr = (SqlUserDefinedTypeAttribute)attr[0]; } else { throw InvalidUdtException.Create(t, Strings.SqlUdtReason_NoUdtAttribute); } return(udtAttr); }
// Create a new serializer for the given type. private static Serializer GetNewSerializer(Type t) { SqlUserDefinedTypeAttribute udtAttr = GetUdtAttribute(t); switch (udtAttr.Format) { case Format.Native: return(new NormalizedSerializer(t)); case Format.UserDefined: return(new BinarySerializeSerializer(t)); case Format.Unknown: // should never happen, but fall through default: throw ADP.InvalidUserDefinedTypeSerializationFormat(udtAttr.Format); } }
internal static SqlUserDefinedTypeAttribute GetUdtAttribute(Type t) { SqlUserDefinedTypeAttribute udtAttr = null; object[] attr = GetCustomAttributes(t); if (attr != null && attr.Length == 1) { udtAttr = (SqlUserDefinedTypeAttribute)attr[0]; } else { Type InvalidUdtExceptionType = typeof(InvalidUdtException); var arguments = new Type[] { typeof(Type), typeof(String) }; MethodInfo Create = InvalidUdtExceptionType.GetMethod("Create", arguments); Create.Invoke(null, new object[] { t, Strings.SqlUdtReason_NoUdtAttribute }); } return(udtAttr); }