private bool IsValidRequirement(RequiredComponentAttribute attrib) { Type reqType = attrib.RequiredComponentType; TypeInfo reqTypeInfo = reqType.GetTypeInfo(); // Ignore requirements to non-exported / internal types, as // Duality will ignore them as well. if (reqTypeInfo.IsNotPublic) { return(false); } // Ignore requirements to non-Components TypeInfo componentTypeInfo = typeof(Component).GetTypeInfo(); if (!reqTypeInfo.IsInterface && !componentTypeInfo.IsAssignableFrom(reqTypeInfo)) { return(false); } return(true); }
private void AddCreationChainElements(ComponentRequirementMap map, RequiredComponentAttribute attrib, Type subChainType) { if (subChainType == this.Component) { return; } int baseIndex = this.CreationChain.Count; int subChainLength = 0; // Retrieve the creation sub-chain to satisfy this item's requirements List <CreationChainItem> createTypeSubChain = map.GetCreationChain(subChainType); foreach (CreationChainItem subItem in createTypeSubChain) { this.CreationChain.Add(subItem); subChainLength++; } // Add the main item after its requirement items so we're always creating bottom-up this.CreationChain.Add(new CreationChainItem { RequiredType = attrib.RequiredComponentType, CreateType = attrib.CreateDefaultType }); // If this is a conditional requirement, add a control item that checks the // requirement and skips this item and its sub-chains if it's already met. if (subChainLength > 0 && attrib.CreateDefaultType != attrib.RequiredComponentType) { this.CreationChain.Insert(baseIndex, new CreationChainItem { RequiredType = attrib.RequiredComponentType, SkipIfExists = 1 + subChainLength }); } }