internal MutableAmbientProperty(MutableItem owner, AmbientPropertyInfo info)
     : base(owner, StObjMutableReferenceKind.AmbientProperty)
 {
     _info      = info;
     Type       = _info.PropertyType;
     IsOptional = _info.IsOptional;
 }
 internal MutableInjectObject(MutableItem owner, InjectObjectInfo info)
     : base(owner, StObjMutableReferenceKind.RealObject)
 {
     InjecttInfo = info;
     Type        = InjecttInfo.PropertyType;
     IsOptional  = InjecttInfo.IsOptional;
 }
Ejemplo n.º 3
0
 internal void AddInterfaceMapping(Type t, MutableItem m, MutableItem finalType)
 {
     Debug.Assert(t.IsInterface);
     _map.Add(t, finalType);
     _map.Add(new RealObjectInterfaceKey(t), m);
     finalType.RealObjectType.AddUniqueMapping(t);
 }
 /// <summary>
 /// Initializes a new marker object: the ambient property has not been found.
 /// A marker is not used.
 /// </summary>
 internal MutableAmbientProperty(MutableItem owner, string unexistingPropertyName)
     : base(owner, StObjMutableReferenceKind.AmbientProperty)
 {
     _info      = null !;
     Type       = typeof(object);
     IsOptional = false;
     _maxSpecializationDepthSet = Int32.MaxValue;
 }
Ejemplo n.º 5
0
 internal void AddClassMapping(Type t, MutableItem m)
 {
     Debug.Assert(t.IsClass);
     _map.Add(t, m);
     if (t != m.RealObjectType.Type)
     {
         m.RealObjectType.AddUniqueMapping(t);
     }
 }
Ejemplo n.º 6
0
 internal MutableParameter(MutableItem owner, ParameterInfo param, bool isContainer)
     : base(owner, isContainer
                     ? StObjMutableReferenceKind.ConstructParameter | StObjMutableReferenceKind.Container
                     : StObjMutableReferenceKind.ConstructParameter)
 {
     _param     = param;
     Type       = param.ParameterType;
     IsOptional = param.IsOptional;
     if (IsSetupLogger)
     {
         StObjRequirementBehavior = Setup.StObjRequirementBehavior.None;
     }
 }
Ejemplo n.º 7
0
        internal void RegisterServiceFinalObjectMapping(Type t, CKTypeInfo typeInfo)
        {
            Debug.Assert(typeInfo is RealObjectClassInfo);
            var         c       = (RealObjectClassInfo)typeInfo;
            MutableItem mapping = c.AutoServiceImpl;

            if (mapping == null)
            {
                c.AutoServiceImpl = mapping = _map[typeInfo.Type];
                _serviceRealObjects.Add(mapping);
            }
            _serviceToObjectMap.Add(t, mapping);
        }
 internal MutableReference(MutableItem owner, StObjMutableReferenceKind kind)
 {
     Owner = owner;
     _kind = kind;
     if (_kind == StObjMutableReferenceKind.Requires ||
         _kind == StObjMutableReferenceKind.Group ||
         _kind == StObjMutableReferenceKind.RealObject ||
         (_kind & StObjMutableReferenceKind.Container) != 0)
     {
         StObjRequirementBehavior = StObjRequirementBehavior.ErrorIfNotStObj;
     }
     else
     {
         Debug.Assert((_kind & StObjMutableReferenceKind.ConstructParameter) != 0 ||
                      _kind == StObjMutableReferenceKind.RequiredBy ||
                      _kind == StObjMutableReferenceKind.AmbientProperty);
         StObjRequirementBehavior = StObjRequirementBehavior.None;
     }
 }
 internal MutableReferenceList(MutableItem owner, StObjMutableReferenceKind kind)
 {
     _owner = owner;
     _kind  = kind;
 }
 internal TrackedAmbientPropertyInfo(MutableItem o, AmbientPropertyInfo p)
 {
     Owner = o;
     AmbientPropertyInfo = p;
 }
