예제 #1
0
        //------------------------------------------------------------
        // NestedTypeResolver.ResolveType
        //
        /// <summary>
        /// Find the class specified in args and create its Type.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        //------------------------------------------------------------
        internal Assembly ResolveType(object sender, ResolveEventArgs args)
        {
            if (args == null || String.IsNullOrEmpty(args.Name))
            {
                return(null);
            }

            string[]  names     = args.Name.Split('.');
            AGGSYM    aggSym    = null;
            AGGSYM    parentSym = this.EnclosingAggSym;
            Exception excp      = null;

            for (int i = 0; i < names.Length; ++i)
            {
                aggSym = compiler.LookupGlobalSym(names[i], parentSym, SYMBMASK.AGGSYM) as AGGSYM;
                if (aggSym == null)
                {
                    return(null);
                }
                parentSym = aggSym;
            }

            aggSym.CreateType(out excp);
            OUTFILESYM outfileSym = aggSym.GetOutputFile();

            if (outfileSym != null && outfileSym.AssemblyBuilderEx != null)
            {
                return(outfileSym.AssemblyBuilderEx.AssemblyBuilder);
            }
            return(null);
        }
예제 #2
0
        //------------------------------------------------------------
        // MetaDataHelper.GetAggregateFlags
        //
        /// <summary>
        /// <para>Determine the flags for a typedef definition in metadata</para>
        /// <para>Use System.Reflection.TypeAttribuetes in place of CorTypeAttr of sscli.</para>
        /// <para>CorTypeAttr has a member named "Forwarder" which TypeAttributes does not has.</para>
        /// </summary>
        /// <param name="aggSym"></param>
        /// <returns></returns>
        //------------------------------------------------------------
        internal static TypeAttributes GetAggregateFlags(AGGSYM aggSym)
        {
            TypeAttributes flags = 0;

            // Determine flags.

            // Set access flags.
            flags |= GetTypeAccessFlags(aggSym);

            // Set other flags
            switch (aggSym.AggKind)
            {
            case AggKindEnum.Class:
                if (aggSym.IsSealed)
                {
                    flags |= TypeAttributes.Sealed;
                }
                if (aggSym.IsAbstract)
                {
                    flags |= TypeAttributes.Abstract;
                }
                if (!aggSym.HasUserDefinedStaticCtor)
                {
                    flags |= TypeAttributes.BeforeFieldInit;
                }
                break;

            case AggKindEnum.Interface:
                flags |= TypeAttributes.Interface | TypeAttributes.Abstract;
                break;

            case AggKindEnum.Enum:
                DebugUtil.Assert(aggSym.IsSealed);
                flags |= TypeAttributes.Sealed;
                break;

            case AggKindEnum.Struct:
                DebugUtil.Assert(aggSym.IsSealed);
                flags |= TypeAttributes.Sealed;
                if (!aggSym.HasUserDefinedStaticCtor)
                {
                    flags |= TypeAttributes.BeforeFieldInit;
                }
                if (aggSym.IsFabricated)
                {
                    flags |= TypeAttributes.SequentialLayout;     // Fabricated structs are always sequential
                }
                break;

            case AggKindEnum.Delegate:
                DebugUtil.Assert(aggSym.IsSealed);
                flags |= TypeAttributes.Sealed;
                break;

            default:
                DebugUtil.Assert(false);
                break;
            }

            switch (aggSym.GetOutputFile().DefaultCharSet)
            {
            default:
                DebugUtil.VsFail("A new value was added to System.Runtime.InteropServices.CharSet that we need to handle");
                goto case 0;

            case (System.Runtime.InteropServices.CharSet) 0:        // Unset
            case System.Runtime.InteropServices.CharSet.None:       // 1:
                break;

            case System.Runtime.InteropServices.CharSet.Ansi:       // 2:
                flags |= TypeAttributes.AnsiClass;
                break;

            case System.Runtime.InteropServices.CharSet.Unicode:        // 3:
                flags |= TypeAttributes.UnicodeClass;
                break;

            case System.Runtime.InteropServices.CharSet.Auto:       // 4:
                flags |= TypeAttributes.AutoClass;
                break;
            }

            return(flags);
        }