Skip to content

Commit

Permalink
Update similar files, Share more files (#835)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wraith2 authored Dec 22, 2020
1 parent a9c21bb commit d02bf4b
Show file tree
Hide file tree
Showing 13 changed files with 1,061 additions and 3,521 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,18 @@
<Compile Include="..\..\src\Microsoft\Data\SqlClient\Server\SqlFunctionAttribute.cs">
<Link>Microsoft\Data\SqlClient\Server\SqlFunctionAttribute.cs</Link>
</Compile>
<Compile Include="..\..\src\Microsoft\Data\SqlClient\Server\SqlMetaData.cs">
<Link>Microsoft\Data\SqlClient\Server\SqlMetaData.cs</Link>
</Compile>
<Compile Include="..\..\src\Microsoft\Data\SqlClient\Server\SqlMethodAttribute.cs">
<Link>Microsoft\Data\SqlClient\Server\SqlMethodAttribute.cs</Link>
</Compile>
<Compile Include="..\..\src\Microsoft\Data\SqlClient\Server\SqlUserDefinedTypeAttribute.cs">
<Link>Microsoft\Data\SqlClient\Server\SqlUserDefinedTypeAttribute.cs</Link>
</Compile>
<Compile Include="..\..\src\Microsoft\Data\SqlClient\Server\SqlUserDefinedAggregateAttribute.cs">
<Link>Microsoft\Data\SqlClient\Server\SqlUserDefinedAggregateAttribute.cs</Link>
</Compile>
<Compile Include="..\..\src\Microsoft\Data\SqlClient\ColumnEncryptionKeyInfo.cs">
<Link>Microsoft\Data\SqlClient\ColumnEncryptionKeyInfo.cs</Link>
</Compile>
Expand Down Expand Up @@ -243,6 +249,9 @@
<Compile Include="..\..\src\Microsoft\Data\SqlClient\Server\InvalidUdtException.cs">
<Link>Microsoft\Data\SqlClient\Server\InvalidUdtException.cs</Link>
</Compile>
<Compile Include="..\..\src\Microsoft\Data\SqlClient\Server\SqlRecordBuffer.cs">
<Link>Microsoft\Data\SqlClient\Server\SqlRecordBuffer.cs</Link>
</Compile>
<Compile Include="..\..\src\Microsoft\Data\SqlClient\SignatureVerificationCache.cs">
<Link>Microsoft\Data\SqlClient\SignatureVerificationCache.cs</Link>
</Compile>
Expand Down Expand Up @@ -313,7 +322,6 @@
<Compile Include="Microsoft\Data\SqlClient\Server\SmiTypedGetterSetter.cs" />
<Compile Include="Microsoft\Data\SqlClient\Server\SmiXetterAccessMap.cs" />
<Compile Include="Microsoft\Data\SqlClient\Server\SqlDataRecord.cs" />
<Compile Include="Microsoft\Data\SqlClient\Server\SqlRecordBuffer.cs" />
<Compile Include="Microsoft\Data\SqlClient\Server\ValueUtilsSmi.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlDbColumn.cs" />
<Compile Include="$(CommonPath)\Microsoft\Data\Common\AdapterUtil.cs">
Expand Down Expand Up @@ -364,10 +372,8 @@
<Compile Include="Microsoft\Data\ProviderBase\DbConnectionPool.cs" />
<Compile Include="Microsoft\Data\ProviderBase\DbConnectionPoolIdentity.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlAuthenticationProviderManager.cs" />
<Compile Include="Microsoft\Data\SqlClient\Server\SqlMetaData.cs" />
<Compile Include="Microsoft\Data\SqlClient\Server\SqlNorm.cs" />
<Compile Include="Microsoft\Data\SqlClient\Server\SqlSer.cs" />
<Compile Include="Microsoft\Data\SqlClient\Server\SqlUserDefinedAggregateAttribute.cs" />
<Compile Include="Microsoft\Data\SqlClient\LocalDBAPI.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlBuffer.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlBulkCopy.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,34 @@ namespace Microsoft.Data.SqlClient.Server
// a particular field.
internal sealed class FieldInfoEx : IComparable
{
internal readonly int Offset;
internal readonly FieldInfo FieldInfo;
internal readonly Normalizer Normalizer;
private readonly int _offset;

internal FieldInfoEx(FieldInfo fi, int offset, Normalizer normalizer)
{
FieldInfo = fi;
Offset = offset;
Debug.Assert(normalizer != null, "normalizer argument should not be null!");
Normalizer = normalizer;
FieldInfo = fi;
_offset = offset;
}
internal FieldInfo FieldInfo { get; private set; }
internal Normalizer Normalizer { get; private set; }

// Sort fields by field offsets.
public int CompareTo(object other)
{
FieldInfoEx otherF = other as FieldInfoEx;
if (otherF == null)
{
return -1;
return Offset.CompareTo(otherF.Offset);
}
return _offset.CompareTo(otherF._offset);
}
}

// The most complex normalizer, a udt normalizer
internal sealed class BinaryOrderedUdtNormalizer : Normalizer
{
internal readonly FieldInfoEx[] FieldsToNormalize;
private readonly FieldInfoEx[] _fieldsToNormalize;
private int _size;
private byte[] _padBuffer;
internal readonly object NullInstance;
Expand Down Expand Up @@ -69,18 +71,18 @@ internal BinaryOrderedUdtNormalizer(Type t, bool isTopLevelUdt)
// get all the fields
FieldInfo[] fields = GetFields(t);

FieldsToNormalize = new FieldInfoEx[fields.Length];
_fieldsToNormalize = new FieldInfoEx[fields.Length];

int i = 0;

foreach (FieldInfo fi in fields)
{
int offset = Marshal.OffsetOf(fi.DeclaringType, fi.Name).ToInt32();
FieldsToNormalize[i++] = new FieldInfoEx(fi, offset, GetNormalizer(fi.FieldType));
_fieldsToNormalize[i++] = new FieldInfoEx(fi, offset, GetNormalizer(fi.FieldType));
}

//sort by offset
Array.Sort(FieldsToNormalize);
Array.Sort(_fieldsToNormalize);
//if this is not a top-level udt, do setup for null values.
//null values need to compare less than all other values,
//so prefix a null byte indicator.
Expand Down Expand Up @@ -138,8 +140,10 @@ private object DeNormalizeInternal(Type t, Stream s)
}
}
if (result == null)
{
result = Activator.CreateInstance(t);
foreach (FieldInfoEx myField in FieldsToNormalize)
}
foreach (FieldInfoEx myField in _fieldsToNormalize)
{
myField.Normalizer.DeNormalize(myField.FieldInfo, result, s);
}
Expand Down Expand Up @@ -173,7 +177,7 @@ internal override void Normalize(FieldInfo fi, object obj, Stream s)
}
}

