Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update similar files, Share more files #835

Merged
merged 4 commits into from
Dec 22, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,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 @@ -237,6 +243,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 @@ -307,7 +316,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;
}
public FieldInfo FieldInfo { get; private set; }
public 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 @@ -197,10 +197,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 +250,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 @@ -172,12 +172,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 @@ -331,8 +340,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 All @@ -355,18 +362,26 @@
<Compile Include="Microsoft\Data\SqlClient\SqlColumnEncryptionCngProvider.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlColumnEncryptionCspProvider.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlColumnEncryptionEnclaveProvider.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlCommand.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlCommandBuilder.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlCommand.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Microsoft\Data\SqlClient\SqlCommandBuilder.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Microsoft\Data\SqlClient\SqlCommandSet.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlConnection.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlConnection.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Microsoft\Data\SqlClient\SqlConnectionFactory.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlConnectionPoolGroupProviderInfo.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlConnectionPoolKey.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlConnectionString.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlConnectionStringBuilder.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlConnectionTimeoutErrorInternal.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlCredential.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlDataAdapter.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlDataAdapter.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Microsoft\Data\SqlClient\SqlDataReader.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlDataReaderSmi.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlDelegatedTransaction.cs" />
Expand Down Expand Up @@ -432,7 +447,9 @@
<Compile Include="Microsoft\Data\ProviderBase\DbBuffer.cs" />
<Compile Include="Microsoft\Data\ProviderBase\DbConnectionClosed.cs" />
<Compile Include="Microsoft\Data\ProviderBase\DbConnectionFactory.cs" />
<Compile Include="Microsoft\Data\ProviderBase\SqlConnectionHelper.cs" />
<Compile Include="Microsoft\Data\ProviderBase\SqlConnectionHelper.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Microsoft\Data\ProviderBase\DbConnectionInternal.cs" />
<Compile Include="Microsoft\Data\ProviderBase\DbConnectionPool.cs" />
<Compile Include="Microsoft\Data\ProviderBase\DbConnectionPoolGroup.cs" />
Expand Down Expand Up @@ -461,7 +478,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 Expand Up @@ -535,4 +551,4 @@
<Import Project="$(NetFxSource)tools\targets\GenerateThisAssemblyCs.targets" />
<Import Project="$(NetFxSource)tools\targets\GenerateAssemblyRef.targets" />
<Import Project="$(NetFxSource)tools\targets\GenerateAssemblyInfo.targets" />
</Project>
</Project>
Loading