четверг, 28 сентября 2023 г.

GS, Serialization, Shedevr

public static T BuildTypeWithCollectionInside<T, TKey, TItem>(XDocument xdoc, string root)

            where T : class, IHaveCollection<TKey, TItem>, IHaveUri

            where TItem : class, IHaveKey<TKey>

        {

            T t = null;

            try

            {

                t = DeSerialization2<T>(xdoc, root);

                if (t == null)

                    throw new NullReferenceException("Deserialization Failure");

                if (t is IHaveUri uri && t is IHaveCollection<TKey, TItem> collection)

                {

                    var items = GetElements(xdoc, uri.XPath);

                    foreach (var i in items)

                    {

                        var ty = Type.GetType(i.TypeName, false, true);

                        if (Serialization.Do.DeSerialize(ty, i.XElement, null) is TItem s)

                            collection.Register(s);

                    }

                }

            }

            catch (Exception e)

            {

                 // throw new Exception("Builder DeSerialization Failure in " + root + " " + e.Message);

                 ConsoleSync.WriteLineT($@"{e}");

            }

            return t;

        }

Комментариев нет:

Отправить комментарий