Exemple #1
0
        public static string Serialize(Unity.PackageManager.Ivy.ModuleRepository repo)
        {
            HasErrors      = false;
            ErrorMessage   = null;
            ErrorException = null;
            Unity.PackageManager.IvyInternal.ModuleRepository repository = Cloner.CloneObject <Unity.PackageManager.IvyInternal.ModuleRepository>(repo);
            IvyRoot o = new IvyRoot {
                Repository = repository
            };
            StringBuilder builder = new StringBuilder();

            using (UTF8StringWriter writer = new UTF8StringWriter(builder))
            {
                XmlSerializable.GetSerializer(o.GetType()).Serialize(writer, o, Namespaces);
            }
            return(builder.ToString().Replace("<root>", "").Replace("</root>", ""));
        }
Exemple #2
0
        public static string Serialize(IvyModule module)
        {
            IvyParser.HasErrors      = false;
            IvyParser.ErrorMessage   = null;
            IvyParser.ErrorException = null;
            Unity.PackageManager.IvyInternal.IvyModule ivyModule = Cloner.CloneObject <Unity.PackageManager.IvyInternal.IvyModule>(module);
            IvyRoot ivyRoot = new IvyRoot();

            ivyRoot.Module = ivyModule;
            StringBuilder stringBuilder = new StringBuilder();

            using (UTF8StringWriter uTF8StringWriter = new UTF8StringWriter(stringBuilder))
            {
                XmlSerializer serializer = XmlSerializable.GetSerializer(ivyModule.GetType());
                serializer.Serialize(uTF8StringWriter, ivyModule, IvyParser.Namespaces);
            }
            return(stringBuilder.ToString().Replace("<root>", string.Empty).Replace("</root>", string.Empty));
        }
Exemple #3
0
        public static T Deserialize <T>(string xml) where T : class
        {
            IvyParser.HasErrors      = false;
            IvyParser.ErrorMessage   = null;
            IvyParser.ErrorException = null;
            if (xml.Length <= 0)
            {
                IvyParser.HasErrors    = true;
                IvyParser.ErrorMessage = "Cannot deserialize empty xml document.";
                return((T)((object)null));
            }
            Type typeFromHandle = typeof(T);
            int  startIndex     = 0;
            int  num            = xml.IndexOf("<ivy-module");
            int  num2           = xml.IndexOf("<ivy-repository");

            if (typeof(T) == typeof(IvyModule))
            {
                if (num < 0)
                {
                    return((T)((object)null));
                }
                startIndex     = num;
                typeFromHandle = typeof(IvyModule);
            }
            else if (typeof(T) == typeof(ModuleRepository))
            {
                if (num2 < 0)
                {
                    return((T)((object)null));
                }
                startIndex     = num2;
                typeFromHandle = typeof(ModuleRepository);
            }
            else if (typeof(T) == typeof(object))
            {
                if (num2 >= 0)
                {
                    startIndex     = num2;
                    typeFromHandle = typeof(ModuleRepository);
                }
                else if (num >= 0)
                {
                    startIndex     = num;
                    typeFromHandle = typeof(IvyModule);
                }
            }
            xml = xml.Insert(startIndex, "<root>") + "</root>";
            try
            {
                XmlTextReader xmlReader  = new XmlTextReader(xml, XmlNodeType.Document, null);
                XmlSerializer serializer = XmlSerializable.GetSerializer(typeof(IvyRoot));
                IvyRoot       ivyRoot    = serializer.Deserialize(xmlReader) as IvyRoot;
                T             result;
                if (typeFromHandle == typeof(IvyModule))
                {
                    result = (Cloner.CloneObject(ivyRoot.Module, typeFromHandle) as T);
                    return(result);
                }
                result = (Cloner.CloneObject(ivyRoot.Repository, typeFromHandle) as T);
                return(result);
            }
            catch (Exception errorException)
            {
                IvyParser.HasErrors      = true;
                IvyParser.ErrorMessage   = "Deserialization failed.";
                IvyParser.ErrorException = errorException;
            }
            return((T)((object)null));
        }
Exemple #4
0
 public IvyArtifact Clone() =>
 Cloner.CloneObject <IvyArtifact>(this);
Exemple #5
0
 public IvyModule Clone()
 {
     return(Cloner.CloneObject <IvyModule>(this));
 }
Exemple #6
0
 public IvyDependency Clone() =>
 Cloner.CloneObject <IvyDependency>(this);
Exemple #7
0
 public IvyInfo Clone()
 {
     return(Cloner.CloneObject <IvyInfo>(this));
 }
