[CLOSED] How to add Guid[] property to the component?

  1. #1

    [CLOSED] How to add Guid[] property to the component?

    Hello!

    I need to add array of GUID to some components. I had override property:
            ....
    
            public Guid[] Guids
            {
                get; set;
            }
    
    
            [Browsable(false)]
            [EditorBrowsable(EditorBrowsableState.Never)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
            [XmlIgnore]
            [JsonIgnore]
            public override ConfigOptionsCollection ConfigOptions
            {
                get
                {
                    ConfigOptionsCollection list = base.ConfigOptions;
    
                    list.Add("guids", null, this.Guids));
    
                    return list;
                }
            }
    
            ....
    I expect get JS of constructor like:

    new Ext.Component({
      ...
      guids: ["E5224141-DECE-444C-AA53-629C04880339", "EA3020DD-D8D3-4264-934D-A56111D61E08", "0BB07B1D-F955-48E5-B888-5AD9D9F47BBD"]
      ...
    })
    But my new property wasn't setted. All that I get the error:

    Unsupported type: System.Guid[]. Use the JsonSerializer class to get the object's JSON representation.
    It's happend at line:
    var script = panel.ToScript(RenderMode.AddTo, modalEditor ? "Viewport1" : "TabPanel1");
    I am sure that property has been setted and value wasn't Null. I create component from code and get them JS code by method this.ToScript().

    How add similar (array of GUID) property correctly?

    At this time I use workaround:
             var guidArray = JsonConvert.SerializeObject(this.LinkedItems);
    
             list.Add("linkedItems",
                             new ConfigOption("linkedItems", 
                                 new SerializationOptions("linkedItems", JsonMode.Raw),                              
                                 null,
                                 guidArray));
    I think it's bad practice.

    Thanks!
    Last edited by Daniil; May 02, 2011 at 10:29 AM. Reason: [CLOSED]
  2. #2
    Hi,

    Personally, your workaround is good.

    Another way is:

    public string[] Guids
    and
    list.Add("guids", 
            new ConfigOption
            (
                "guids",
                new SerializationOptions("guids", JsonMode.Array), 
                null, 
                this.Guids
            )
    );
    Here is the full example.

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <%@ Import Namespace="System" %>
    <%@ Import Namespace="System.Collections.Generic" %>
    <%@ Import Namespace="System.ComponentModel" %>
    <%@ Import Namespace="System.Drawing" %>
    <%@ Import Namespace="System.Web.UI" %>
    <%@ Import Namespace="System.Web.UI.WebControls" %>
    <%@ Import Namespace="System.Xml.Serialization" %>
    <%@ Import Namespace="Newtonsoft.Json" %>
    
    <script runat="server">
        class MyControl : Ext.Net.Panel
        {
            public override string Title
            {
                get
                {
                    return "Test";
                }
            }
            
            public override string Html
            {
                get
                {
                    return this.Guids.ToString();
                }
            }
            
            public string[] Guids
            {
                get;
                set;
            }
    
            [Browsable(false)]
            [EditorBrowsable(EditorBrowsableState.Never)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
            [XmlIgnore]
            [JsonIgnore]
            public override ConfigOptionsCollection ConfigOptions
            {
                get
                {
                    ConfigOptionsCollection list = base.ConfigOptions;
             
                    list.Add("guids", 
                            new ConfigOption
                            (
                                "guids",
                                new SerializationOptions("guids", JsonMode.Array), 
                                null, 
                                this.Guids
                            )
                    );
             
                    return list;
                }
            }
        }
    
        protected void Page_Load(object sender, EventArgs e)
        {
            MyControl mc = new MyControl()
            {
                ID = "MyControl1"
            };
    
            string[] guids = { Guid.NewGuid().ToString(), Guid.NewGuid().ToString() };
            mc.Guids = guids;
    
            this.Container1.Items.Add(mc);
        }
    </script>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.Net Example</title>
    </head>
    <body>
        <form runat="server">
        <ext:ResourceManager runat="server" />
        <ext:Container ID="Container1" runat="server" />
        <ext:Button runat="server" Text="Get .guids">
            <Listeners>
                <Click Handler="alert(Ext.encode(MyControl1.guids));" />
            </Listeners>
        </ext:Button>
        </form>
    </body>
    </html>
  3. #3
    Thanks, Daniil!

    I hoped that exist options or attributes, that will help convert Guid[] automaticly. But seems I was wrong. Thank for consultation!
  4. #4
    Another two ways.

    1. Your own ExtJsonConverter. See, for example, AutoLoadParamsJsonConverter in Ext.Net sources. And
    new SerializationOptions(typeof(AutoLoadParamsJsonConverter))
    2. Or additional proxy property. See, for example, AutoLoadParamsProxy in StoreBase.cs. By the way, there is also AutoLoadParamsJsonConverter.
    [ConfigOption("autoLoad", typeof(AutoLoadParamsJsonConverter))]
    protected ParameterCollection AutoLoadParamsProxy

Similar Threads

  1. Replies: 2
    Last Post: Jun 24, 2010, 9:17 PM
  2. SQL GUID USE AT GRID PANEL
    By sadeque in forum 1.x Help
    Replies: 1
    Last Post: Feb 03, 2010, 3:32 AM
  3. GUID in Ext:Label.Text property...
    By shaun in forum 1.x Help
    Replies: 2
    Last Post: Jul 26, 2009, 8:14 PM
  4. Replies: 1
    Last Post: Jun 17, 2009, 4:47 PM
  5. Replies: 1
    Last Post: May 22, 2009, 7:38 AM

Tags for this Thread

Posting Permissions