未验证 提交 072e8761 编写于 作者: A Andrii Kurdiumov 提交者: GitHub

Improve System.Speech trimmability (#61566)

by removing obvious warnings
上级 f9d05bd2
......@@ -14,10 +14,10 @@ internal static class AudioFormatConverter
internal static SpeechAudioFormatInfo ToSpeechAudioFormatInfo(IntPtr waveFormatPtr)
{
WaveFormatEx waveFormatEx = (WaveFormatEx)Marshal.PtrToStructure(waveFormatPtr, typeof(WaveFormatEx));
WaveFormatEx waveFormatEx = Marshal.PtrToStructure<WaveFormatEx>(waveFormatPtr);
byte[] extraData = new byte[waveFormatEx.cbSize];
IntPtr extraDataPtr = new(waveFormatPtr.ToInt64() + Marshal.SizeOf(waveFormatEx));
IntPtr extraDataPtr = new(waveFormatPtr.ToInt64() + Marshal.SizeOf<WaveFormatEx>());
for (int i = 0; i < waveFormatEx.cbSize; i++)
{
extraData[i] = Marshal.ReadByte(extraDataPtr, i);
......
......@@ -450,7 +450,7 @@ internal static ISpPhrase CreatePhraseFromWordUnits(RecognizedWordUnit[] words,
SPPHRASEELEMENT[] elements = new SPPHRASEELEMENT[words.Length];
// build the unmanaged interop layer
int size = Marshal.SizeOf(typeof(SPPHRASEELEMENT));
int size = Marshal.SizeOf<SPPHRASEELEMENT>();
List<GCHandle> handles = new();
coMem = Marshal.AllocCoTaskMem(size * elements.Length);
......@@ -496,7 +496,7 @@ internal static ISpPhrase CreatePhraseFromWordUnits(RecognizedWordUnit[] words,
elements[i].pszPronunciation = handle.AddrOfPinnedObject();
}
Marshal.StructureToPtr(elements[i], new IntPtr((long)coMem + size * i), false);
Marshal.StructureToPtr<SPPHRASEELEMENT>(elements[i], new IntPtr((long)coMem + size * i), false);
}
}
finally
......@@ -505,7 +505,7 @@ internal static ISpPhrase CreatePhraseFromWordUnits(RecognizedWordUnit[] words,
}
SPPHRASE spPhrase = new();
spPhrase.cbSize = (uint)Marshal.SizeOf(spPhrase.GetType());
spPhrase.cbSize = (uint)Marshal.SizeOf<SPPHRASE>();
spPhrase.LangID = (ushort)culture.LCID;
spPhrase.Rule = new SPPHRASERULE
{
......
......@@ -26,7 +26,7 @@ internal class SpeechEvent : IDisposable
// Let the GC know if we have a unmanaged object with a given size
if (_paramType == SPEVENTLPARAMTYPE.SPET_LPARAM_IS_POINTER || _paramType == SPEVENTLPARAMTYPE.SPET_LPARAM_IS_STRING)
{
GC.AddMemoryPressure(_sizeMemoryPressure = Marshal.SizeOf(_lParam));
GC.AddMemoryPressure(_sizeMemoryPressure = sizeof(ulong));
}
}
......
......@@ -1005,7 +1005,7 @@ private CfgGrammar.CfgSerializedHeader BuildHeader(List<State> sortedStates, int
}
CfgGrammar.CfgSerializedHeader header = new();
uint ulOffset = (uint)Marshal.SizeOf(typeof(CfgGrammar.CfgSerializedHeader));
uint ulOffset = (uint)Marshal.SizeOf<CfgGrammar.CfgSerializedHeader>();
header.FormatId = CfgGrammar._SPGDF_ContextFree;
_guid = Guid.NewGuid();
......@@ -1032,16 +1032,16 @@ private CfgGrammar.CfgSerializedHeader BuildHeader(List<State> sortedStates, int
ulOffset += (uint)_symbols.SerializeSize() * Helpers._sizeOfChar;
header.cRules = _rules.Count;
header.pRules = ulOffset;
ulOffset += (uint)(_rules.Count * Marshal.SizeOf(typeof(CfgRule)));
ulOffset += (uint)(_rules.Count * Marshal.SizeOf<CfgRule>());
header.cBasePath = cBasePath > 0 ? ulOffset : 0; //If there is no base path offset is set to zero
ulOffset += (uint)((cBasePath * Helpers._sizeOfChar + 3) & ~3);
header.cArcs = cArcs;
header.pArcs = ulOffset;
ulOffset += (uint)(cArcs * Marshal.SizeOf(typeof(CfgArc)));
ulOffset += (uint)(cArcs * Marshal.SizeOf<CfgArc>());
if (_fNeedWeightTable)
{
header.pWeights = ulOffset;
ulOffset += (uint)(cArcs * Marshal.SizeOf(typeof(float)));
ulOffset += (uint)(cArcs * sizeof(float));
pWeights = new float[cArcs];
pWeights[0] = 0.0f;
}
......@@ -1067,16 +1067,16 @@ private CfgGrammar.CfgSerializedHeader BuildHeader(List<State> sortedStates, int
header.GrammarMode = (uint)_grammarMode;
header.cTags = cSemanticTags;
header.tags = ulOffset;
ulOffset += (uint)(cSemanticTags * Marshal.SizeOf(typeof(CfgSemanticTag)));
ulOffset += (uint)(cSemanticTags * Marshal.SizeOf<CfgSemanticTag>());
header.cScripts = _scriptRefs.Count;
header.pScripts = header.cScripts > 0 ? ulOffset : 0;
ulOffset += (uint)(_scriptRefs.Count * Marshal.SizeOf(typeof(CfgScriptRef)));
ulOffset += (uint)(_scriptRefs.Count * Marshal.SizeOf<CfgScriptRef>());
header.cIL = 0;
header.pIL = 0;
ulOffset += (uint)(header.cIL * Marshal.SizeOf(typeof(byte)));
ulOffset += (uint)(header.cIL * sizeof(byte));
header.cPDB = 0;
header.pPDB = 0;
ulOffset += (uint)(header.cPDB * Marshal.SizeOf(typeof(byte)));
ulOffset += (uint)(header.cPDB * sizeof(byte));
header.ulTotalSerializedSize = ulOffset;
return header;
}
......
......@@ -272,7 +272,7 @@ internal static CfgHeader ConvertCfgHeader(StreamMarshaler streamHelper, bool in
}
//We know that in SAPI 5.0 grammar format pszWords follows header immediately.
if (cfgSerializedHeader.pszWords < Marshal.SizeOf(typeof(CfgSerializedHeader)))
if (cfgSerializedHeader.pszWords < Marshal.SizeOf<CfgSerializedHeader>())
{
//This is SAPI 5.0 and SAPI 5.1 grammar format
header.ulRootRuleIndex = 0xFFFFFFFF;
......@@ -294,7 +294,7 @@ internal static CfgHeader ConvertCfgHeader(StreamMarshaler streamHelper, bool in
// Get the chars and build the string
if (cfgSerializedHeader.cBasePath > 0)
{
streamHelper.Stream.Position = (int)cfgSerializedHeader.pRules + (header.rules.Length * Marshal.SizeOf(typeof(CfgRule)));
streamHelper.Stream.Position = (int)cfgSerializedHeader.pRules + (header.rules.Length * Marshal.SizeOf<CfgRule>());
header.BasePath = streamHelper.ReadNullTerminatedString();
}
}
......@@ -319,7 +319,7 @@ internal static ScriptRef[] LoadScriptRefs(StreamMarshaler streamHelper, CfgSeri
}
//We know that in SAPI 5.0 grammar format pszWords follows header immediately.
if (pFH.pszWords < Marshal.SizeOf(typeof(CfgSerializedHeader)))
if (pFH.pszWords < Marshal.SizeOf<CfgSerializedHeader>())
{
// Must be SAPI 6.0 or above to hold a .NET script
return null;
......@@ -412,25 +412,25 @@ private static void CheckValidCfgFormat(CfgSerializedHeader pFH, CfgHeader heade
//Check the rule offset
if (pFH.cRules > 0)
{
CheckSetOffsets(pFH.pRules, pFH.cRules * Marshal.SizeOf(typeof(CfgRule)), ref ullStartOffset, pFH.ulTotalSerializedSize);
CheckSetOffsets(pFH.pRules, pFH.cRules * Marshal.SizeOf<CfgRule>(), ref ullStartOffset, pFH.ulTotalSerializedSize);
}
//Check the arc offset
if (pFH.cArcs > 0)
{
CheckSetOffsets(pFH.pArcs, pFH.cArcs * Marshal.SizeOf(typeof(CfgArc)), ref ullStartOffset, pFH.ulTotalSerializedSize);
CheckSetOffsets(pFH.pArcs, pFH.cArcs * Marshal.SizeOf<CfgArc>(), ref ullStartOffset, pFH.ulTotalSerializedSize);
}
//Check the weight offset
if (pFH.pWeights > 0)
{
CheckSetOffsets(pFH.pWeights, pFH.cArcs * Marshal.SizeOf(typeof(float)), ref ullStartOffset, pFH.ulTotalSerializedSize);
CheckSetOffsets(pFH.pWeights, pFH.cArcs * sizeof(float), ref ullStartOffset, pFH.ulTotalSerializedSize);
}
//Check the semantic tag offset
if (pFH.cTags > 0)
{
CheckSetOffsets(pFH.tags, pFH.cTags * Marshal.SizeOf(typeof(CfgSemanticTag)), ref ullStartOffset, pFH.ulTotalSerializedSize);
CheckSetOffsets(pFH.tags, pFH.cTags * Marshal.SizeOf<CfgSemanticTag>(), ref ullStartOffset, pFH.ulTotalSerializedSize);
if (includeAllGrammarData)
{
......@@ -465,17 +465,17 @@ private static void CheckValidCfgFormat(CfgSerializedHeader pFH, CfgHeader heade
//Check the offset for the scripts
if (pFH.cScripts > 0)
{
CheckSetOffsets(pFH.pScripts, pFH.cScripts * Marshal.SizeOf(typeof(CfgScriptRef)), ref ullStartOffset, pFH.ulTotalSerializedSize);
CheckSetOffsets(pFH.pScripts, pFH.cScripts * Marshal.SizeOf<CfgScriptRef>(), ref ullStartOffset, pFH.ulTotalSerializedSize);
}
if (pFH.cIL > 0)
{
CheckSetOffsets(pFH.pIL, pFH.cIL * Marshal.SizeOf(typeof(byte)), ref ullStartOffset, pFH.ulTotalSerializedSize);
CheckSetOffsets(pFH.pIL, pFH.cIL * sizeof(byte), ref ullStartOffset, pFH.ulTotalSerializedSize);
}
if (pFH.cPDB > 0)
{
CheckSetOffsets(pFH.pPDB, pFH.cPDB * Marshal.SizeOf(typeof(byte)), ref ullStartOffset, pFH.ulTotalSerializedSize);
CheckSetOffsets(pFH.pPDB, pFH.cPDB * sizeof(byte), ref ullStartOffset, pFH.ulTotalSerializedSize);
}
}
......
......@@ -30,8 +30,7 @@ public void Dispose()
#region internal Methods
internal void ReadArray<T>(T[] ao, int c)
{
Type type = typeof(T);
int sizeOfOne = Marshal.SizeOf(type);
int sizeOfOne = Marshal.SizeOf<T>();
int sizeObject = sizeOfOne * c;
byte[] ab = Helpers.ReadStreamToByteArray(_stream, sizeObject);
......@@ -40,21 +39,20 @@ internal void ReadArray<T>(T[] ao, int c)
Marshal.Copy(ab, 0, buffer, sizeObject);
for (int i = 0; i < c; i++)
{
ao[i] = (T)Marshal.PtrToStructure((IntPtr)((long)buffer + i * sizeOfOne), type);
ao[i] = Marshal.PtrToStructure<T>((IntPtr)((long)buffer + i * sizeOfOne));
}
}
internal void WriteArray<T>(T[] ao, int c)
{
Type type = typeof(T);
int sizeOfOne = Marshal.SizeOf(type);
int sizeOfOne = Marshal.SizeOf<T>();
int sizeObject = sizeOfOne * c;
byte[] ab = new byte[sizeObject];
IntPtr buffer = _safeHMem.Buffer(sizeObject);
for (int i = 0; i < c; i++)
{
Marshal.StructureToPtr(ao[i], (IntPtr)((long)buffer + i * sizeOfOne), false);
Marshal.StructureToPtr<T>(ao[i], (IntPtr)((long)buffer + i * sizeOfOne), false);
}
Marshal.Copy(buffer, ab, 0, sizeObject);
......@@ -116,24 +114,24 @@ internal void WriteArrayChar(char[] ach, int c)
}
}
internal void ReadStream(object o)
internal void ReadStream<T>(T o)
{
int sizeObject = Marshal.SizeOf(o.GetType());
int sizeObject = Marshal.SizeOf<T>();
byte[] ab = Helpers.ReadStreamToByteArray(_stream, sizeObject);
IntPtr buffer = _safeHMem.Buffer(sizeObject);
Marshal.Copy(ab, 0, buffer, sizeObject);
Marshal.PtrToStructure(buffer, o);
Marshal.PtrToStructure<T>(buffer, o);
}
internal void WriteStream(object o)
internal void WriteStream<T>(T o)
{
int sizeObject = Marshal.SizeOf(o.GetType());
int sizeObject = Marshal.SizeOf<T>();
byte[] ab = new byte[sizeObject];
IntPtr buffer = _safeHMem.Buffer(sizeObject);
Marshal.StructureToPtr(o, buffer, false);
Marshal.StructureToPtr<T>(o, buffer, false);
Marshal.Copy(buffer, ab, 0, sizeObject);
// Read the Header
......
......@@ -234,10 +234,10 @@ internal static void WriteWaveHeader(Stream stream, WAVEFORMATEX waveEx, long po
BLOCKHDR block = new(0);
DATAHDR dataHdr = new(0);
int cRiff = Marshal.SizeOf(riff);
int cBlock = Marshal.SizeOf(block);
int cRiff = Marshal.SizeOf<RIFFHDR>();
int cBlock = Marshal.SizeOf<BLOCKHDR>();
int cWaveEx = waveEx.Length;// Marshal.SizeOf (waveEx); // The CLR automatically pad the waveEx structure to dword boundary. Force 16.
int cDataHdr = Marshal.SizeOf(dataHdr);
int cDataHdr = Marshal.SizeOf<DATAHDR>();
int total = cRiff + cBlock + cWaveEx + cDataHdr;
......
......@@ -313,7 +313,7 @@ internal static MMSYSERR GetDeviceName(int deviceId, [MarshalAs(UnmanagedType.LP
prodName = string.Empty;
SafeNativeMethods.WAVEOUTCAPS caps = new();
MMSYSERR result = SafeNativeMethods.waveOutGetDevCaps((IntPtr)deviceId, ref caps, Marshal.SizeOf(caps));
MMSYSERR result = SafeNativeMethods.waveOutGetDevCaps((IntPtr)deviceId, ref caps, Marshal.SizeOf<SafeNativeMethods.WAVEOUTCAPS>());
if (result != MMSYSERR.NOERROR)
{
return result;
......
......@@ -86,7 +86,7 @@ internal int SizeHDR
{
get
{
return Marshal.SizeOf(_waveHdr);
return Marshal.SizeOf<WAVEHDR>();
}
}
......
......@@ -151,7 +151,7 @@ public RecognizedAudio Audio
{
IntPtr audioBuffer = gc.AddrOfPinnedObject();
SPWAVEFORMATEX audioHeader = (SPWAVEFORMATEX)Marshal.PtrToStructure(audioBuffer, typeof(SPWAVEFORMATEX));
SPWAVEFORMATEX audioHeader = Marshal.PtrToStructure<SPWAVEFORMATEX>(audioBuffer);
IntPtr rawDataBuffer = new((long)audioBuffer + audioHeader.cbUsed);
byte[] rawAudioData = new byte[audioLength - audioHeader.cbUsed];
......@@ -296,15 +296,15 @@ private void Initialize(IRecognizerInternal recognizer, ISpRecoResult recoResult
int headerSize = Marshal.ReadInt32(buffer, 4); // Read header size directly from buffer - 4 is the offset of cbHeaderSize.
if (headerSize == Marshal.SizeOf(typeof(SPRESULTHEADER_Sapi51))) // SAPI 5.1 size
if (headerSize == Marshal.SizeOf<SPRESULTHEADER_Sapi51>()) // SAPI 5.1 size
{
SPRESULTHEADER_Sapi51 legacyHeader = (SPRESULTHEADER_Sapi51)Marshal.PtrToStructure(buffer, typeof(SPRESULTHEADER_Sapi51));
SPRESULTHEADER_Sapi51 legacyHeader = Marshal.PtrToStructure<SPRESULTHEADER_Sapi51>(buffer);
_header = new SPRESULTHEADER(legacyHeader);
_isSapi53Header = false;
}
else
{
_header = (SPRESULTHEADER)Marshal.PtrToStructure(buffer, typeof(SPRESULTHEADER));
_header = Marshal.PtrToStructure<SPRESULTHEADER>(buffer);
_isSapi53Header = true;
}
......@@ -355,12 +355,12 @@ private Collection<RecognizedPhrase> ExtractAlternates(int numberOfAlternates, b
{
IntPtr buffer = gc.AddrOfPinnedObject();
int sizeOfSpSerializedPhraseAlt = Marshal.SizeOf(typeof(SPSERIALIZEDPHRASEALT));
int sizeOfSpSerializedPhraseAlt = Marshal.SizeOf<SPSERIALIZEDPHRASEALT>();
int offset = 0;
for (int i = 0; i < numberOfAlternates; i++)
{
IntPtr altBuffer = new((long)buffer + offset);
SPSERIALIZEDPHRASEALT alt = (SPSERIALIZEDPHRASEALT)Marshal.PtrToStructure(altBuffer, typeof(SPSERIALIZEDPHRASEALT));
SPSERIALIZEDPHRASEALT alt = Marshal.PtrToStructure<SPSERIALIZEDPHRASEALT>(altBuffer);
offset += sizeOfSpSerializedPhraseAlt; // advance over SPSERIALIZEDPHRASEALT
if (isSapi53Header)
......
......@@ -159,7 +159,7 @@ public ReadOnlyCollection<RecognizedWordUnit> Words
int elementsOffset = (int)_serializedPhrase.ElementsOffset;
List<RecognizedWordUnit> wordList = new(countOfElements);
int sizeofPhraseElement = Marshal.SizeOf(typeof(SPSERIALIZEDPHRASEELEMENT));
int sizeofPhraseElement = Marshal.SizeOf<SPSERIALIZEDPHRASEELEMENT>();
GCHandle gc = GCHandle.Alloc(_phraseBuffer, GCHandleType.Pinned);
try
......@@ -168,7 +168,7 @@ public ReadOnlyCollection<RecognizedWordUnit> Words
for (int i = 0; i < countOfElements; i++)
{
IntPtr elementBuffer = new((long)buffer + elementsOffset + i * sizeofPhraseElement);
SPSERIALIZEDPHRASEELEMENT element = (SPSERIALIZEDPHRASEELEMENT)Marshal.PtrToStructure(elementBuffer, typeof(SPSERIALIZEDPHRASEELEMENT));
SPSERIALIZEDPHRASEELEMENT element = Marshal.PtrToStructure<SPSERIALIZEDPHRASEELEMENT>(elementBuffer);
string displayForm = null, lexicalForm = null, pronunciation = null;
if (element.pszDisplayTextOffset != 0)
......@@ -292,9 +292,9 @@ public Collection<ReplacementText> ReplacementWordUnits
// Get the ITN and Look for replacement phrase/
IntPtr itnBuffer = new((long)buffer + _serializedPhrase.ReplacementsOffset);
for (int i = 0; i < _serializedPhrase.cReplacements; i++, itnBuffer = (IntPtr)((long)itnBuffer + Marshal.SizeOf(typeof(SPPHRASEREPLACEMENT))))
for (int i = 0; i < _serializedPhrase.cReplacements; i++, itnBuffer = (IntPtr)((long)itnBuffer + Marshal.SizeOf<SPPHRASEREPLACEMENT>()))
{
SPPHRASEREPLACEMENT replacement = (SPPHRASEREPLACEMENT)Marshal.PtrToStructure(itnBuffer, typeof(SPPHRASEREPLACEMENT));
SPPHRASEREPLACEMENT replacement = (SPPHRASEREPLACEMENT)Marshal.PtrToStructure<SPPHRASEREPLACEMENT>(itnBuffer);
string text = Marshal.PtrToStringUni(new IntPtr((long)buffer + replacement.pszReplacementText));
DisplayAttributes displayAttributes = RecognizedWordUnit.SapiAttributesToDisplayAttributes(replacement.bDisplayAttributes);
_replacementText.Add(new ReplacementText(displayAttributes, text, (int)replacement.ulFirstElement, (int)replacement.ulCountOfElements));
......@@ -325,11 +325,11 @@ internal static SPSERIALIZEDPHRASE GetPhraseHeader(IntPtr phraseBuffer, uint exp
if (isSapi53Header)
{
serializedPhrase = (SPSERIALIZEDPHRASE)Marshal.PtrToStructure(phraseBuffer, typeof(SPSERIALIZEDPHRASE));
serializedPhrase = Marshal.PtrToStructure<SPSERIALIZEDPHRASE>(phraseBuffer);
}
else
{
SPSERIALIZEDPHRASE_Sapi51 legacyPhrase = (SPSERIALIZEDPHRASE_Sapi51)Marshal.PtrToStructure(phraseBuffer, typeof(SPSERIALIZEDPHRASE_Sapi51));
SPSERIALIZEDPHRASE_Sapi51 legacyPhrase = Marshal.PtrToStructure<SPSERIALIZEDPHRASE_Sapi51>(phraseBuffer);
serializedPhrase = new SPSERIALIZEDPHRASE(legacyPhrase);
}
......@@ -539,7 +539,7 @@ private static SemanticValue RecursiveBuildSemanticProperties(IList<RecognizedWo
private static void RecursivelyExtractSemanticProperties(List<ResultPropertiesRef> propertyList, int semanticsOffset, IntPtr phraseBuffer, RuleNode ruleTree, IList<RecognizedWordUnit> words, bool isSapi53Header)
{
IntPtr propertyBuffer = new((long)phraseBuffer + semanticsOffset);
SPSERIALIZEDPHRASEPROPERTY property = (SPSERIALIZEDPHRASEPROPERTY)Marshal.PtrToStructure(propertyBuffer, typeof(SPSERIALIZEDPHRASEPROPERTY));
SPSERIALIZEDPHRASEPROPERTY property = Marshal.PtrToStructure<SPSERIALIZEDPHRASEPROPERTY>(propertyBuffer);
string propertyName;
SemanticValue thisSemanticValue = ExtractSemanticValueInformation(semanticsOffset, property, phraseBuffer, isSapi53Header, out propertyName);
......@@ -572,7 +572,7 @@ private void RecursivelyExtractSemanticValue(IntPtr phraseBuffer, int semanticsO
{
IntPtr propertyBuffer = new((long)phraseBuffer + semanticsOffset);
SPSERIALIZEDPHRASEPROPERTY property =
(SPSERIALIZEDPHRASEPROPERTY)Marshal.PtrToStructure(propertyBuffer, typeof(SPSERIALIZEDPHRASEPROPERTY));
Marshal.PtrToStructure<SPSERIALIZEDPHRASEPROPERTY>(propertyBuffer);
string propertyName;
SemanticValue thisSemanticValue = ExtractSemanticValueInformation(semanticsOffset, property, phraseBuffer, isSapi53Header, out propertyName);
......@@ -695,7 +695,7 @@ private static SemanticValue ExtractSemanticValueInformation(int semanticsOffset
break;
case VarEnum.VT_UI4:
propertyValue = Marshal.PtrToStructure(valueBuffer, typeof(uint));
propertyValue = Marshal.PtrToStructure<uint>(valueBuffer);
break;
case VarEnum.VT_I8:
......@@ -703,15 +703,15 @@ private static SemanticValue ExtractSemanticValueInformation(int semanticsOffset
break;
case VarEnum.VT_UI8:
propertyValue = Marshal.PtrToStructure(valueBuffer, typeof(ulong));
propertyValue = Marshal.PtrToStructure<ulong>(valueBuffer);
break;
case VarEnum.VT_R4:
propertyValue = Marshal.PtrToStructure(valueBuffer, typeof(float));
propertyValue = Marshal.PtrToStructure<float>(valueBuffer);
break;
case VarEnum.VT_R8:
propertyValue = Marshal.PtrToStructure(valueBuffer, typeof(double));
propertyValue = Marshal.PtrToStructure<double>(valueBuffer);
break;
case VarEnum.VT_BOOL:
......@@ -754,7 +754,7 @@ private static RuleNode ExtractRules(Grammar grammar, SPSERIALIZEDPHRASERULE rul
if (rule.NextSiblingOffset > 0)
{
IntPtr elementBuffer = new((long)phraseBuffer + rule.NextSiblingOffset);
SPSERIALIZEDPHRASERULE ruleNext = (SPSERIALIZEDPHRASERULE)Marshal.PtrToStructure(elementBuffer, typeof(SPSERIALIZEDPHRASERULE));
SPSERIALIZEDPHRASERULE ruleNext = Marshal.PtrToStructure<SPSERIALIZEDPHRASERULE>(elementBuffer);
node._next = ExtractRules(grammar, ruleNext, phraseBuffer);
}
......@@ -762,7 +762,7 @@ private static RuleNode ExtractRules(Grammar grammar, SPSERIALIZEDPHRASERULE rul
if (rule.FirstChildOffset > 0)
{
IntPtr elementBuffer = new((long)phraseBuffer + rule.FirstChildOffset);
SPSERIALIZEDPHRASERULE ruleFirst = (SPSERIALIZEDPHRASERULE)Marshal.PtrToStructure(elementBuffer, typeof(SPSERIALIZEDPHRASERULE));
SPSERIALIZEDPHRASERULE ruleFirst = Marshal.PtrToStructure<SPSERIALIZEDPHRASERULE>(elementBuffer);
node._child = ExtractRules(grammar, ruleFirst, phraseBuffer);
}
......@@ -781,7 +781,7 @@ private void ThrowInvalidSemanticInterpretationError()
{
IntPtr smlBuffer = gc.AddrOfPinnedObject();
SPSEMANTICERRORINFO semanticError = (SPSEMANTICERRORINFO)Marshal.PtrToStructure((IntPtr)((long)smlBuffer + (int)_serializedPhrase.SemanticErrorInfoOffset), typeof(SPSEMANTICERRORINFO));
SPSEMANTICERRORINFO semanticError = Marshal.PtrToStructure<SPSEMANTICERRORINFO>((IntPtr)((long)smlBuffer + (int)_serializedPhrase.SemanticErrorInfoOffset));
string source = Marshal.PtrToStringUni(new IntPtr((long)smlBuffer + semanticError.pszSourceOffset));
string description = Marshal.PtrToStringUni(new IntPtr((long)smlBuffer + semanticError.pszDescriptionOffset));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册