MarshalPseudoCustomAttributeData IMarshalAsAttributeTarget.GetOrCreateData()
        {
            VerifySealed(expected: false);
            if (_lazyMarshalAsData == null)
            {
                _lazyMarshalAsData = new MarshalPseudoCustomAttributeData();
                SetDataStored();
            }

            return(_lazyMarshalAsData);
        }
Esempio n. 2
0
        /// <summary>
        /// Returns an instance of <see cref="MarshalPseudoCustomAttributeData"/> with all types replaced by types returned by specified translator.
        /// Returns this instance if it doesn't hold on any types.
        /// </summary>
        internal MarshalPseudoCustomAttributeData WithTranslatedTypes <TTypeSymbol, TArg>(
            Func <TTypeSymbol, TArg, TTypeSymbol> translator, TArg arg)
            where TTypeSymbol : ITypeSymbol
        {
            if (_marshalType != Cci.Constants.UnmanagedType_SafeArray || _marshalTypeNameOrSymbol == null)
            {
                return(this);
            }

            var translatedType = translator((TTypeSymbol)_marshalTypeNameOrSymbol, arg);

            if ((object)translatedType == (object)_marshalTypeNameOrSymbol)
            {
                return(this);
            }

            var result = new MarshalPseudoCustomAttributeData();

            result.SetMarshalAsSafeArray((Cci.VarEnum)_marshalArrayElementType, translatedType);
            return(result);
        }