foreach (FieldInfoEx myField in FieldsToNormalize)
foreach (FieldInfoEx myField in _fieldsToNormalize)
{
myField.Normalizer.Normalize(myField.FieldInfo, inner, s);
}
Expand All @@ -189,10 +193,14 @@ internal override int Size
get
{
if (_size != 0)
{
return _size;
}
if (IsNullable && !_isTopLevelUdt)
{
_size = 1;
foreach (FieldInfoEx myField in FieldsToNormalize)
}
foreach (FieldInfoEx myField in _fieldsToNormalize)
{
_size += myField.Normalizer.Size;
}
Expand Down Expand Up @@ -238,7 +246,9 @@ internal static Normalizer GetNormalizer(Type t)
n = new BinaryOrderedUdtNormalizer(t, false);
}
if (n == null)
{
throw new Exception(StringsHelper.GetString(Strings.SQL_CannotCreateNormalizer, t.FullName));
}
n._skipNormalize = false;
return n;
}
Expand All @@ -250,15 +260,14 @@ internal static Normalizer GetNormalizer(Type t)
protected void FlipAllBits(byte[] b)
{
for (int i = 0; i < b.Length; i++)
{
b[i] = (byte)~b[i];
}
}

protected object GetValue(FieldInfo fi, object obj) => fi.GetValue(obj);

protected void SetValue(FieldInfo fi, object recvr, object value)
{
fi.SetValue(recvr, value);
}
protected void SetValue(FieldInfo fi, object recvr, object value) => fi.SetValue(recvr, value);

internal abstract int Size { get; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,12 @@ private static Serializer GetNewSerializer(Type t)
// The base serializer class.
internal abstract class Serializer
{
protected Type _type;

public abstract object Deserialize(Stream s);
public abstract void Serialize(Stream s, object o);
protected Type _type;

protected Serializer(Type t)
{
_type = t;
}
protected Serializer(Type t) => _type = t;
}

internal sealed class NormalizedSerializer : Serializer
Expand All @@ -197,10 +195,7 @@ internal NormalizedSerializer(Type t) : base(t)
_maxSize = _normalizer.Size;
}

