Esempio n. 1
0
 public IOCFactoryModel.RegistMappingContextCollection GetMappingContexts(string fileUrl)
 {
     try
     {
         var returnValue = new RegistMappingContextCollection();
         using (var fs = File.Open(fileUrl, FileMode.Open))
         {
             returnValue = this.GetMappingContexts(fs);
         }
         return returnValue;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Esempio n. 2
0
        public RegistMappingContextCollection GetMappingContexts(Stream stream)
        {
            var returnValue = new RegistMappingContextCollection();
            try
            {
                var ser = new XmlSerializer(typeof(Unity));
                var config = (Unity)ser.Deserialize(stream);

                var types = new List<UnityType>();

                foreach (var container in config.Containers)
                {

                    types.AddRange(container.Types);
                }

                foreach (var type in types)
                {
                    var newObj = new RegistMappingContext();

                    newObj.PTypeStr = type.TypeStr;

                    string cType = type.MapTo;
                    if (string.IsNullOrWhiteSpace(cType))
                    {
                        newObj.CTypeStr = newObj.PTypeStr;
                    }
                    else
                    {
                        newObj.CTypeStr = cType;
                    }

                    newObj.InstTypeStr = mapping[type.LifeTime.Type].ToString();

                    newObj.Name = type.Name;

                    returnValue.Contexts.Add(newObj);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return returnValue;
        }