Example #1
0
        internal SynthesizedDelegateSymbol SynthesizeDelegate(int parameterCount, RefKindVector refKinds, bool returnsVoid, int generation)
        {
            // parameterCount doesn't include return type
            Debug.Assert(refKinds.IsNull || parameterCount == refKinds.Capacity - (returnsVoid ? 0 : 1));

            var key = new SynthesizedDelegateKey(parameterCount, refKinds, returnsVoid, generation);

            SynthesizedDelegateValue result;

            if (this.SynthesizedDelegates.TryGetValue(key, out result))
            {
                return(result.Delegate);
            }

            // NOTE: the newly created template may be thrown away if another thread wins
            var synthesizedDelegate = new SynthesizedDelegateSymbol(
                this.Compilation.Assembly.GlobalNamespace,
                key.MakeTypeName(),
                this.System_Object,
                Compilation.GetSpecialType(SpecialType.System_IntPtr),
                returnsVoid ? Compilation.GetSpecialType(SpecialType.System_Void) : null,
                parameterCount,
                refKinds);

            return(this.SynthesizedDelegates.GetOrAdd(key, new SynthesizedDelegateValue(this, synthesizedDelegate)).Delegate);
        }
            internal InvokeMethod(
                SynthesizedDelegateSymbol containingType,
                BitVector byRefParameters,
                TypeSymbol voidReturnTypeOpt
                )
            {
                var typeParams = containingType.TypeParameters;

                _containingType = containingType;

                // if we are given Void type the method returns Void, otherwise its return type is the last type parameter of the delegate:
                _returnType = voidReturnTypeOpt ?? typeParams.Last();

                var parameters = new ParameterSymbol[
                    typeParams.Length - ((object)voidReturnTypeOpt != null ? 0 : 1)
                                 ];

                for (int i = 0; i < parameters.Length; i++)
                {
                    // we don't need to distinguish between out and ref since this is an internal synthesized symbol:
                    var refKind =
                        !byRefParameters.IsNull && byRefParameters[i] ? RefKind.Ref : RefKind.None;

                    parameters[i] = SynthesizedParameterSymbol.Create(
                        this,
                        TypeWithAnnotations.Create(typeParams[i]),
                        i,
                        refKind
                        );
                }

                _parameters = parameters.AsImmutableOrNull();
            }
Example #3
0
 public SynthesizedDelegateValue(
     AnonymousTypeManager manager,
     SynthesizedDelegateSymbol @delegate
     )
 {
     Debug.Assert(manager != null && (object)@delegate != null);
     this.Manager  = manager;
     this.Delegate = @delegate;
 }
Example #4
0
        private SynthesizedDelegateValue CreatePlaceholderSynthesizedDelegateValue(string name, RefKindVector refKinds, bool returnsVoid, int parameterCount)
        {
            var symbol = new SynthesizedDelegateSymbol(
                this.Compilation.Assembly.GlobalNamespace,
                MetadataHelpers.InferTypeArityAndUnmangleMetadataName(name, out _),
                this.System_Object,
                Compilation.GetSpecialType(SpecialType.System_IntPtr),
                returnsVoid ? Compilation.GetSpecialType(SpecialType.System_Void) : null,
                parameterCount,
                refKinds);

            return(new SynthesizedDelegateValue(this, symbol));
        }
            internal InvokeMethod(SynthesizedDelegateSymbol containingType, BitVector byRefParameters, TypeSymbol voidReturnTypeOpt)
            {
                var typeParams = containingType.TypeParameters;

                _containingType = containingType;

                // if we are given Void type the method returns Void, otherwise its return type is the last type parameter of the delegate:
                _returnType = voidReturnTypeOpt ?? typeParams.Last();

                var parameters = new ParameterSymbol[typeParams.Length - ((object)voidReturnTypeOpt != null ? 0 : 1)];
                for (int i = 0; i < parameters.Length; i++)
                {
                    // we don't need to distinguish between out and ref since this is an internal synthesized symbol:
                    var refKind = !byRefParameters.IsNull && byRefParameters[i] ? RefKind.Ref : RefKind.None;

                    parameters[i] = SynthesizedParameterSymbol.Create(this, typeParams[i], i, refKind);
                }

                _parameters = parameters.AsImmutableOrNull();
            }