1

I have a program in which I upload a DLL containing various types of objects. When uploaded, I create an instance of each type and save it into a Treeview (these objects may contain other objects inside). The purpose of the program is to edit these objects, so I have a propertyGrid which allows me to edit the selected object in the Treeview. This works perfectly fine for almost every object. I'm just having problems editing objects with properties whose types are List of xObjectType and this xObjectType has a yObjectType as property: For example, these classes are defined in the DLL, I have to edit FunctionCommand, however when I select the property Function in the propertyGrid a CollectionEditor pops up, this Collection Editor works fine when inner properties are of type int, string, byte[] etc. However I cannot edit properties which are more complex objects. In this case the RFunction property is disabled.

public partial class FunctionCommand
{
    /// <summary> Number of functions sent as part of the command</summary>
    public uint TotalNoOfFunctions { get; set; }

    /// <summary> Message structure for the function definition. Cloud shall always set this.</summary>
    public List<Function> Function { get; set; }

}

    public partial class Function
{
    public enum StoragePriorityENUM
    {
        LOW = 0,
        HIGH = 1,
    }

    /// <summary> Function id to uniquely identify a function</summary>
    public string FunctionId { get; set; }


    /// <summary> Set this ONLY for R function</summary>
    public RFunction RFunction { get; set; }
}

public partial class RFunction
{
    /// <summary> Diagnostics data for R function</summary>
    public DIAGData DiagData { get; set; }

    /// <summary>shall start the diagnostic process with a delay(minutes)</summary>
    public uint DelayTimeToStart { get; set; }

}

I can edit these type of objects correctly outside the CollectionEditor but not inside of it. Why does this specific property is not editable, How can I make to edit complex objects inside the CollectionEditor?

Edit: This is the way I'am creating the instances in the Treeview, this includes creating the instance of a List<> if it is necessary, The "types" variable is a list which includes all the types from the DLL:

private TreeNode GetSubTypes(Type subType, ref TreeNode rootObj, List<TreeNode> treenodeObj)
    {
        foreach (PropertyInfo prop in subType.GetProperties())
        {
            Type subtemp = null;
            Type[] temp = prop.PropertyType.GenericTypeArguments;
            if (temp.Length> 0)
            {
                subtemp = temp[0];
            }
            var childObj = new TreeNode();
            if (types.Contains(prop.PropertyType) || subtemp!=null)
            {
                childObj.Text = prop.Name;
                childObj.Tag = Activator.CreateInstance(prop.PropertyType);

                if (subtemp != null)
                {

                    var listType = typeof(List<>);
                    var constructedListType = listType.MakeGenericType(subtemp);


                    prop.SetValue(rootObj.Tag, Activator.CreateInstance(constructedListType));
                }
            }
            else
            {
                childObj.Text = prop.Name;
                childObj.Tag = "";
            }

            GetSubTypes(prop.PropertyType, ref childObj, treenodeObj);
            if(childObj.Text!="") rootObj.Nodes.Add(childObj);
            if (!usedTypes.Contains(prop.PropertyType.Name))
                usedTypes.Add(prop.PropertyType.Name);
            treenodeObj.RemoveAll(x => x.Text == prop.PropertyType.Name);
            treenodeObj.RemoveAll(x => x.Text == "");


        }
        return null;
    }

Combine 10 cycles into one in Javascript

Here's my code with cycles and I want to make it shorter (in one cycle if possible).

 function plan(piece) {

        for (i = 0; i < 10; i++) {
            piece.addStep('right');
        }
        for (i = 0; i < 9; i++) {
            piece.addStep('down');
        }
        for (i = 0; i < 8; i++) {
            piece.addStep('left');
        }
        for (i = 0; i < 7; i++) {
            piece.addStep('up');
        }
    }

etc... to i < 1

I thought about it that case,

   function plan(piece) {
     for (i=10; i>1; i--){ 
         piece.addStep('right');
         piece.addStep('down');
         piece.addStep('left');
         piece.addStep('up');
     }

but it's was wrong. Help pls!

here's look of task(maze)

here's look of task(maze)

4

0 回答 0