private void InitializePropertyDescriptorTypes()
        {
            var typeInfos = CandidateTypes
                            .Select(x => x.Value).ToList();

            foreach (var item in typeInfos)
            {
                var typeProperties = item.GetProperties();
                foreach (var propInfo in typeProperties)
                {
                    var attr = propInfo.GetCustomAttribute <PropertyDescriptorAttribute>();
                    if (attr != null)
                    {
                        var attribute = attr as PropertyDescriptorAttribute;
                        if (attr.CompossibleItem != CompossibleItemTypes.Unset)
                        {
                            List <PropertyInfo> props = new List <PropertyInfo>();
                            if (DescriptorProperties.TryGetValue(item, out props))
                            {
                                props.Add(propInfo);
                            }
                            else
                            {
                                DescriptorProperties.Add(item, new List <PropertyInfo> {
                                    propInfo
                                });
                            }
                        }
                    }
                }
            }
        }
        public Type GetMetadata(string fullName)
        {
            if (string.IsNullOrEmpty(fullName))
            {
                return(null);
            }

            Type predefinedType = null;

            if (TypeCoreExtensions.PredefinedTypes.TryGetValue(fullName, out predefinedType))
            {
                return(predefinedType);
            }

            Type cacheType = null;

            if (CandidateTypes.TryGetValue(fullName, out cacheType))
            {
                return(cacheType);
            }

            Type resolvedType = CurrentAssembly.GetType(fullName);

            if (resolvedType != null)
            {
                return(resolvedType);
            }

            throw new ArgumentOutOfRangeException($"Sepecified known type could not be found! {Environment.NewLine}");
        }
Exemplo n.º 3
0
        static MyConveyorSorter()
        {
            drainAll        = new MyTerminalControlOnOffSwitch <MyConveyorSorter>("DrainAll", MySpaceTexts.Terminal_DrainAll);
            drainAll.Getter = (block) => block.DrainAll;
            drainAll.Setter = (block, val) => block.DrainAll = val;
            drainAll.EnableToggleAction();
            MyTerminalControlFactory.AddControl(drainAll);

            MyTerminalControlFactory.AddControl(new MyTerminalControlSeparator <MyConveyorSorter>());

            blacklistWhitelist = new MyTerminalControlCombobox <MyConveyorSorter>("blacklistWhitelist", MySpaceTexts.BlockPropertyTitle_ConveyorSorterFilterMode, MySpaceTexts.Blank);
            blacklistWhitelist.ComboBoxContent = (block) => FillBlWlCombo(block);
            blacklistWhitelist.Getter          = (block) => (long)(block.IsWhitelist ? 1 : 0);
            blacklistWhitelist.Setter          = (block, val) => block.ChangeBlWl(val == 1);
            blacklistWhitelist.SetSerializerBit();
            blacklistWhitelist.SupportsMultipleBlocks = false;
            MyTerminalControlFactory.AddControl(blacklistWhitelist);

            currentList                        = new MyTerminalControlListbox <MyConveyorSorter>("CurrentList", MySpaceTexts.BlockPropertyTitle_ConveyorSorterFilterItemsList, MySpaceTexts.Blank, true);
            currentList.ListContent            = (block, list1, list2) => block.FillCurrentList(list1, list2);
            currentList.ItemSelected           = (block, val) => block.SelectFromCurrentList(val);
            currentList.SupportsMultipleBlocks = false;
            MyTerminalControlFactory.AddControl(currentList);

            removeFromSelectionButton = new MyTerminalControlButton <MyConveyorSorter>("removeFromSelectionButton",
                                                                                       MySpaceTexts.BlockPropertyTitle_ConveyorSorterRemove,
                                                                                       MySpaceTexts.Blank,
                                                                                       (block) => block.RemoveFromCurrentList());
            removeFromSelectionButton.Enabled = (x) => x.m_selectedForDelete != null && x.m_selectedForDelete.Count > 0;;
            removeFromSelectionButton.SupportsMultipleBlocks = false;
            MyTerminalControlFactory.AddControl(removeFromSelectionButton);

            candidates                        = new MyTerminalControlListbox <MyConveyorSorter>("candidatesList", MySpaceTexts.BlockPropertyTitle_ConveyorSorterCandidatesList, MySpaceTexts.Blank, true);
            candidates.ListContent            = (block, list1, list2) => block.FillCandidatesList(list1, list2);
            candidates.ItemSelected           = (block, val) => block.SelectCandidate(val);
            candidates.SupportsMultipleBlocks = false;
            MyTerminalControlFactory.AddControl(candidates);

            addToSelectionButton = new MyTerminalControlButton <MyConveyorSorter>("addToSelectionButton",
                                                                                  MySpaceTexts.BlockPropertyTitle_ConveyorSorterAdd,
                                                                                  MySpaceTexts.Blank,
                                                                                  (x) => x.AddToCurrentList());
            addToSelectionButton.SupportsMultipleBlocks = false;
            addToSelectionButton.Enabled = (x) => x.m_selectedForAdd != null && x.m_selectedForAdd.Count > 0;
            MyTerminalControlFactory.AddControl(addToSelectionButton);

            byte index = 0;//warning: if you shuffle indexes, you will shuffle data in saved games

            CandidateTypes.Add(++index, new Tuple <MyObjectBuilderType, StringBuilder>(typeof(MyObjectBuilder_AmmoMagazine), MyTexts.Get(MySpaceTexts.DisplayName_ConvSorterTypes_Ammo)));
            CandidateTypes.Add(++index, new Tuple <MyObjectBuilderType, StringBuilder>(typeof(MyObjectBuilder_Component), MyTexts.Get(MySpaceTexts.DisplayName_ConvSorterTypes_Component)));
            CandidateTypes.Add(++index, new Tuple <MyObjectBuilderType, StringBuilder>(typeof(MyObjectBuilder_PhysicalGunObject), MyTexts.Get(MySpaceTexts.DisplayName_ConvSorterTypes_HandTool)));
            CandidateTypes.Add(++index, new Tuple <MyObjectBuilderType, StringBuilder>(typeof(MyObjectBuilder_Ingot), MyTexts.Get(MySpaceTexts.DisplayName_ConvSorterTypes_Ingot)));
            CandidateTypes.Add(++index, new Tuple <MyObjectBuilderType, StringBuilder>(typeof(MyObjectBuilder_Ore), MyTexts.Get(MySpaceTexts.DisplayName_ConvSorterTypes_Ore)));
            foreach (var val in CandidateTypes)
            {
                CandidateTypesToId.Add(val.Value.Item1, val.Key);
            }
        }
