示例#1
0
		/// <summary>
		/// Collects appearance data of an item using a specific constructor and parameters list
		/// </summary>
		/// <param name="type">The Type that's being instantiated</param>
		/// <param name="parameters">An array of parameters</param>
		/// <returns>An ItemDef object describing the item created, null in case of failure</returns>
		public static ItemDef GetItemDef( Type type, params object[] parameters )
		{
			ItemDef def = null;

			try
			{
				Item item = Activator.CreateInstance( type, parameters ) as Item;

				if ( item != null )
				{
					def = new ItemDef( item.ItemID, item.Hue );
					item.Internalize();
					item.Delete();
				}
			}
			catch {}

			return def;
		}
示例#2
0
        /// <summary>
        /// Collects appearance data of an item using a specific constructor and parameters list
        /// </summary>
        /// <param name="type">The Type that's being instantiated</param>
        /// <param name="parameters">An array of parameters</param>
        /// <returns>An ItemDef object describing the item created, null in case of failure</returns>
        public static ItemDef GetItemDef(Type type, params object[] parameters)
        {
            ItemDef def = null;

            try
            {
                Item item = Activator.CreateInstance(type, parameters) as Item;

                if (item != null)
                {
                    def = new ItemDef(item.ItemID, item.Hue);
                    item.Internalize();
                    item.Delete();
                }
            }
            catch {}

            return(def);
        }
示例#3
0
 /// <summary>
 /// Creates a new BoxItem object
 /// </summary>
 public BoxItem()
 {
     m_Item = new ItemDef();
 }
示例#4
0
		/// <summary>
		/// Creates a new BoxItem object
		/// </summary>
		public BoxItem()
		{
			m_Item = new ItemDef();
		}
示例#5
0
        /// <summary>
        /// Extracts a ConstructorDef from a ConstructorInfo. Assumes the constructor has at least one and not more than two parameters.
        /// </summary>
        /// <param name="info">The ConstructorInfo object to evaluate</param>
        /// <returns>A ConsturctorDef object defining the constructor in PB</returns>
        public static ConstructorDef FromConstructorInfo(ConstructorInfo ctor)
        {
            ConstructorDef def = new ConstructorDef();

            ParameterInfo[] parameters = ctor.GetParameters();

            def.m_Param1 = ParamDef.FromParameterInfo(parameters[0]);

            if (parameters.Length > 1)
            {
                def.m_Param2 = ParamDef.FromParameterInfo(parameters[1]);
            }

            // Get the default appearance for this constructor
            object def1 = null;
            object def2 = null;

            try
            {
                def1 = Activator.CreateInstance(parameters[0].ParameterType);

                if (parameters.Length > 1)
                {
                    def2             = Activator.CreateInstance(parameters[1].ParameterType);
                    def.m_DefaultArt = ItemDef.GetItemDef(ctor.DeclaringType, def1, def2);
                }
                else
                {
                    def.m_DefaultArt = ItemDef.GetItemDef(ctor.DeclaringType, def1);
                }
            }
            catch
            {
                def.m_DefaultArt = null;
            }

            // Collect enum data if needed

            if (def.m_Param1.ParamType == BoxPropType.Enumeration)
            {
                object default2 = null;
                def.m_List1 = new ArrayList();
                bool requireSecondParam = false;

                if (def.m_Param2 != null)
                {
                    requireSecondParam = true;

                    try
                    {
                        default2 = Activator.CreateInstance(parameters[1].ParameterType);
                    }
                    catch
                    {
                        default2 = null;
                    }
                }

                if (!requireSecondParam || default2 != null)
                {
                    foreach (object obj in Enum.GetValues(parameters[0].ParameterType))
                    {
                        if (default2 != null)
                        {
                            def.m_List1.Add(ItemDef.GetItemDef(ctor.DeclaringType, obj, default2));
                        }
                        else
                        {
                            def.m_List1.Add(ItemDef.GetItemDef(ctor.DeclaringType, obj));
                        }
                    }
                }
            }

            // Check param 2
            if (def.m_Param2 != null && def.m_Param2.ParamType == BoxPropType.Enumeration)
            {
                // Collect information on enumeration for parameter1
                object default1 = null;

                try
                {
                    default1 = Activator.CreateInstance(parameters[0].ParameterType);
                }
                catch
                {
                    default1 = null;
                }

                if (default1 != null)
                {
                    def.m_List2 = new ArrayList();

                    foreach (object obj in Enum.GetValues(parameters[1].ParameterType))
                    {
                        def.m_List2.Add(ItemDef.GetItemDef(ctor.DeclaringType, default1, obj));
                    }
                }
            }

            return(def);
        }