Free Support Forum - aspose.com

ICustomTypeDesciptor support

Why WorkbookDesigner doesn’t support ICustomTypeDesciptor implementors?
As I understand WorkbookDesigner uses object.GetType().GetProperties() instead of TypeDescriptor.GetProperties(object). Other framework and tools uses TypeDescriptor (MonoRail, ASP.NET MVC, all bindable DevExpress controls).

Hi,

We will get back to you soon for your query.

Thank you.

Hi,

could you please explain more why you want to use ICustomTypeDesciptor. We will check whether
WorkbookDesigner can support your need.


Thank you.


We are using light weight structures that simply holds two arrays - array of column names and array of column values (DataRow uses same approach). For DataBinding purposes we should publish our ‘properties’. As you see from example Row class doesn’t have properties at all, but .net have special abstarctioan for such a cases ICustomTypeDescriptor (there are many implementors of it and you are using at least one of them DataRowView). ICustomTypeDescriptor let you emulate Properties via GetProperties method. see example - and client side (who want to bind my data) should be aware of this or any other extension interface.

[TestFixture]
public class CustomTypeDescriptorTests
{
[Test]
public void can_emulate_properties()
{
var row = new Row();
foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(row))
{
Console.WriteLine(property.Name);
Console.WriteLine(property.GetValue(row));
}
}
}
public class Row:ICustomTypeDescriptor
{
readonly string[] columns = new[]{“Name”,“Age”,“DoB”};
readonly object[] values = new object[]{ “John”, 25, DateTime.Now };

#region Implementation of ICustomTypeDescriptor

public AttributeCollection GetAttributes()
{
return null;
}

public string GetClassName()
{
return null;
}

public string GetComponentName()
{
return null;
}

public TypeConverter GetConverter()
{
return null;
}

public EventDescriptor GetDefaultEvent()
{
return null;
}

public PropertyDescriptor GetDefaultProperty()
{
return null;
}

public object GetEditor(Type editorBaseType)
{
return null;
}

public EventDescriptorCollection GetEvents()
{
return null;
}

public EventDescriptorCollection GetEvents(Attribute[] attributes)
{
return null;
}

public PropertyDescriptorCollection GetProperties()
{
var props = columns.Select(column => new ColumnDescriptor(column));
return new PropertyDescriptorCollection(props.ToArray());
}

public class ColumnDescriptor:PropertyDescriptor
{
public ColumnDescriptor(string column):base(column, null)
{

}

#region Overrides of PropertyDescriptor

public override bool CanResetValue(object component)
{
return false;
}

public override object GetValue(object component)
{
var row = (Row) component;
var indexOfColumnValue = Array.IndexOf(row.columns,Name);
return row.values[indexOfColumnValue];
}

public override void ResetValue(object component)
{

}

public override void SetValue(object component, object value)
{

}

public override bool ShouldSerializeValue(object component)
{
return false;
}

public override Type ComponentType
{
get { return typeof(object); }
}

public override bool IsReadOnly
{
get { return true; }
}

public override Type PropertyType
{
get { return ComponentType; }
}

#endregion
}

public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{
return GetProperties();
}

public object GetPropertyOwner(PropertyDescriptor pd)
{
return this;
}

#endregion
}

Hi,

Thanks for providing us some details.

We will check and get back to you soon.

Thank you.

Hi,

After some analysis, I am afraid, we cannot support it soon.

Please simply convert data to custom objects or database now.


See following sample code for custom objects:

public class Person

{

private string m_Name;

public string Name

{

get { return m_Name; }

set { m_Name = value; }

}

private int m_Age;

public int Age

{

get { return m_Age; }

set { m_Age = value; }

}

public Person(string name, int age)

{

this.m_Name = name;

this.m_Age = age;

}

}

internal void TestSmart()

{

WorkbookDesigner designer = new WorkbookDesigner();

designer.Open(@"F:\FileTemp\SmartMarker1.xls");

ArrayList list = new ArrayList();

list.Add(new Person("simon", 30));

list.Add(new Person("Johnson", 33));

designer.SetDataSource("Person", list);

designer.Process(false);

designer.Save(@"F:\FileTemp\dest.xls");



For reference, please see the document: http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/smart-markers.html


Thank you.

Where can I find Issue tracker for submit my feature request?

Hi,

Well, I am afraid, you cannot access our issue tracking system. It is an internal system used to track issues for the products among the developers worldwide. You can post your feature requests via forum posts, we will analyze your request and add your feature request to the system assigning an id with description for the issue. You may inquire about the status of any issue using its id and we will keep you updated about its status.


Thanks for your understanding!

It is a very bad practice to hide from your customers.
Look around and you will see that other component and tools developers (DevExpress, Infragistics, JetBrains) never hide details from customers

I have logged your feature request and will provide a plan for this feature tommorrow.

We will add a new method:

WorkbookDesigner.SetDataSource(ICustomTypeDescriptor data)

In your ICustomTypeDescriptor implementation class, you will return a row of data or multi-rows of data.

Can that serve your need?

Hi, nice to see positive feedback :slight_smile:

Actually I need this method
void SetDataSource(IEnumerable data) where T : ICustomTypeDescriptor

And if you do that you got DataView or DataTable.DefaultView for free :slight_smile:
List rows = new List();

SetDataSource(rows);
and
DataView view = new DataView();
SetDataSource(view.Cast());
PS
code for Row class see above

Hello Laurence!
I want to clarify my position.

We are developed a high performance OLAP engine. And volume of data, which we processing is a very huge (about 5-10Millions of input data records). As you can see performance is a very important concern for us that’s why we had choose yours great product for outputing calculated data.

First reply from Aspose staff was: hey guys simply covert your data into datatable. no problem.
here is code (warning live programming here:) )
//create table
var dataTable = new DataTable();
//Create columns
foreach (var descriptor in TypeDescriptor.GetProperties(Rows[0])) //we simply choose first row
{
dataTable.Columns.Add(descriptor.Name,desciptor.ComponentType)
}
//Fill data
foreach(var row in Rows)
{
//add array of values from our row class
//dataTable.Rows.Add(row.Values)
//or via
desciptor.GetValue(row) // you can save descriptor per data column
}

but we simply can’t do that. DataTable is a very HUGE object it holds a reference to DataView(defaultview property), which creates RedBlack tree under the hood.
And row memory limit for datatable with 40 column is about 600-800 thousands of DataRows.
Our internal DataTable class allow us to load about 5-8M rows on x86.

My feature is not a simply dynamic properties - from ComponentModel attributes you can build a strong reporting infrastructure.

For example:
[Browsable] - for showing/hiding columns
[Description] - for columnNames
[Category] - for column grouping
etc

Sincerely yours
.
Sergey Mirvoda



Hi,

Please try the attached version.

We have supported this feature.

If you still have any problem, please post your template file and sample project. We will check it soon.



Thank you.


Wow.
I’ll check and submit my expressions as soon as possible.

Thank you guys. It’s quite the thing!