Esempio n. 1
0
        static CustomMod [] CombineCustomMods(CustomMod [] original, CustomMod [] next)
        {
            if (next == null || next.Length == 0)
            {
                return(original);
            }

            CustomMod [] mods = new CustomMod [original.Length + next.Length];
            Array.Copy(original, mods, original.Length);
            Array.Copy(next, 0, mods, original.Length, next.Length);
            return(mods);
        }
        void Write(CustomMod cm)
        {
            switch (cm.CMOD)
            {
            case CustomMod.CMODType.OPT:
                Write(ElementType.CModOpt);
                break;

            case CustomMod.CMODType.REQD:
                Write(ElementType.CModReqD);
                break;
            }

            Write((int)Utilities.CompressMetadataToken(
                      CodedIndex.TypeDefOrRef, cm.TypeDefOrRef));
        }
        CustomMod ReadCustomMod(byte [] data, int pos, out int start)
        {
            CustomMod cm = new CustomMod();

            start = pos;
            ElementType cmod = (ElementType)Utilities.ReadCompressedInteger(data, start, out start);

            if (cmod == ElementType.CModOpt)
            {
                cm.CMOD = CustomMod.CMODType.OPT;
            }
            else if (cmod == ElementType.CModReqD)
            {
                cm.CMOD = CustomMod.CMODType.REQD;
            }
            else
            {
                cm.CMOD = CustomMod.CMODType.None;
            }
            cm.TypeDefOrRef = Utilities.GetMetadataToken(CodedIndex.TypeDefOrRef,
                                                         (uint)Utilities.ReadCompressedInteger(data, start, out start));
            return(cm);
        }
Esempio n. 4
0
		void Write (CustomMod cm)
		{
			switch (cm.CMOD) {
			case CustomMod.CMODType.OPT :
				Write (ElementType.CModOpt);
				break;
			case CustomMod.CMODType.REQD :
				Write (ElementType.CModReqD);
				break;
			}

			Write ((int) Utilities.CompressMetadataToken (
					CodedIndex.TypeDefOrRef, cm.TypeDefOrRef));
		}
Esempio n. 5
0
		void Write (CustomMod [] customMods)
		{
			foreach (CustomMod cm in customMods)
				Write (cm);
		}
Esempio n. 6
0
        public CustomMod[] GetCustomMods(TypeReference type)
        {
            if (!(type is ModType))
                return new CustomMod [0];

            ArrayList cmods = new ArrayList ();
            TypeReference cur = type;
            while (cur is ModType) {
                if (cur is ModifierOptional) {
                    CustomMod cmod = new CustomMod ();
                    cmod.CMOD = CustomMod.CMODType.OPT;
                    cmod.TypeDefOrRef = GetTypeDefOrRefToken ((cur as ModifierOptional).ModifierType);
                    cmods.Add (cmod);
                } else if (cur is ModifierRequired) {
                    CustomMod cmod = new CustomMod ();
                    cmod.CMOD = CustomMod.CMODType.REQD;
                    cmod.TypeDefOrRef = GetTypeDefOrRefToken ((cur as ModifierRequired).ModifierType);
                    cmods.Add (cmod);
                }

                cur = (cur as ModType).ElementType;
            }

            return cmods.ToArray (typeof (CustomMod)) as CustomMod [];
        }
Esempio n. 7
0
        public TypeReference GetModifierType(CustomMod [] cmods, TypeReference type)
        {
            if (cmods == null || cmods.Length == 0)
                return type;

            TypeReference ret = type;
            for (int i = cmods.Length - 1; i >= 0; i--) {
                CustomMod cmod = cmods [i];
                TypeReference modType;

                if (cmod.TypeDefOrRef.TokenType == TokenType.TypeDef)
                    modType = GetTypeDefAt (cmod.TypeDefOrRef.RID);
                else
                    modType = GetTypeRefAt (cmod.TypeDefOrRef.RID);

                if (cmod.CMOD == CustomMod.CMODType.OPT)
                    ret = new ModifierOptional (ret, modType);
                else if (cmod.CMOD == CustomMod.CMODType.REQD)
                    ret = new ModifierRequired (ret, modType);
            }
            return ret;
        }
Esempio n. 8
0
 CustomMod ReadCustomMod(byte [] data, int pos, out int start)
 {
     CustomMod cm = new CustomMod ();
     start = pos;
     ElementType cmod = (ElementType) Utilities.ReadCompressedInteger (data, start, out start);
     if (cmod == ElementType.CModOpt)
         cm.CMOD = CustomMod.CMODType.OPT;
     else if (cmod == ElementType.CModReqD)
         cm.CMOD = CustomMod.CMODType.REQD;
     else
         cm.CMOD = CustomMod.CMODType.None;
     cm.TypeDefOrRef = Utilities.GetMetadataToken (CodedIndex.TypeDefOrRef,
         (uint) Utilities.ReadCompressedInteger (data, start, out start));
     return cm;
 }
Esempio n. 9
0
		public CustomMod [] GetCustomMods (TypeReference type)
		{
			ModType modifier = type as ModType;
			if (modifier == null)
				return CustomMod.EmptyCustomMod;

			ArrayList cmods = new ArrayList ();
			do {
				CustomMod cmod = new CustomMod ();
				cmod.TypeDefOrRef = GetTypeDefOrRefToken (modifier.ModifierType);

				if (modifier is ModifierOptional)
					cmod.CMOD = CustomMod.CMODType.OPT;
				else if (modifier is ModifierRequired)
					cmod.CMOD = CustomMod.CMODType.REQD;

				cmods.Add (cmod);
				modifier = modifier.ElementType as ModType;
			} while (modifier != null);

			return cmods.ToArray (typeof (CustomMod)) as CustomMod [];
		}
Esempio n. 10
0
		static CustomMod [] CombineCustomMods (CustomMod [] original, CustomMod [] next)
		{
			if (next == null || next.Length == 0)
				return original;

			CustomMod [] mods = new CustomMod [original.Length + next.Length];
			Array.Copy (original, mods, original.Length);
			Array.Copy (next, 0, mods, original.Length, next.Length);
			return mods;
		}