Function that Returns Ref dynamically according to Enum assigned to dynamic

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

zequion1

Guest
The code I present simulates the functions of my program and has been checked.

I have a Function_Test_End (dynamic Parameters = null) that returns ref to a Global Static variable, which is a structure, depending on the value of the dynamic which contains an Enum indicating the type of return I want .

It is checked if the dynamic contains an Enum to determine which variable is the one requested.I need it to be a dynamic because I use it to pass more parameters from function to function, for example, Parameters [0] = Enum ... Parameters [1] = Integer Value ...

namespace Name_Referencia_Test
{
#region Initialization
public enum St_Comun_Types
{ St_Comun,
St_Comun_Ini
}
// St_Comun. Estructure.
public struct St_Comun
{ public int MyInteger;
// Constructor.
public St_Comun(bool Initialize = true) : this()
{ if (Initialize)
{ this.MyInteger = 1;
}
}
}
public static class Cls_Referencia_Test
{ // St_Comun. Static Global Variables.
public static Name_Referencia_Test.St_Comun StComun = default(Name_Referencia_Test.St_Comun);
public static Name_Referencia_Test.St_Comun StComun_Ini = new Name_Referencia_Test.St_Comun(true);
#endregion

#region Reference. Test
// ------------------------------
// FUNCTION_TESTA(). REQUEST TO FUNCTION_TESTB() RETURN REF TO STATIC GLOBAL StComun/StComun_Ini ACCORDING ENUM.
// ------------------------------
public static ref Name_Referencia_Test.St_Comun Function_TestA()
{ // StComun/StComun_Ini. Request ref according Enum.
ref Name_Referencia_Test.St_Comun StComun = ref Name_Referencia_Test.Cls_Referencia_Test.Function_TestB(Name_Referencia_Test.St_Comun_Types.St_Comun_Ini);
return ref StComun;
}
// ------------------------------
// FUNCTION_TESTB(). REQUEST TO FUNCTION_TEST_END() RETURN REF TO STATIC GLOBAL StComun/StComun_Ini ACCORDING DYNAMIC/ENUM.
// ------------------------------
public static ref Name_Referencia_Test.St_Comun Function_TestB(dynamic Parameters = null)
{ // StComun/StComun_Ini. Request ref according Enum. CORRECT.
ref Name_Referencia_Test.St_Comun StComun = ref Name_Referencia_Test.Cls_Referencia_Test.Function_Test_End(Name_Referencia_Test.St_Comun_Types.St_Comun_Ini);

// StComun/StComun_Ini. Request ref according dynamic. ERROR:"An out or ref Value must be an Assignable Variable".
ref Name_Referencia_Test.St_Comun StComun1 = ref Name_Referencia_Test.Cls_Referencia_Test.Function_Test_End(Parameters);

// StComun/StComun_Ini. Requestref according dynamic Array. CORRECT.
dynamic[] Parameters1 = new dynamic[]{ Parameters };
ref Name_Referencia_Test.St_Comun StComun2 = ref Name_Referencia_Test.Cls_Referencia_Test.Function_Test_End(Parameters1);

// StComun/StComun_Ini. Request ref according dynamic. ERROR. "An out or ref Value must be an Assignable Variable".
dynamic Parameters2 = Parameters;
ref Name_Referencia_Test.St_Comun StComun3 = ref Name_Referencia_Test.Cls_Referencia_Test.Function_Test_End(Parameters2);
return ref StComun;
}
// ------------------------------
// FUNCTION_TEST_END(). REQUEST REF TO STATIC GLOBAL StComun/StComun_Ini ACCORDING DYNAMIC WITH ENUM.
// ------------------------------
public static ref Name_Referencia_Test.St_Comun Function_Test_End(dynamic Parameters = null)
{ // StComun. Initialize.
ref Name_Referencia_Test.St_Comun StComun = ref Name_Referencia_Test.Cls_Referencia_Test.StComun;

// Asign ref StComun.
if (Parameters != null && Parameters is Name_Referencia_Test.St_Comun_Types && Parameters == Name_Referencia_Test.St_Comun_Types.St_Comun)
StComun = ref Name_Referencia_Test.Cls_Referencia_Test.StComun;

// Asign ref StComun_Ini.
if (Parameters != null && Parameters is Name_Referencia_Test.St_Comun_Types && Parameters == Name_Referencia_Test.St_Comun_Types.St_Comun_Ini)
StComun = ref Name_Referencia_Test.Cls_Referencia_Test.StComun_Ini;

return ref StComun;
}
}
#endregion

Continue reading...
 
Back
Top