예제 #1
0
        /// <summary>
        /// Override the dispid if Guid_DispIdOverride is present
        /// </summary>
        /// <param name="index">The index of the func/var, not the disp id</param>
        /// <returns>Whether we have Guid_DispIdOverride or not</returns>
        public static bool GetOverrideDispId(ConverterInfo info, TypeInfo typeInfo, int index, InterfaceMemberType memberType, ref int dispid, bool isSet)
        {
            bool hasOverride = false;
            object data;

            if (memberType == InterfaceMemberType.Method)
                data = typeInfo.GetFuncCustData(index, CustomAttributeGuids.GUID_DispIdOverride);
            else
            {
                Debug.Assert(memberType == InterfaceMemberType.Variable);
                data = typeInfo.GetVarCustData(index, CustomAttributeGuids.GUID_DispIdOverride);
            }

            if (data is short)
            {
                dispid = (short)data;
                hasOverride = true;
            }
            else if (data is int)
            {
                dispid = (int)data;
                hasOverride = true;
            }
            else if (data != null)
            {
                // We only emit Wrn_NonIntegralCustomAttributeType when we set the id
                if (isSet)
                {
                    //
                    // Emit Wrn_NonIntegralCustomAttributeType warning
                    //
                    info.ReportEvent(
                        WarningCode.Wrn_NonIntegralCustomAttributeType,
                        Resource.FormatString("Wrn_NonIntegralCustomAttributeType", "{" + CustomAttributeGuids.GUID_DispIdOverride.ToString().ToUpper() + "}", typeInfo.GetDocumentation(dispid)));
                }
            }

            return hasOverride;
        }