Beispiel #1
0
        public static AssemblyFlags ConvertAssemblyNameFlags(AssemblyNameFlags flags)
        {
            var result = (AssemblyFlags)0;

            if (flags.HasFlag(AssemblyNameFlags.PublicKey))
            {
                result |= AssemblyFlags.PublicKey;
            }

            if (flags.HasFlag(AssemblyNameFlags.Retargetable))
            {
                result |= AssemblyFlags.Retargetable;
            }

            // No, it's not a typo. Microsoft decided to put "exact opposite of the meaning" for this flag.
            if (flags.HasFlag(AssemblyNameFlags.EnableJITcompileOptimizer))
            {
                result |= AssemblyFlags.DisableJitCompileOptimizer;
            }

            if (flags.HasFlag(AssemblyNameFlags.EnableJITcompileTracking))
            {
                result |= AssemblyFlags.EnableJitCompileTracking;
            }

            return(result);
        }
        private Expression GetAssemblyFlagsExpression(AssemblyNameFlags assemblyFlags)
        {
            var flagNames  = new List <string>();
            var flagValues = Enum.GetValues(typeof(AssemblyNameFlags));

            foreach (var flagValue in flagValues)
            {
                if (assemblyFlags.HasFlag((Enum)flagValue) && (int)flagValue > 0)
                {
                    flagNames.Add(flagValue.ToString());
                }
            }

            Expression expression = null;

            while (flagNames.Count > 0)
            {
                var currentFlagName = flagNames[0];
                var flagExpression  = new MemberReferenceExpression(new IdentifierExpression("AssemblyNameFlags"), currentFlagName);

                expression = expression == null
                                        ? (Expression)flagExpression
                                        : new BinaryOperatorExpression(expression, BinaryOperatorType.BitwiseOr, flagExpression);

                flagNames.Remove(currentFlagName);
            }

            return(expression);
        }