Exemplo n.º 4
0
 static MyConveyorSorter()
 {
     byte index = 0;//warning: if you shuffle indexes, you will shuffle data in saved games
     CandidateTypes.Add(++index, new Tuple<MyObjectBuilderType, StringBuilder>(typeof(MyObjectBuilder_AmmoMagazine), MyTexts.Get(MySpaceTexts.DisplayName_ConvSorterTypes_Ammo)));
     CandidateTypes.Add(++index, new Tuple<MyObjectBuilderType, StringBuilder>(typeof(MyObjectBuilder_Component), MyTexts.Get(MySpaceTexts.DisplayName_ConvSorterTypes_Component)));
     CandidateTypes.Add(++index, new Tuple<MyObjectBuilderType, StringBuilder>(typeof(MyObjectBuilder_PhysicalGunObject), MyTexts.Get(MySpaceTexts.DisplayName_ConvSorterTypes_HandTool)));
     CandidateTypes.Add(++index, new Tuple<MyObjectBuilderType, StringBuilder>(typeof(MyObjectBuilder_Ingot), MyTexts.Get(MySpaceTexts.DisplayName_ConvSorterTypes_Ingot)));
     CandidateTypes.Add(++index, new Tuple<MyObjectBuilderType, StringBuilder>(typeof(MyObjectBuilder_Ore), MyTexts.Get(MySpaceTexts.DisplayName_ConvSorterTypes_Ore)));
     foreach (var val in CandidateTypes)
     {
         CandidateTypesToId.Add(val.Value.Item1, val.Key);
     }
 }
        private void ResolveTypes()
        {
            if (_lookupAssemblies == null)
            {
                throw new ArgumentNullException(nameof(_lookupAssemblies));
            }

            var cachedTypeList = new List <Type>();

            foreach (var item in _lookupAssemblies)
            {
                cachedTypeList.AddRange(item.GetTypes()
                                        .Where(x => TypeHelper.IsCompositeType(x) || TypeHelper.IsViewModel(x)).ToList());
            }

            foreach (var type in cachedTypeList)
            {
                CandidateTypes.Add(type.FullName, type);
            }
        }
        private void InitializeDbModelNavigationProperties()
        {
            var typeInfos = CandidateTypes.Where(x => TypeHelper.IsEntity(x.Value))
                            .Select(x => x.Value.GetTypeInfo()).ToList();

            var excludeTypeList = new List <string>
            {
                nameof(EntityBase),
                nameof(IObjectState),
            };

            foreach (var item in typeInfos)
            {
                if (excludeTypeList.Contains(item.Name))
                {
                    continue;
                }

                Type itemType         = item.AsType();
                var  checkGenericType = itemType.GetGenericArguments();
                if (checkGenericType != null && checkGenericType.Count() > 0)
                {
                    itemType = itemType.GetGenericArguments()[0];
                }

                var props = item.AsType().GetProperties();

                foreach (var prop in props)
                {
                    Type   underlyingType           = null;
                    string fullname                 = prop.PropertyType.FullName;
                    bool   isCollection             = false;
                    EntityTypeDefinition definition = new EntityTypeDefinition();
                    if (typeof(ICollection <IObjectState>).IsAssignableFrom(prop.PropertyType) ||
                        typeof(IEnumerable <IObjectState>).IsAssignableFrom(prop.PropertyType))
                    {
                        isCollection   = true;
                        underlyingType = prop.PropertyType.GetGenericArguments()[0];
                        fullname       = underlyingType.FullName;
                    }
                    if (underlyingType == null && TypeHelper.IsEntity(prop.PropertyType))
                    {
                        underlyingType = prop.PropertyType;
                    }

                    if (underlyingType != null)
                    {
                        definition.PropertyName = prop.Name;
                        definition.IsCollection = isCollection;
                        definition.Metadata     = fullname;
                        List <EntityTypeDefinition> definitions = new List <EntityTypeDefinition>();
                        if (NavigationProperties.TryGetValue(itemType.FullName, out definitions))
                        {
                            definitions.Add(definition);
                        }
                        else
                        {
                            definitions = new List <EntityTypeDefinition> {
                                definition
                            };
                            NavigationProperties.Add(itemType.FullName, definitions);
                        }
                    }
                }
            }
        }