Ejemplo n.º 1
0
        internal void EmitArrayBlockInitializer(ImmutableArray <byte> data, SyntaxNode syntaxNode, DiagnosticBag diagnostics)
        {
            // get helpers
            Cci.IMethodReference initializeArray = module.GetInitArrayHelper();

            // map a field to the block (that makes it addressable via a token)
            Cci.IFieldReference field = module.GetFieldForData(data, syntaxNode, diagnostics);

            // emit call to the helper
            EmitOpCode(ILOpCode.Dup);                  //array
            EmitOpCode(ILOpCode.Ldtoken);
            EmitToken(field, syntaxNode, diagnostics); //block
            EmitOpCode(ILOpCode.Call, -2);
            EmitToken(initializeArray, syntaxNode, diagnostics);
        }
        private static void VisitFieldReference(Cci.IFieldReference fieldReference, EmitContext context)
        {
            Debug.Assert(fieldReference != null);

            // Visit containing type
            VisitTypeReference(fieldReference.GetContainingType(context), context);

            // Translate substituted field to original definition
            Cci.ISpecializedFieldReference specializedField = fieldReference.AsSpecializedFieldReference;
            if (specializedField != null)
            {
                fieldReference = specializedField.UnspecializedVersion;
            }

            // Visit field type
            VisitTypeReference(fieldReference.GetType(context), context);
        }
        public static void VisitReference(Cci.IReference reference, EmitContext context)
        {
            Cci.ITypeReference typeReference = reference as Cci.ITypeReference;
            if (typeReference != null)
            {
                VisitTypeReference(typeReference, context);
                return;
            }

            Cci.IMethodReference methodReference = reference as Cci.IMethodReference;
            if (methodReference != null)
            {
                VisitMethodReference(methodReference, context);
                return;
            }

            Cci.IFieldReference fieldReference = reference as Cci.IFieldReference;
            if (fieldReference != null)
            {
                VisitFieldReference(fieldReference, context);
                return;
            }
        }