/// <summary> /// Obtains the parameter information for a given FuncDesc. /// </summary> internal static ParameterInformation[] GetParameterInformation(COM.FUNCDESC funcdesc, bool skipLastParameter) { int cParams = funcdesc.cParams; if (skipLastParameter) { Diagnostics.Assert(cParams > 0, "skipLastParameter is only true for property setters where there is at least one parameter"); cParams--; } ParameterInformation[] parameters = new ParameterInformation[cParams]; IntPtr ElementDescriptionArrayPtr = funcdesc.lprgelemdescParam; int ElementDescriptionSize = Marshal.SizeOf <COM.ELEMDESC>(); for (int i = 0; i < cParams; i++) { COM.ELEMDESC ElementDescription; int ElementDescriptionArrayByteOffset; IntPtr ElementDescriptionPointer; bool fOptional = false; ElementDescription = new COM.ELEMDESC(); ElementDescriptionArrayByteOffset = i * ElementDescriptionSize; // Disable PRefast warning for converting to int32 and converting back into intptr. // Code below takes into account 32 bit vs 64 bit conversions #pragma warning disable 56515 if (IntPtr.Size == 4) { ElementDescriptionPointer = (IntPtr)(ElementDescriptionArrayPtr.ToInt32() + ElementDescriptionArrayByteOffset); } else { ElementDescriptionPointer = (IntPtr)(ElementDescriptionArrayPtr.ToInt64() + ElementDescriptionArrayByteOffset); } #pragma warning enable 56515 ElementDescription = Marshal.PtrToStructure <COM.ELEMDESC>(ElementDescriptionPointer); // get the type of parameter Type type = ComUtil.GetTypeFromTypeDesc(ElementDescription.tdesc); object defaultvalue = null; // check is this parameter is optional. if ((ElementDescription.desc.paramdesc.wParamFlags & COM.PARAMFLAG.PARAMFLAG_FOPT) != 0) { fOptional = true; defaultvalue = Type.Missing; } bool fByRef = (ElementDescription.desc.paramdesc.wParamFlags & COM.PARAMFLAG.PARAMFLAG_FOUT) != 0; parameters[i] = new ParameterInformation(type, fOptional, defaultvalue, fByRef); } return(parameters); }
private static ComMethodInformation GetMethodInformation( System.Runtime.InteropServices.ComTypes.FUNCDESC funcdesc, bool skipLastParameter) { Type typeFromTypeDesc = ComUtil.GetTypeFromTypeDesc(funcdesc.elemdescFunc.tdesc); ParameterInformation[] parameterInformation1 = ComUtil.GetParameterInformation(funcdesc, skipLastParameter); bool hasoptional = false; foreach (ParameterInformation parameterInformation2 in parameterInformation1) { if (parameterInformation2.isOptional) { hasoptional = true; break; } } return(new ComMethodInformation(false, hasoptional, parameterInformation1, typeFromTypeDesc)); }
internal static ParameterInformation[] GetParameterInformation( System.Runtime.InteropServices.ComTypes.FUNCDESC funcdesc, bool skipLastParameter) { int cParams = (int)funcdesc.cParams; if (skipLastParameter) { --cParams; } ParameterInformation[] parameterInformationArray = new ParameterInformation[cParams]; IntPtr lprgelemdescParam = funcdesc.lprgelemdescParam; int num1 = Marshal.SizeOf(typeof(System.Runtime.InteropServices.ComTypes.ELEMDESC)); for (int index = 0; index < cParams; ++index) { System.Runtime.InteropServices.ComTypes.ELEMDESC elemdesc = new System.Runtime.InteropServices.ComTypes.ELEMDESC(); int num2 = index * num1; elemdesc = (System.Runtime.InteropServices.ComTypes.ELEMDESC)Marshal.PtrToStructure(IntPtr.Size != 4 ? (IntPtr)(lprgelemdescParam.ToInt64() + (long)num2) : (IntPtr)(lprgelemdescParam.ToInt32() + num2), typeof(System.Runtime.InteropServices.ComTypes.ELEMDESC)); Type typeFromTypeDesc = ComUtil.GetTypeFromTypeDesc(elemdesc.tdesc); object defaultValue = (object)null; bool isOptional; if ((elemdesc.desc.paramdesc.wParamFlags & System.Runtime.InteropServices.ComTypes.PARAMFLAG.PARAMFLAG_FOPT) != System.Runtime.InteropServices.ComTypes.PARAMFLAG.PARAMFLAG_NONE) { isOptional = true; defaultValue = Type.Missing; } else { isOptional = false; } bool isByRef = false; if ((elemdesc.desc.paramdesc.wParamFlags & System.Runtime.InteropServices.ComTypes.PARAMFLAG.PARAMFLAG_FOUT) != System.Runtime.InteropServices.ComTypes.PARAMFLAG.PARAMFLAG_NONE) { isByRef = true; } parameterInformationArray[index] = new ParameterInformation(typeFromTypeDesc, isOptional, defaultValue, isByRef); } return(parameterInformationArray); }