Ejemplo n.º 1
0
        private void LoadCultures()
        {
            var cultures = CultureInfo.GetCultures(CultureTypes.AllCultures);

            _cultures = new HashList <string>(cultures.Length, StringComparer.OrdinalIgnoreCase);

            for (int i = 0; i < cultures.Length; i++)
            {
                _cultures.TryAdd(cultures[i].Name);
            }
        }
        private int AddString(string value)
        {
            if (value == null)
            {
                value = string.Empty;
            }

            int index;

            _strings.TryAdd(value, out index);

            return(index);
        }
Ejemplo n.º 3
0
        internal int AddSignature <T>(ref T signature)
            where T : ISignature
        {
            if (signature == null)
            {
                return(0);
            }

            int index;

            if (!_signatures.TryAdd(signature, out index))
            {
                signature = (T)_signatures[index];
            }

            return(index + 1);
        }
        private bool Build(ILInstruction instruction)
        {
            var methodRef = instruction.Value as MethodReference;

            if (methodRef == null)
            {
                return(false);
            }

            var opCode = instruction.OpCode;

            if (opCode != OpCodes.Call && opCode != OpCodes.Callvirt)
            {
                return(false);
            }

            if (methodRef.HasThis ||
                methodRef.CallConv != MethodCallingConvention.Default)
            {
                return(false);
            }

            int methodIndex;

            _methodRefs.TryAdd(methodRef, out methodIndex);

            instruction.OpCode = OpCodes.Ldsfld;
            instruction.Value  =
                new FieldReference(
                    "MethodPointers",
                    new ArrayType(
                        TypeReference.GetPrimitiveType(PrimitiveTypeCode.IntPtr, _module.Assembly)),
                    new TypeReference(_mainType.Name, _mainType.Namespace, false));
            instruction = instruction.AddNext(Instruction.GetLdc(methodIndex));
            instruction = instruction.AddNext(OpCodes.Ldelem_I);
            instruction = instruction.AddNext(OpCodes.Calli, methodRef.CallSite);

            return(true);
        }
Ejemplo n.º 5
0
        public string GenerateUniqueString()
        {
            string s;

            do
            {
                s = GenerateNextString();
            }while (!_existingStrings.TryAdd(s));

            return(s);
        }