Exemple #8
0
 private static void CloneThing(MemberInfo thing, object target, object originValue, Type originValueType, Type targetValueType)
 {
     if ((!thing.CanWrite() || (originValue != null && !targetValueType.IsAssignableFrom(originValueType))) && typeof(IList).IsAssignableFrom(originValueType))
     {
         IList list = thing.GetValue(target) as IList;
         if (list == null && thing.CanWrite())
         {
             list = (Activator.CreateInstance(targetValueType) as IList);
             thing.SetValue(target, list);
         }
         if (list != null)
         {
             IList list2 = originValue as IList;
             foreach (object current in list2)
             {
                 if (current != null)
                 {
                     object value = Cloner.CloneObject(current, Cloner.GetElementType(list.GetType()));
                     list.Add(value);
                 }
             }
             return;
         }
     }
     if (!thing.CanWrite())
     {
         return;
     }
     if (originValue != null && !targetValueType.IsAssignableFrom(originValueType))
     {
         if (targetValueType.IsAssignableFrom(typeof(Uri)) && originValueType.IsAssignableFrom(typeof(string)))
         {
             Uri value2 = null;
             if (Uri.TryCreate((string)originValue, UriKind.RelativeOrAbsolute, out value2))
             {
                 thing.SetValue(target, value2);
             }
         }
         else if (targetValueType.IsAssignableFrom(typeof(string)) && originValueType.IsAssignableFrom(typeof(Uri)))
         {
             string value3 = string.Empty;
             if (originValue != null)
             {
                 value3 = originValue.ToString();
             }
             thing.SetValue(target, value3);
         }
         else if (targetValueType.IsAssignableFrom(typeof(PackageVersion)) && originValueType.IsAssignableFrom(typeof(string)))
         {
             try
             {
                 PackageVersion value4 = new PackageVersion((string)originValue);
                 thing.SetValue(target, value4);
             }
             catch
             {
             }
         }
         else if (targetValueType.IsAssignableFrom(typeof(string)) && originValueType.IsAssignableFrom(typeof(PackageVersion)))
         {
             string value5 = string.Empty;
             if (originValue != null)
             {
                 value5 = originValue.ToString();
             }
             thing.SetValue(target, value5);
         }
         else if (targetValueType.IsClass)
         {
             object obj = Cloner.CloneObject(originValue, targetValueType);
             if (obj == null)
             {
                 obj = thing.GetValue(target);
             }
             if (obj != null)
             {
                 thing.SetValue(target, obj);
             }
             else
             {
                 thing.SetValue(target, originValue);
             }
         }
         else if (targetValueType.IsEnum)
         {
             thing.SetValue(target, (int)originValue);
         }
     }
     else if (originValue == null)
     {
         thing.SetValue(target, originValue);
     }
     else if (targetValueType.IsClass && targetValueType != typeof(string))
     {
         object obj2 = Cloner.CloneObject(originValue, targetValueType);
         if (obj2 == null)
         {
             obj2 = thing.GetValue(target);
         }
         if (obj2 != null)
         {
             thing.SetValue(target, obj2);
         }
         else
         {
             thing.SetValue(target, originValue);
         }
     }
     else
     {
         thing.SetValue(target, originValue);
     }
 }
Exemple #9
0
        public static T Deserialize <T>(string xml) where T : class
        {
            HasErrors      = false;
            ErrorMessage   = null;
            ErrorException = null;
            if (xml.Length <= 0)
            {
                HasErrors    = true;
                ErrorMessage = "Cannot deserialize empty xml document.";
                return(null);
            }
            Type targetType = typeof(T);
            int  startIndex = 0;
            int  index      = xml.IndexOf("<ivy-module");
            int  num3       = xml.IndexOf("<ivy-repository");

            if (typeof(T) == typeof(Unity.PackageManager.Ivy.IvyModule))
            {
                if (index < 0)
                {
                    return(null);
                }
                startIndex = index;
                targetType = typeof(Unity.PackageManager.Ivy.IvyModule);
            }
            else if (typeof(T) == typeof(Unity.PackageManager.Ivy.ModuleRepository))
            {
                if (num3 < 0)
                {
                    return(null);
                }
                startIndex = num3;
                targetType = typeof(Unity.PackageManager.Ivy.ModuleRepository);
            }
            else if (typeof(T) == typeof(object))
            {
                if (num3 >= 0)
                {
                    startIndex = num3;
                    targetType = typeof(Unity.PackageManager.Ivy.ModuleRepository);
                }
                else if (index >= 0)
                {
                    startIndex = index;
                    targetType = typeof(Unity.PackageManager.Ivy.IvyModule);
                }
            }
            xml = xml.Insert(startIndex, "<root>") + "</root>";
            try
            {
                XmlTextReader xmlReader = new XmlTextReader(xml, XmlNodeType.Document, null);
                IvyRoot       root      = XmlSerializable.GetSerializer(typeof(IvyRoot)).Deserialize(xmlReader) as IvyRoot;
                if (targetType == typeof(Unity.PackageManager.Ivy.IvyModule))
                {
                    return(Cloner.CloneObject(root.Module, targetType) as T);
                }
                return(Cloner.CloneObject(root.Repository, targetType) as T);
            }
            catch (Exception exception)
            {
                HasErrors      = true;
                ErrorMessage   = "Deserialization failed.";
                ErrorException = exception;
            }
            return(null);
        }
Exemple #10
0
 public ModuleRepository Clone()
 {
     return(Cloner.CloneObject <ModuleRepository>(this));
 }
 public IvyDependencies Clone() =>
 Cloner.CloneObject <IvyDependencies>(this);
Exemple #12
0
 public IvyInfo Clone() =>
 Cloner.CloneObject <IvyInfo>(this);
Exemple #13
0
 public IvyDependency Clone()
 {
     return(Cloner.CloneObject <IvyDependency>(this));
 }
 public IvyModule Clone() =>
 Cloner.CloneObject <IvyModule>(this);
Exemple #15
0
 public IvyArtifact Clone()
 {
     return(Cloner.CloneObject <IvyArtifact>(this));
 }
Exemple #16
0
 public ModuleRepository Clone() =>
 Cloner.CloneObject <ModuleRepository>(this);
Exemple #17
0
 public IvyRepository Clone()
 {
     return(Cloner.CloneObject <IvyRepository>(this));
 }
Exemple #18
0
 public IvyRepository Clone() =>
 Cloner.CloneObject <IvyRepository>(this);