Example #1
0
        /// Add reference to .NET assembly specified either by filename or by name
        public Assembly AddReference(string from, string name, bool embed, bool forceLoad, string loadIfStartsWith)
        {
            bool add = true;

            foreach (var r in _references)
            {
                if (!string.IsNullOrEmpty(from) && r.From == from)
                {
                    if (!forceLoad)
                    {
                        return(null);
                    }
                    add = false;
                }
                if (!string.IsNullOrEmpty(name) && r.Name == name)
                {
                    if (!forceLoad)
                    {
                        return(null);
                    }
                    add = false;
                }
            }
            var rNew = new Ref {
                From = from, Name = name, Embed = embed
            };

            if (add)
            {
                _references.Add(rNew);
            }

            foreach (var a in AppDomain.CurrentDomain.GetAssemblies())
            {
                if (!string.IsNullOrEmpty(name) && a.FullName == name)
                {
                    return(a);
                }
            }

            if (forceLoad)
            {
                return(rNew.ForceLoad(_verboseWriter));
            }
            if (loadIfStartsWith != null)
            {
                _notLoadedReferences.Add(rNew, loadIfStartsWith);
            }
            return(null);
        }