public override void Serialize(Stream s, object o)
{
_normalizer.NormalizeTopObject(o, s);
}
public override void Serialize(Stream s, object o) => _normalizer.NormalizeTopObject(o, s);

public override object Deserialize(Stream s) => _normalizer.DeNormalizeTopObject(_type, s);
}
Expand Down Expand Up @@ -253,22 +248,13 @@ private void DontDoIt()

public override long Position
{
get
{
return _size;
}
set
{
_size = value;
}
get => _size;
set => _size = value;
}

public override long Length => _size;

public override void SetLength(long value)
{
_size = value;
}
public override void SetLength(long value) => _size = value;

public override long Seek(long value, SeekOrigin loc)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2729,7 +2729,6 @@ private static void SetUdt_LengthChecked(SmiEventSink_Default sink, ITypedSetter
}
}


//
// Semantics support routines
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,21 @@
<Compile Include="..\..\src\Microsoft\Data\SqlClient\Server\SqlFunctionAttribute.cs">
<Link>Microsoft\Data\SqlClient\Server\SqlFunctionAttribute.cs</Link>
</Compile>
<Compile Include="..\..\src\Microsoft\Data\SqlClient\Server\SqlMetaData.cs">
<Link>Microsoft\Data\SqlClient\Server\SqlMetaData.cs</Link>
</Compile>
<Compile Include="..\..\src\Microsoft\Data\SqlClient\Server\SqlMethodAttribute.cs">
<Link>Microsoft\Data\SqlClient\Server\SqlMethodAttribute.cs</Link>
</Compile>
<Compile Include="..\..\src\Microsoft\Data\SqlClient\Server\SqlUserDefinedTypeAttribute.cs">
<Link>Microsoft\Data\SqlClient\Server\SqlUserDefinedTypeAttribute.cs</Link>
</Compile>
<Compile Include="..\..\src\Microsoft\Data\SqlClient\Server\SqlUserDefinedAggregateAttribute.cs">
<Link>Microsoft\Data\SqlClient\Server\SqlUserDefinedAggregateAttribute.cs</Link>
</Compile>
<Compile Include="..\..\src\Microsoft\Data\SqlClient\Server\SqlRecordBuffer.cs">
<Link>Microsoft\Data\SqlClient\Server\SqlRecordBuffer.cs</Link>
</Compile>
<Compile Include="..\..\src\Microsoft\Data\SqlClient\ColumnEncryptionKeyInfo.cs">
<Link>Microsoft\Data\SqlClient\ColumnEncryptionKeyInfo.cs</Link>
</Compile>
Expand Down Expand Up @@ -337,8 +346,6 @@
<Compile Include="Microsoft\Data\SqlClient\LocalDBConfig.cs" />
<Compile Include="Microsoft\Data\SqlClient\AssemblyRef.cs" />
<Compile Include="Microsoft\Data\SqlClient\Server\SqlDataRecord.cs" />
<Compile Include="Microsoft\Data\SqlClient\Server\SqlMetaData.cs" />
<Compile Include="Microsoft\Data\SqlClient\Server\SqlUserDefinedAggregateAttribute.cs" />
<Compile Include="Microsoft\Data\SqlClient\Server\TriggerAction.cs" />
<Compile Include="Microsoft\Data\SqlClient\VirtualSecureModeEnclaveProvider.cs" />
<Compile Include="Microsoft\Data\SqlClient\VirtualSecureModeEnclaveProviderBase.cs" />
Expand Down Expand Up @@ -465,7 +472,6 @@
<Compile Include="Microsoft\Data\SqlClient\Server\SmiStream.cs" />
<Compile Include="Microsoft\Data\SqlClient\Server\SmiTypedGetterSetter.cs" />
<Compile Include="Microsoft\Data\SqlClient\Server\SmiXetterAccessMap.cs" />
<Compile Include="Microsoft\Data\SqlClient\Server\SqlRecordBuffer.cs" />
<Compile Include="Microsoft\Data\SqlClient\Server\ValueUtilsSmi.cs" />
<Compile Include="Microsoft\Data\SqlClient\Server\sqlser.cs" />
<Compile Include="Microsoft\Data\Sql\SqlGenericUtil.cs" />
Expand Down
Loading

0 comments on commit d02bf4b

Please sign in to comment.