Пример #1
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);
        }
Пример #2
0
		/// <summary>
		/// Extracts a ParamDef object from a ParameterInfo
		/// </summary>
		/// <param name="pInfo">The ParameterInfo object containing information about a constructor parameter</param>
		/// <returns>A ParamDef object</returns>
		public static ParamDef FromParameterInfo( ParameterInfo pInfo )
		{
			ParamDef def = new ParamDef();

			def.m_Name = pInfo.Name;
			def.m_ParamType = BoxProp.GetPropType( pInfo.ParameterType );

			if ( pInfo.ParameterType.IsEnum )
			{
				def.m_EnumValues = new ArrayList();
				def.m_EnumValues.AddRange( Enum.GetNames( pInfo.ParameterType ) );
			}

			return def;
		}
Пример #3
0
		/// <summary>
		/// Creates a control for a parameter
		/// </summary>
		/// <param name="param">The type of the parameter that will be displayed</param>
		/// <param name="location">The location at which the control should be added</param>
		/// <returns>An IParam object that's been added to the control</returns>
		private IParam AddParam( ParamDef param, Point location )
		{
			UserControl c = null;

			switch ( param.ParamType )
			{
				case BoxPropType.Boolean:

					c = new BoolParam();
					break;

				case BoxPropType.DateTime:

					c = new DateTimeParam();
					break;

				case BoxPropType.Enumeration:

					c = new EnumParam();
					( c as EnumParam ).EnumValues = param.EnumValues;
					( c as EnumParam ).EnumValueChanged += new EventHandler(ConstructorsViewer_EnumValueChanged);
					break;

				case BoxPropType.Map:

					c = new MapParam();
					break;

				case BoxPropType.Numeric:

					c = new NumericParam();
					break;

				case BoxPropType.Other:

					c = new TextParam();
					( c as TextParam ).IsOther = true;
					break;

				case BoxPropType.Point3D:

					c = new Point3DParam();
					break;

				case BoxPropType.Text:

					c = new TextParam();
					break;

				case BoxPropType.TimeSpan:

					c = new TimeSpanParam();
					break;
			}

			( c as IParam ).ParamName = param.Name;
			c.Location = location;
			Controls.Add( c );

			return c as IParam;
		}