You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#region Work around inability to access SqlMoney.ctor(long, int) and SqlMoney.ToSqlInternalRepresentation
23
-
privatestaticreadonlyFunc<long,SqlMoney>s_sqlMoneyfactory=CtorHelper.CreateFactory<SqlMoney,long,int>();// binds to SqlMoney..ctor(long, int) if it exists
// If an exception occurs for any reason, swallow & use the fallback code path.
137
-
}
138
-
139
-
returndecomposer??FallbackDecomposer;
140
-
}
141
-
142
-
privatestaticDecomposerGetFastDecomposer()
143
-
{
144
-
// This takes advantage of the fact that for [Serializable] types, the member fields are implicitly
145
-
// part of the type's serialization contract. This includes the fields' names and types. By default,
146
-
// [Serializable]-compliant serializers will read all the member fields and shove the data into a
147
-
// SerializationInfo dictionary. We mimic this behavior in a manner consistent with the [Serializable]
148
-
// pattern, but much more efficiently.
149
-
//
150
-
// In order to make sure we're staying compliant, we need to gate our checks to fulfill some core
151
-
// assumptions. Importantly, the type must be [Serializable] but cannot be ISerializable, as the
152
-
// presence of the interface means that the type wants to be responsible for its own serialization,
153
-
// and that member fields are not guaranteed to be part of the serialization contract. Additionally,
154
-
// we need to check for [OnSerializing] and [OnDeserializing] methods, because we cannot account
155
-
// for any logic which might be present within them.
156
-
157
-
if(!typeof(SqlDecimal).IsSerializable)
158
-
{
159
-
SqlClientEventSource.Log.TryTraceEvent("SqlTypeWorkarounds.SqlDecimalHelper.GetFastDecomposer | Info | SqlDecimal isn't Serializable. Less efficient fallback method will be used.");
160
-
returnnull;// type is not serializable - cannot use fast path assumptions
SqlClientEventSource.Log.TryTraceEvent("SqlTypeWorkarounds.SqlDecimalHelper.GetFastDecomposer | Info | SqlDecimal is ISerializable. Less efficient fallback method will be used.");
166
-
returnnull;// type contains custom logic - cannot use fast path assumptions
SqlClientEventSource.Log.TryTraceEvent("SqlTypeWorkarounds.SqlDecimalHelper.GetFastDecomposer | Info | SqlDecimal contains custom serialization logic. Less efficient fallback method will be used.");
174
-
returnnull;// type contains custom logic - cannot use fast path assumptions
175
-
}
176
-
}
177
-
178
-
// GetSerializableMembers filters out [NonSerialized] fields for us automatically.
SqlClientEventSource.Log.TryTraceEvent("SqlTypeWorkarounds.SqlDecimalHelper.GetFastDecomposer | Info | Expected SqlDecimal fields are missing. Less efficient fallback method will be used.");
199
-
returnnull;// missing one of the expected member fields - cannot use fast path assumptions
data4=(uint)data[3];// write in reverse to avoid multiple bounds checks
245
-
data3=(uint)data[2];
246
-
data2=(uint)data[1];
247
-
data1=(uint)data[0];
248
-
}
249
-
}
144
+
// Note: Although it would be faster to use the m_data[1-4] member variables in
145
+
// SqlDecimal, we cannot use them because they are not documented. The Data property
146
+
// is less ideal, but is documented.
147
+
int[]data=value.Data;
148
+
data1=(uint)data[0];
149
+
data2=(uint)data[1];
150
+
data3=(uint)data[2];
151
+
data4=(uint)data[3];
250
152
}
153
+
251
154
#endregion
252
155
253
156
#region Work around inability to access SqlBinary.ctor(byte[], bool)
254
-
privatestaticreadonlyFunc<byte[],SqlBinary>s_sqlBinaryfactory=CtorHelper.CreateFactory<SqlBinary,byte[],bool>();// binds to SqlBinary..ctor(byte[], bool) if it exists
#region Work around inability to access SqlGuid.ctor(byte[], bool)
273
-
privatestaticreadonlyFunc<byte[],SqlGuid>s_sqlGuidfactory=CtorHelper.CreateFactory<SqlGuid,byte[],bool>();// binds to SqlGuid..ctor(byte[], bool) if it exists
0 commit comments