Exemplo n.º 1
0
 public static void AddCilHint(IHasMetaTable target, ICilHint hint)
 {
     if (target.Meta.ContainsKey(Loader.CilHintsKey))
         target.Meta.AddTo(Loader.CilHintsKey, hint.ToMetaEntry());
     else
         target.Meta[Loader.CilHintsKey] = (MetaEntry) new[] {hint.ToMetaEntry()};
 }
Exemplo n.º 2
0
        public static void SetCilHint(IHasMetaTable target, ICilHint newHint)
        {
            MetaEntry cilHints;
            if (target.Meta.TryGetValue(Loader.CilHintsKey, out cilHints))
            {
                var hints = cilHints.List;
                var replaced = false;
                var excessHints = 0;
                for (var i = 0; i < hints.Length; i++)
                {
                    var cilHint = hints[i].List;

                    //We're only interested in CIL hints that conflict with the new one.
                    if (!Engine.StringsAreEqual(cilHint[0].Text, newHint.CilKey))
                        continue;


                    if (replaced)
                    {
                        hints[i] = null;
                        excessHints++;
                    }
                    else
                    {
                        hints[i] = newHint.ToMetaEntry();
                        replaced = true;
                    }
                }

                if (excessHints == 0)
                {
                    if (!replaced)
                        target.Meta.AddTo(Loader.CilHintsKey, newHint.ToMetaEntry());
                    //otherwise the array has already been modified by ref.
                }
                else
                {
                    //need to resize array (and possibly add new CIL hint)
                    var newHints = new MetaEntry[hints.Length - excessHints + (replaced ? 0 : 1)];
                    int idxNew;
                    int idxOld;
                    for (idxNew = idxOld = 0; idxOld < hints.Length; idxOld++)
                    {
                        var oldHint = hints[idxOld];
                        if (oldHint == null)
                            continue;

                        newHints[idxNew++] = oldHint;
                    }
                    if (!replaced)
                        newHints[idxNew] = newHint.ToMetaEntry();

                    target.Meta[Loader.CilHintsKey] = (MetaEntry) newHints;
                }
            }
            else
            {
                target.Meta[Loader.CilHintsKey] = (MetaEntry) new[] {newHint.ToMetaEntry()};
            }
        }