Ejemplo n.º 1
0
        internal bool ConstructorEligible <T>(XType <T> xType)
        {
            Type type = typeof(T);

            return(type.CanCreateInstances() && !type.IsValueType && !type.IsArray && !XDefaultTypes.IsDefaultType(type) &&
                   xType.Component <XTexter <T> >() == null && xType.Component <XBuilderComponent <T> >() == null);
        }
Ejemplo n.º 2
0
        protected override void OnInitialized()
        {
            base.OnInitialized();
            XConstructor <ReadOnlyDictionary <TKey, TValue> > ctor = XType.Component <XConstructor <ReadOnlyDictionary <TKey, TValue> > >();

            if (ctor != null)
            {
                ctor.Enabled = false;
            }
        }
Ejemplo n.º 3
0
        protected override void OnInitialized()
        {
            base.OnInitialized();
            XConstructor <ReadOnlyCollection <T> > ctor = XType.Component <XConstructor <ReadOnlyCollection <T> > >();

            if (ctor != null)
            {
                ctor.Enabled = false;
            }
        }
Ejemplo n.º 4
0
 protected override void OnCreateXTypeLate <T>(XType <T> xType)
 {
     if (xType.Components <XTexter <T> >().Any(x => x.Enabled) ||
         xType.Components <XBuilderComponent <T> >().Any(x => x.Enabled))
     {
         XConstructor <T> ctor = xType.Component <XConstructor <T> >();
         if (ctor != null)
         {
             ctor.Enabled = false;
         }
     }
 }
Ejemplo n.º 5
0
        protected override bool OnRead <T>(IXReadOperation reader, XType <T> xType, XElement element, Func <object, bool> assign,
                                           XObjectArgs args)
        {
            Type type = typeof(T);

            // A serialized reference has no attributes, no elements, some text, is of a type that can be ID'd,
            // and not of a type that has a registered XTexter

            string value = element.Value;

            if (!element.HasAttributes &&
                !element.HasElements &&
                !string.IsNullOrEmpty(value) &&
                xType.Component <XTexter <T> >() == null &&
                Identifier.CanId(type, out Type idType))
            {
                bool   idFound = false;
                object id      = null;

                reader.Read(element, idType, x =>
                {
                    idFound = true;
                    if (!Identifier.KeyComparer.Equals(x, ReflectionTools.GetDefaultValue(idType)))
                    {
                        id = x;
                    }
                    return(true);
                },
                            XObjectArgs.DefaultIgnoreElementName);

                // Schedule a task to assign the object if it shows up in the dictionary

                reader.AddTask(this, () =>
                {
                    if (!idFound)
                    {
                        return(false);
                    }
                    if (id == null)
                    {
                        return(true);
                    }
                    if (referenceObjects.TryGetValue(id, out object refObject))
                    {
                        if (refObject == null || type == refObject.GetType())
                        {
                            return(assign(refObject));
                        }
                        else
                        {
                            throw new InvalidOperationException(
                                $"Possible collision: the reference object with ID {id} was of expected type {type.Name}, " +
                                $"but that ID resolved to an object of type {refObject.GetType().Name}.");
                        }
                    }

                    return(false);
                });

                return(true);
            }

            return(false);
        }