public TryGet <Object> Parse(XElement root, bool doMasks, out object maskObj)
        {
            if (!XmlTranslator.TranslateElementName(root.Name.LocalName, out INotifyingItemGetter <Type> t))
            {
                throw new ArgumentException($"Could not match Element type {root.Name.LocalName} to an XML Translator.");
            }
            var xml = GetTranslator(t.Value);

            return(xml.Parse(root, doMasks, out maskObj));
        }
        public void CopyIn <C>(XElement root, C item, bool doMasks, out M mask, NotifyingFireParameters?cmds)
            where C : T, INoggolloquyObjectSetter
        {
            mask = doMasks ? new M() : default(M);
            HashSet <ushort> readIndices = new HashSet <ushort>();

            try
            {
                foreach (var elem in root.Elements())
                {
                    if (!elem.TryGetAttribute("name", out XAttribute name))
                    {
                        mask.Warnings.Add("Skipping field that did not have name");
                        continue;
                    }

                    var i = item.GetNameIndex(name.Value);
                    if (!i.HasValue)
                    {
                        mask.Warnings.Add("Skipping field that did not exist anymore with name: " + name);
                        continue;
                    }

                    try
                    {
                        var    type = item.GetNthType(i.Value);
                        object subMaskObj;
                        if (item.GetNthIsNoggolloquy(i.Value))
                        {
                            if (TryGetCopyInFunction(type, out NoggXmlCopyInFunction copyInFunc))
                            {
                                if (item.GetNthIsSingleton(i.Value))
                                {
                                    copyInFunc(elem, item.GetNthObject(i.Value), cmds, doMasks, out subMaskObj);
                                }
                                else
                                {
                                    object subNogg = Activator.CreateInstance(type);
                                    copyInFunc(elem, subNogg, cmds, doMasks, out subMaskObj);
                                    item.SetNthObject(i.Value, subNogg);
                                }
                                readIndices.Add(i.Value);
                            }
                            else
                            {
                                throw new ArgumentException($"No XML Translator found for {type}");
                            }
                        }
                        else
                        {
                            if (!XmlTranslator.TryGetTranslator(type, out IXmlTranslation <object> translator))
                            {
                                throw new ArgumentException($"No XML Translator found for {type}");
                            }
                            var objGet = translator.Parse(elem, doMasks, out subMaskObj);
                            if (objGet.Succeeded)
                            {
                                item.SetNthObject(i.Value, objGet.Value);
                                readIndices.Add(i.Value);
                            }
                            else
                            {
                                mask.SetNthMask(i.Value, subMaskObj);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        if (doMasks)
                        {
                            mask.SetNthException(i.Value, ex);
                        }
                        else
                        {
                            throw;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (doMasks)
                {
                    mask.Overall = ex;
                }
                else
                {
                    throw;
                }
            }

            for (ushort i = 0; i < item.FieldCount; i++)
            {
                if (item.IsNthDerivative(i))
                {
                    continue;
                }
                if (!readIndices.Contains(i))
                {
                    item.SetNthObjectHasBeenSet(i, false);
                }
            }
        }
        public void Write(XmlWriter writer, string name, T item, bool doMasks, out M mask)
        {
            using (new ElementWrapper(writer, item.NoggolloquyName))
            {
                if (!string.IsNullOrEmpty(name))
                {
                    writer.WriteAttributeString("name", name);
                }
                mask = doMasks ? new M() : default(M);

                try
                {
                    for (ushort i = 0; i < item.FieldCount; i++)
                    {
                        try
                        {
                            if (!item.GetNthObjectHasBeenSet(i))
                            {
                                continue;
                            }

                            var    type = item.GetNthType(i);
                            object subMaskObj;
                            if (item.GetNthIsNoggolloquy(i))
                            {
                                if (TryGetWriteFunction(type, out NoggXmlWriteFunction writeFunc))
                                {
                                    writeFunc(writer, item.GetNthName(i), item.GetNthObject(i), doMasks, out subMaskObj);
                                }
                                else
                                {
                                    throw new ArgumentException($"No XML Translator found for {type}");
                                }
                            }
                            else
                            {
                                if (!XmlTranslator.TryGetTranslator(type, out IXmlTranslation <object> translator))
                                {
                                    throw new ArgumentException($"No XML Translator found for {type}");
                                }
                                translator.Write(writer, item.GetNthName(i), item.GetNthObject(i), doMasks, out subMaskObj);
                            }

                            if (subMaskObj != null)
                            {
                                mask.SetNthMask(i, subMaskObj);
                            }
                        }
                        catch (Exception ex)
                        {
                            if (doMasks)
                            {
                                mask.SetNthException(i, ex);
                            }
                            else
                            {
                                throw;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (doMasks)
                    {
                        mask.Overall = ex;
                    }
                    else
                    {
                        throw;
                    }
                }
            }
        }
 public bool Validate(Type t)
 {
     return(XmlTranslator.Validate(t));
 }
 public IXmlTranslation <Object> GetTranslator(Type t)
 {
     return(XmlTranslator.GetTranslator(t).Value.Value);
 }