public FieldInfoMatchTarget(TypeInfo parentTypeInfo, int index)
 {
     if (parentTypeInfo == null) throw new ArgumentNullException(nameof(parentTypeInfo));
     m_parentTypeInfo = parentTypeInfo;
     m_index = index;
     m_varDesc = m_parentTypeInfo.GetVarDesc(m_index);
     m_nativeParentTypeName = m_parentTypeInfo.GetDocumentation();
 }
示例#2
0
 public ElemDesc(VarDesc varDesc, ELEMDESC elemdesc)
 {
     m_parent = varDesc;
     Init(elemdesc);
 }
示例#3
0
        private void CreateField(TypeInfo type, TypeAttr attr, VarDesc var, ref bool isConversionLoss)
        {
            TypeDesc fieldTypeDesc = var.elemdescVar.tdesc;
            TypeConverter typeConverter = new TypeConverter(m_info, type, fieldTypeDesc, ConversionType.Field);
            Type fieldType = typeConverter.ConvertedType;
            string fieldName = type.GetDocumentation(var.memid);
            FieldBuilder field = m_typeBuilder.DefineField(fieldName, fieldType, FieldAttributes.Public);
            typeConverter.ApplyAttributes(field);

            isConversionLoss |= typeConverter.IsConversionLoss;

            //
            // Emit ComConversionLossAttribute for fields if necessary
            //
            if (typeConverter.IsConversionLoss)
            {
                field.SetCustomAttribute(CustomAttributeHelper.GetBuilderForComConversionLoss());

                //
                // Emit Wrn_UnconvertableField warning
                //
                m_info.ReportEvent(
                    WarningCode.Wrn_UnconvertableField,
                    Resource.FormatString("Wrn_UnconvertableField", m_typeBuilder.FullName, fieldName));
            }

            //
            // Emit TypeLibVarAttribute if necessary
            //
            if (var.wVarFlags != 0)
            {
                field.SetCustomAttribute(CustomAttributeHelper.GetBuilderForTypeLibVar((TypeLibVarFlags)var.wVarFlags));
            }
        }
示例#4
0
        private void CreateField(TypeInfo type, TypeAttr attr, VarDesc var, ref bool isConversionLoss)
        {
            if (IsObjectType(type, var.elemdescVar.tdesc))
            {
                isConversionLoss = true;
            }
            else
            {

                TypeConverter typeConverter = new TypeConverter(m_info, type, var.elemdescVar.tdesc, ConversionType.Field);
                Type fieldType = typeConverter.ConvertedType;

                // TlbImp2 will only skip reference types, instead of skipping every field
                // Also, TlbImp1 will skip ValueType *, which doesn't make any sense. TlbImp2 will keep ValueType * as IntPtr

                string fieldName = type.GetDocumentation(var.memid);
                // Generates the [FieldOffset(0)] layout declarations that approximate unions in managed code
                FieldBuilder field = m_typeBuilder.DefineField(fieldName, fieldType, FieldAttributes.Public);
                field.SetCustomAttribute(CustomAttributeHelper.GetBuilderForFieldOffset(0));
                typeConverter.ApplyAttributes(field);

                isConversionLoss |= typeConverter.IsConversionLoss;

                //
                // Emit ComConversionLossAttribute for fields if necessary
                //
                if (typeConverter.IsConversionLoss)
                {
                    field.SetCustomAttribute(CustomAttributeHelper.GetBuilderForComConversionLoss());

                    //
                    // Emit Wrn_UnconvertableField warning
                    //
                    m_info.ReportEvent(
                        WarningCode.Wrn_UnconvertableField,
                        Resource.FormatString("Wrn_UnconvertableField", m_typeBuilder.FullName, fieldName));
                }
            }
        }
示例#5
0
 public ElemDesc(VarDesc varDesc, ELEMDESC elemdesc)
 {
     m_parent = varDesc;
     Init(elemdesc);
 }
示例#6
0
        private static MethodBuilder CreateMethodInternal(InterfaceInfo info, VarDesc var, InterfaceMemberInfo memberInfo, CreateMethodMode mode, ref bool isConversionLoss)
        {
            bool convertingNewEnumMember = IsNewEnumDispatchProperty(info.ConverterInfo, info.RefTypeInfo, var, memberInfo.Index);

            Type retType = null;
            Type[] paramTypes = null;
            TypeConverter propTypeConverter = new TypeConverter(info.ConverterInfo, info.RefTypeInfo, var.elemdescVar.tdesc, ConversionType.ReturnValue);

            isConversionLoss |= propTypeConverter.IsConversionLoss;
            Type propType = propTypeConverter.ConvertedType;

            int propTypeParamIndex = 0;  // The index of the function parameter that represents the property type
            if (memberInfo.InvokeKind == TypeLibTypes.Interop.INVOKEKIND.INVOKE_PROPERTYGET)
            {
                retType = propType;
                paramTypes = new Type[] { };
                propTypeParamIndex = 0;     // for Type get_XXX(). Index = 0
            }
            else if (memberInfo.InvokeKind == TypeLibTypes.Interop.INVOKEKIND.INVOKE_PROPERTYPUT)
            {
                retType = typeof(void);
                paramTypes = new Type[] { propType };
                propTypeParamIndex = 1;     // for void set_XXX(Type arg). Index = 1
            }
            else
            {
                Debug.Assert(false, "Should not get here!");
            }

            MethodBuilder methodBuilder = CreateMethodCore(info, memberInfo, convertingNewEnumMember, mode, true, retType, paramTypes);
            ProcessParam(info, memberInfo, var.elemdescVar, propTypeConverter, methodBuilder, propTypeParamIndex, "", false, false);

            return methodBuilder;
        }
示例#7
0
 /// <summary>
 /// Sets the default value according to the ElemDesc on the FieldBuilder
 /// </summary>
 public static void SetDefaultValue(VarDesc var, Type type, FieldBuilder fieldBuilder)
 {
     SetDefaultValueInternal(var.lpvarValue, type, null, fieldBuilder, (short)var.elemdescVar.tdesc.vt);
 }
示例#8
0
        /// <summary>
        /// Is this dispatch property a NewEnum property with the right type and DISPID?
        /// </summary>
        public static bool IsNewEnumDispatchProperty(ConverterInfo info, TypeInfo typeInfo, VarDesc var, int index)
        {
            //
            // Support GUID_DispIdOverride
            //
            int dispid = var.memid;
            GetOverrideDispId(info, typeInfo, index, InterfaceMemberType.Variable, ref dispid, false);

            if (dispid == WellKnownDispId.DISPID_NEWENUM &&
                var.elemdescVar.paramdesc.IsRetval &&
                var.IsReadOnly
                )
            {
                TypeDesc typeDesc = var.elemdescVar.tdesc;

                if (typeDesc.vt == (int)VarEnum.VT_UNKNOWN || typeDesc.vt == (int)VarEnum.VT_DISPATCH)
                {
                    return true;
                }
                else if (typeDesc.vt == (int)VarEnum.VT_PTR)
                {
                    typeDesc = typeDesc.lptdesc;
                    if (typeDesc.vt == (int)VarEnum.VT_USERDEFINED)
                    {
                        TypeInfo type = typeInfo.GetRefTypeInfo(typeDesc.hreftype);
                        using (TypeAttr attr = type.GetTypeAttr())
                        {
                            if (attr.Guid == WellKnownGuids.IID_IUnknown ||
                               attr.Guid == WellKnownGuids.IID_IDispatch ||
                               attr.Guid == WellKnownGuids.IID_IEnumVARIANT)
                            {
                                return true;
                            }
                        }
                    }
                }
            }

            return false;
        }