First of all I'd like to thank you for this great plugin.
In the following file,
EPPlus\ExcelRangeBase.cs
the following method,
public ExcelRangeBase LoadFromCollection<T>(IEnumerable<T> Collection, bool PrintHeaders, TableStyles TableStyle, BindingFlags memberFlags, MemberInfo[] Members)
There is this following code which is throwing an exception when passing a dynamic object T with known MemberInfos.
var type = typeof(T);
if (Members == null)
{
Members = type.GetProperties(memberFlags);
}
else
{
foreach (var t in Members)
{
if (t.DeclaringType != type)
{
throw (new Exception("Supplied properties in parameter Properties must be of the same type as T"));
}
}
}
Currently I have commented this code and importing the whole source code in my solution. If the 'else' part is commented out all is working well even with dynamic objects.
Do you think you could comment the else part and update the nuget? if not why do you have to check the types of individual properties? This would not allow dynamic objects to be passed using dynamic keyword.
Please let me know.
Thank you.
Comments: Hi guys, First of all thanks for the great tools for working with Excel, it works great. However i've encountered the same issue as **kslesinsky** in one of my case scenarios. When dealing with derived classes and properties, having for example: - Base class *BaseClass*, with inheritable properties *BasePropA*, *BasePropB* - Derived class *DerivedClass* which inherits *BaseClass* In the fragment of code cited here, when passing a collection of type *DerivedClass*, *type* would be *typeof(DerivedClass)*, and in the for first loop taking *t* as its member *BasePropA*, results in that *t.DeclaringType* is *typeof(BaseClass)* (since *BaseClass* is the class in which *BasePropA* was declared). Thus, when evaluating *t.DeclaringType.IsSubclassOf(type)* the code is checking whether *BaseClass* is a subclass of *DerivedClass*, which it obviously is not (the relation is the opposite) and hence ending up throwing an exception. This exception is not allowing us to pass inherited public instance properties that belong to the generic type of the IEnumerable parameter to be included in the Excel worksheet. With the above being said, I and probably a bunch of other people using the library would greatly appreciate it if this gets fixed and uploaded to nuget in the future. Thanks for taking the time to read this and hopefully fixing the issue. PS: I think you can benefit from **kslesinsky**'s code suggestion to get started.
In the following file,
EPPlus\ExcelRangeBase.cs
the following method,
public ExcelRangeBase LoadFromCollection<T>(IEnumerable<T> Collection, bool PrintHeaders, TableStyles TableStyle, BindingFlags memberFlags, MemberInfo[] Members)
There is this following code which is throwing an exception when passing a dynamic object T with known MemberInfos.
var type = typeof(T);
if (Members == null)
{
Members = type.GetProperties(memberFlags);
}
else
{
foreach (var t in Members)
{
if (t.DeclaringType != type)
{
throw (new Exception("Supplied properties in parameter Properties must be of the same type as T"));
}
}
}
Currently I have commented this code and importing the whole source code in my solution. If the 'else' part is commented out all is working well even with dynamic objects.
Do you think you could comment the else part and update the nuget? if not why do you have to check the types of individual properties? This would not allow dynamic objects to be passed using dynamic keyword.
Please let me know.
Thank you.
Comments: Hi guys, First of all thanks for the great tools for working with Excel, it works great. However i've encountered the same issue as **kslesinsky** in one of my case scenarios. When dealing with derived classes and properties, having for example: - Base class *BaseClass*, with inheritable properties *BasePropA*, *BasePropB* - Derived class *DerivedClass* which inherits *BaseClass* In the fragment of code cited here, when passing a collection of type *DerivedClass*, *type* would be *typeof(DerivedClass)*, and in the for first loop taking *t* as its member *BasePropA*, results in that *t.DeclaringType* is *typeof(BaseClass)* (since *BaseClass* is the class in which *BasePropA* was declared). Thus, when evaluating *t.DeclaringType.IsSubclassOf(type)* the code is checking whether *BaseClass* is a subclass of *DerivedClass*, which it obviously is not (the relation is the opposite) and hence ending up throwing an exception. This exception is not allowing us to pass inherited public instance properties that belong to the generic type of the IEnumerable parameter to be included in the Excel worksheet. With the above being said, I and probably a bunch of other people using the library would greatly appreciate it if this gets fixed and uploaded to nuget in the future. Thanks for taking the time to read this and hopefully fixing the issue. PS: I think you can benefit from **kslesinsky**'s code suggestion to get started.