Regarding Properties  
Author Message
K.S.RamakrishnaPrasanna





PostPosted: Visual C# General, Regarding Properties Top

Hi,

I have a problem can any one help me ASAP

I have developed a property which is of type collection, it works fine if i access that property with coding, when i try to access the property at design time it shows me not marked as Serializable if i add this attribute it is asking for DeSerialize.

How to Serialize and DeSerialize the Property with collections, I have created a class that class I am using as Collection in my usercontrol, class code as below :

File Name : DGVDataSource.cs

 

using System;

using System.Collections.Generic;

using System.ComponentModel.Design.Serialization;

using System.Text;

namespace IrsGrid

{

public class DGVDataSource

{

private DGVColumnType _dgvColumnType;

private DGVColumnSourceType _dgvColumnSourceType;

private String[] _dgvColumnSource;

private String _dgvColumnCaption;

public DGVDataSource()

{

_dgvColumnType = DGVColumnType.TextboxColumn;

_dgvColumnSourceType = DGVColumnSourceType.Array;

_dgvColumnSource = null;

_dgvColumnCaption = null;

}

public DGVDataSource(

DGVColumnType dgvColumnType,

DGVColumnSourceType dgvColumnSourceType,

String dgvColumnSource,

String dgvColumnCaption)

{

_dgvColumnType = dgvColumnType;

_dgvColumnSourceType = dgvColumnSourceType;

char[] sep = ",".ToCharArray();

_dgvColumnSource = dgvColumnSource.Split(sep);

_dgvColumnCaption = dgvColumnCaption;

}

public DGVDataSource(

DGVColumnType dgvColumnType,

DGVColumnSourceType dgvColumnSourceType,

String[] dgvColumnSource,

String dgvColumnCaption)

{

_dgvColumnType = dgvColumnType;

_dgvColumnSourceType = dgvColumnSourceType;

_dgvColumnSource = dgvColumnSource;

_dgvColumnCaption = dgvColumnCaption;

}

public DGVColumnType dgvColumnType

{

set { _dgvColumnType = value; }

get { return _dgvColumnType; }

}

public DGVColumnSourceType dgvDataSourceType

{

set { _dgvColumnSourceType = value; }

get { return _dgvColumnSourceType; }

}

public String[] dgvColumnSource

{

set { _dgvColumnSource = value; }

get { return _dgvColumnSource; }

}

public String dgvColumnCaption

{

set { _dgvColumnCaption = value; }

get { return _dgvColumnCaption; }

}

}

}

 

Thanks




Visual C#15  
 
 
TaylorMichaelL





PostPosted: Visual C# General, Regarding Properties Top

Assuming that DGVDataSource is the object in the collection you're trying to serialize then you can specify the Serializable attribute on the class to have it serialized. Of course all fields must also be serializable. You didn't specify the types for your custom DGV- types so I can't verify them. Try this:

[Serializable]
public class DGVDataSource
{
...
}

Note that you can not serialize abstract or interface fields so you'll have to handle that case if it occurs.

Michael Taylor - 11/27/06


 
 
K.S.RamakrishnaPrasanna





PostPosted: Visual C# General, Regarding Properties Top

Thanks for the replay.

I am really sorry i have not told this earlier, if i put serializable attribute the form which is having my user control is expecting the deserialization and it is not showing error not showing any controls on the form,I donot know how to do serialization & deserialization at form design time.

Thanks



 
 
TaylorMichaelL





PostPosted: Visual C# General, Regarding Properties Top

Ok now I'm confused. Are you having problems serializing/deserializing an object to a stream or are you having problems generating designer code for your control They are distinct processes. S/D involves converting your object (any object) to XML (or binary) and storing in a stream. The designer involves generating code in the appropriate method to create and initialize your control. This simply involves the creation of your code followed by the assignment of values to each of its properties. For the designer the Serializable attribute has no effect.

Michael Taylor - 11/28/06


 
 
K.S.RamakrishnaPrasanna





PostPosted: Visual C# General, Regarding Properties Top

Basically i have developed control which collection as property when i add objects I have problem in generating the designer code. If you can give me your e-mail id i will send you full code with proper description.



 
 
TaylorMichaelL





PostPosted: Visual C# General, Regarding Properties Top

My e-mail address is "anti-spammed" in my profile. Click on my user name to get the address. I'll take a look at it.

Michael Taylor - 11/29/06


 
 
K.S.RamakrishnaPrasanna





PostPosted: Visual C# General, Regarding Properties Top

Thanks & Regards



 
 
TaylorMichaelL





PostPosted: Visual C# General, Regarding Properties Top

For others looking for the answer the code was modified and returned to the OP and it worked. The problem lied in the fact that a custom designer serializer was being used. It was not needed. Removing the custom serializer and the serialization attributes on the classes resolved the issue.

Michael Taylor - 12/12/06