@@ -950,11 +950,25 @@ type ILAttribElem =
950950
951951type ILAttributeNamedArg = ( string* ILType* bool* ILAttribElem)
952952
953- [<StructuralEquality; StructuralComparison; StructuredFormatDisplay( " {DebugText}" ) >]
954- type ILAttribute =
955- { Method: ILMethodSpec
956- Data: byte []
957- Elements: ILAttribElem list }
953+ [<RequireQualifiedAccess; StructuralEquality; StructuralComparison; StructuredFormatDisplay( " {DebugText}" ) >]
954+ type ILAttribute =
955+ | Encodedof method : ILMethodSpec * data : byte [] * elements : ILAttribElem list
956+ | Decodedof method : ILMethodSpec * fixedArgs : ILAttribElem list * namedArgs : ILAttributeNamedArg list
957+
958+ member x.Method =
959+ match xwith
960+ | Encoded( method, _, _)
961+ | Decoded( method, _, _) -> method
962+
963+ member x.Elements =
964+ match xwith
965+ | Encoded(_, _, elements) -> elements
966+ | Decoded(_, fixedArgs, namedArgs) -> fixedArgs@ ( namedArgs|> List.map( fun ( _ , _ , _ , e ) -> e))
967+
968+ member x.WithMethod ( method : ILMethodSpec ) =
969+ match xwith
970+ | Encoded(_, data, elements) -> Encoded( method, data, elements)
971+ | Decoded(_, fixedArgs, namedArgs) -> Decoded( method, fixedArgs, namedArgs)
958972
959973/// For debugging
960974[<DebuggerBrowsable( DebuggerBrowsableState.Never) >]
@@ -3575,21 +3589,30 @@ let encodeCustomAttrNamedArg ilg (nm, ty, prop, elem) =
35753589yield ! encodeCustomAttrString nm
35763590yield ! encodeCustomAttrValue ilg ty elem|]
35773591
3578- let mkILCustomAttribMethRef ( ilg : ILGlobals ) ( mspec : ILMethodSpec , fixedArgs : list < _ >, namedArgs : list < _ >) =
3592+ let encodeCustomAttrArgs ( ilg : ILGlobals ) ( mspec : ILMethodSpec ) ( fixedArgs : list < _ >) ( namedArgs : list < _ >) =
35793593let argtys = mspec.MethodRef.ArgTypes
3580- let args =
3581- [| yield ! [| 0x01 uy; 0x00 uy; |]
3582- for ( argty, fixedArg) in Seq.zip argtys fixedArgsdo
3583- yield ! encodeCustomAttrValue ilg argty fixedArg
3584- yield ! u16AsBytes( uint16 namedArgs.Length)
3585- for namedArgin namedArgsdo
3586- yield ! encodeCustomAttrNamedArg ilg namedArg|]
3587- { Method= mspec
3588- Data= args
3589- Elements= fixedArgs@ ( namedArgs|> List.map( fun ( _ , _ , _ , e ) -> e)) }
3590-
3591- let mkILCustomAttribute ilg ( tref , argtys , argvs , propvs ) =
3592- mkILCustomAttribMethRef ilg( mkILNonGenericCtorMethSpec( tref, argtys), argvs, propvs)
3594+ [| yield ! [| 0x01 uy; 0x00 uy; |]
3595+ for ( argty, fixedArg) in Seq.zip argtys fixedArgsdo
3596+ yield ! encodeCustomAttrValue ilg argty fixedArg
3597+ yield ! u16AsBytes( uint16 namedArgs.Length)
3598+ for namedArgin namedArgsdo
3599+ yield ! encodeCustomAttrNamedArg ilg namedArg|]
3600+
3601+ let encodeCustomAttr ( ilg : ILGlobals ) ( mspec : ILMethodSpec , fixedArgs : list < _ >, namedArgs : list < _ >) =
3602+ let args = encodeCustomAttrArgs ilg mspec fixedArgs namedArgs
3603+ ILAttribute.Encoded( mspec, args, fixedArgs@ ( namedArgs|> List.map( fun ( _ , _ , _ , e ) -> e)))
3604+
3605+ let mkILCustomAttribMethRef ( ilg : ILGlobals ) ( mspec : ILMethodSpec , fixedArgs : list < _ >, namedArgs : list < _ >) =
3606+ encodeCustomAttr ilg( mspec, fixedArgs, namedArgs)
3607+
3608+ let mkILCustomAttribute ilg ( tref , argtys , argvs , propvs ) =
3609+ encodeCustomAttr ilg( mkILNonGenericCtorMethSpec( tref, argtys), argvs, propvs)
3610+
3611+ let getCustomAttrData ( ilg : ILGlobals ) cattr =
3612+ match cattrwith
3613+ | ILAttribute.Encoded(_, data, _) -> data
3614+ | ILAttribute.Decoded( mspec, fixedArgs, namedArgs) ->
3615+ encodeCustomAttrArgs ilg mspec fixedArgs namedArgs
35933616
35943617let MscorlibScopeRef = ILScopeRef.Assembly( ILAssemblyRef.Create( " mscorlib" , None, Some ecmaPublicKey, true , None, None))
35953618let EcmaMscorlibILGlobals = mkILGlobals MscorlibScopeRef
@@ -3758,7 +3781,10 @@ type ILTypeSigParser(tstring : string) =
37583781 ILAttribElem.Type( Some( ilty))
37593782
37603783let decodeILAttribData ( ilg : ILGlobals ) ( ca : ILAttribute ) =
3761- let bytes = ca.Data
3784+ match cawith
3785+ | ILAttribute.Decoded(_, fixedArgs, namedArgs) -> fixedArgs, namedArgs
3786+ | ILAttribute.Encoded(_, bytes, _) ->
3787+
37623788let sigptr = 0
37633789let bb0 , sigptr = sigptr_ get_ byte bytes sigptr
37643790let bb1 , sigptr = sigptr_ get_ byte bytes sigptr
@@ -3947,7 +3973,7 @@ and refs_of_token s x =
39473973| ILToken.ILMethod mr-> refs_ of_ mspec s mr
39483974| ILToken.ILField fr-> refs_ of_ fspec s fr
39493975
3950- and refs_of_custom_attr sx = refs_ of_ mspec sx .Method
3976+ and refs_of_custom_attr s ( cattr : ILAttribute ) = refs_ of_ mspec scattr .Method
39513977
39523978and refs_of_custom_attrs s ( cas : ILAttributes ) = List.iter( refs_ of_ custom_ attr s) cas.AsList
39533979and refs_of_varargs s tyso = Option.iter( refs_ of_ tys s) tyso