public SignatureInfoMatchTarget(TypeInfo interfaceTypeInfo, int functionIndex, ElemDesc elemDesc, int parameterIndex) { if (interfaceTypeInfo == null) throw new ArgumentNullException(nameof(interfaceTypeInfo)); m_interfaceTypeInfo = interfaceTypeInfo; m_functionIndex = functionIndex; m_funcDesc = interfaceTypeInfo.GetFuncDesc(m_functionIndex); m_elemDesc = elemDesc; m_parameterIndex = parameterIndex; if (m_parameterIndex == 0) { m_name = "return"; } else { // the name of the parameter. string[] signatureNames = m_interfaceTypeInfo.GetNames(m_funcDesc.memid, m_funcDesc.cParams + 1); m_name = signatureNames[m_parameterIndex]; if (m_name == null || m_name.Trim().Equals("")) m_name = "_unnamed_arg_" + m_parameterIndex; } // NativeParentFunctionName m_nativeParentFunctionName = m_interfaceTypeInfo.GetDocumentation(m_funcDesc.memid); // NativeSignature m_nativeSignature = (new TlbType2String(interfaceTypeInfo, m_elemDesc.tdesc)).GetTypeString(); }
/// <summary> /// Process parameters and apply attributes /// </summary> private static void ProcessParam(InterfaceInfo info, InterfaceMemberInfo memInfo, ElemDesc desc, TypeConverter converter, MethodBuilder methodBuilder, int index, string strname, bool isVarArg, bool isOptionalArg) { ParamDesc param = desc.paramdesc; ParameterAttributes attributes = ParameterAttributes.None; if (converter.ParameterAttributesOverride != ParameterAttributes.None) { attributes = converter.ParameterAttributesOverride; } else { // // Determine in/out/opt // Don't emit [In], [Out] for return type // if (index != 0) { // Always emit in/out information according to type library if (param.IsIn) { attributes |= ParameterAttributes.In; } if (param.IsOut) { attributes |= ParameterAttributes.Out; } if (param.IsOpt || isOptionalArg) { attributes |= ParameterAttributes.Optional; } } } // // Define the parameter // ParameterBuilder parameterBuilder = methodBuilder.DefineParameter(index, attributes, strname); // // Apply MarshalAs attribute // converter.ApplyAttributes(parameterBuilder); // // Support for vararg // if (isVarArg) { parameterBuilder.SetCustomAttribute(CustomAttributeHelper.GetBuilderForParamArray()); } // // Support for default value // if (desc.paramdesc.HasDefault && desc.paramdesc.lpVarValue != IntPtr.Zero) SetDefaultValue(desc, converter.ConvertedType, parameterBuilder); }
/// <summary> /// Sets the default value according to the ElemDesc on the ParameterBuilder /// </summary> public static void SetDefaultValue(ElemDesc elem, Type type, ParameterBuilder paramBuilder) { ParamDesc param = elem.paramdesc; IntPtr ipPARAMDESCEX = param.lpVarValue; // It is bad that Marshalling doesn't take alignment into account, so I had to use a hard code value here IntPtr ipVariant = Utils.MovePointer(ipPARAMDESCEX, 8); SetDefaultValueInternal(ipVariant, type, paramBuilder, null, (short)elem.tdesc.vt); }