Ejemplo n.º 11
0
        RealObjectCollectorResult GetRealObjectResult()
        {
            List <MutableItem>           allSpecializations = new List <MutableItem>(_roots.Count);
            StObjObjectEngineMap         engineMap          = new StObjObjectEngineMap(_names, allSpecializations, KindDetector, _assemblies);
            List <List <MutableItem> >   concreteClasses    = new List <List <MutableItem> >();
            List <IReadOnlyList <Type> >?classAmbiguities   = null;
            List <Type> abstractTails    = new List <Type>();
            var         deepestConcretes = new List <(MutableItem, ImplementableTypeInfo)>();

            Debug.Assert(_roots.All(info => info != null && !info.IsExcluded && info.Generalization == null),
                         "_roots contains only not Excluded types.");
            foreach (RealObjectClassInfo newOne in _roots)
            {
                deepestConcretes.Clear();
                newOne.CreateMutableItemsPath(_monitor, _serviceProvider, engineMap, null, _tempAssembly, deepestConcretes, abstractTails);
                if (deepestConcretes.Count == 1)
                {
                    MutableItem last = deepestConcretes[0].Item1;
                    allSpecializations.Add(last);
                    var path = new List <MutableItem>();
                    last.InitializeBottomUp(null);
                    path.Add(last);
                    MutableItem?spec = last, toInit = last;
                    while ((toInit = toInit.Generalization) != null)
                    {
                        toInit.InitializeBottomUp(spec);
                        path.Add(toInit);
                        spec = toInit;
                    }
                    path.Reverse();
                    concreteClasses.Add(path);
                    foreach (var m in path)
                    {
                        engineMap.AddClassMapping(m.RealObjectType.Type, last);
                    }
                }
                else if (deepestConcretes.Count > 1)
                {
                    List <Type> ambiguousPath = new List <Type>()
                    {
                        newOne.Type
                    };
                    ambiguousPath.AddRange(deepestConcretes.Select(m => m.Item1.RealObjectType.Type));

                    if (classAmbiguities == null)
                    {
                        classAmbiguities = new List <IReadOnlyList <Type> >();
                    }
                    classAmbiguities.Add(ambiguousPath.ToArray());
                }
            }
            Dictionary <Type, List <Type> >?interfaceAmbiguities = null;

            foreach (var path in concreteClasses)
            {
                MutableItem finalType = path[path.Count - 1];
                finalType.RealObjectType.InitializeInterfaces(_monitor, this);
                foreach (var item in path)
                {
                    foreach (Type itf in item.RealObjectType.ThisRealObjectInterfaces)
                    {
                        MutableItem?alreadyMapped;
                        if ((alreadyMapped = engineMap.RawMappings.GetValueOrDefault(itf)) != null)
                        {
                            if (interfaceAmbiguities == null)
                            {
                                interfaceAmbiguities = new Dictionary <Type, List <Type> >
                                {
                                    { itf, new List <Type>()
                                      {
                                          itf, alreadyMapped.RealObjectType.Type, item.RealObjectType.Type
                                      } }
                                };
                            }
                            else
                            {
                                var list = interfaceAmbiguities.GetOrSet(itf, t => new List <Type>()
                                {
                                    itf, alreadyMapped.RealObjectType.Type
                                });
                                list.Add(item.RealObjectType.Type);
                            }
                        }
                        else
                        {
                            engineMap.AddInterfaceMapping(itf, item, finalType);
                        }
                    }
                }
            }
            return(new RealObjectCollectorResult(engineMap,
                                                 concreteClasses,
                                                 classAmbiguities ?? (IReadOnlyList <IReadOnlyList <Type> >)Array.Empty <IReadOnlyList <Type> >(),
                                                 interfaceAmbiguities != null
                                                    ? interfaceAmbiguities.Values.Select(list => list.ToArray()).ToArray()
                                                    : Array.Empty <IReadOnlyList <Type> >(),
                                                 abstractTails));
        }
Ejemplo n.º 12
0
 public ListInjectSingleton(MutableItem item)
 {
     _item  = item;
     _count = _item.RealObjectType.InjectObjects.Count;
 }
Ejemplo n.º 13
0
 public ListAmbientProperty(MutableItem item)
 {
     _item  = item;
     _count = _item.RealObjectType.AmbientProperties.Count;
 }
Ejemplo n.º 14
0
#pragma warning disable CS8618 // Non-nullable field is uninitialized. Consider declaring as nullable.
            public LeafData(MutableItem leaf, List <MutableAmbientProperty> ap, MutableInjectObject[] ac)
            {
                LeafSpecialization   = leaf;
                AllAmbientProperties = ap;
                AllInjectObjects     = ac;
            }
Ejemplo n.º 15
0
 internal MutableReferenceOptional(MutableItem owner, StObjMutableReferenceKind kind)
     : base(owner, kind)
 {
     _resolved = UnresolvedMarker;
 }
Ejemplo n.º 16
0
        private bool HandleStObjPropertySource(IActivityMonitor monitor, StObjProperty p, MutableItem source, string sourceName, bool doSetOrMerge)
        {
            StObjProperty?c = source.GetStObjProperty(p.Name);

            // Source property is defined somewhere in the source.
            if (c != null)
            {
                // If the property is explicitly defined (Info != null) and its type is not
                // compatible with our, there is a problem.
                if (c.InfoOnType != null && !p.Type.IsAssignableFrom(c.Type))
                {
                    // It is a warning because if actual values work, everything is okay... but one day, it should fail.
                    var msg = String.Format("StObjProperty '{0}.{1}' of type '{2}' is not compatible with the one of its {6} ('{3}.{4}' of type '{5}'). Type should be compatible since {6}'s property value will be propagated if no explicit value is set for '{7}.{1}' or if '{3}.{4}' is set with an incompatible value.",
                                            ToString(), p.Name, p.Type.Name,
                                            source.RealObjectType.Type.Name, c.Name, c.Type.Name,
                                            sourceName,
                                            RealObjectType.Type.Name);
                    monitor.Warn(msg);
                }
                if (doSetOrMerge)
                {
                    // The source value must have been set and not explicitly "removed" with a System.Type.Missing value.
                    if (c.Value != System.Type.Missing)
                    {
                        // We "Set" the value from this source.
                        if (!p.ValueHasBeenSet)
                        {
                            p.Value = c.Value;
                        }
                        else if (p.Value is IMergeable)
                        {
                            using (var services = new SimpleServiceContainer())
                            {
                                services.Add(monitor);
                                if (!((IMergeable)p.Value).Merge(c.Value, services))
                                {
                                    monitor.Error($"Unable to merge StObjProperty '{ToString()}.{p.Value}' with value from {sourceName}.");
                                }
                            }
                        }
                        return(true);
                    }
                }
            }
            return(false);
        }