A Zero Element Array is not a [0] it is a []

  • Thread starter Thread starter zequion1
  • Start date Start date
Z

zequion1

Guest
I am doing a function that returns the default of any type of variable, but I have a problem with arrays.


I have modified the code thanks to the answers I have received and now I only have the problem that, for example, the default of System.DateTime[2] returns it as System.DateTime[0] instead of System.DateTime[]. I need the output to be correct because it is a standard function that generates values that other functions check.

What is System.DateTime[0], I can't make sense of it.

Here I show the execution of the program:The Proof

public static System.Array Fcn_CreateInstance_Array(dynamic Origen, dynamic lengths_dyn = null)
{ System.Array MyArray_Retorno = null;
System.Type MyType_Empleo = null, MyType_GenericTypeDefinition = null;
int lengths = 0;

System.Type MyType = Origen.GetType(); // {Name = "DateTime[]" FullName = "System.DateTime[]"}
try{ MyType_GenericTypeDefinition = Origen.GetGenericTypeDefinition(); } catch(System.Exception ErrorExcp){}

if (MyType_GenericTypeDefinition != null) MyType_Empleo = MyType_GenericTypeDefinition;
else MyType_Empleo = MyType;

if (lengths_dyn == null) lengths = 0;
else lengths = (int)lengths_dyn;

MyArray_Retorno = (System.Array)System.Activator.CreateInstance(MyType_Empleo, new object[]{ (int)lengths }); // {System.DateTime[0]} BAD, Y NEED System.DateTime[].

return MyArray_Retorno;
}

Continue reading...
 
Back
Top