------------------------------
Question 1:
I am working with system library functions that must be standard for the occasions when I have generic parameters of type <T> and those for occasions when I do not have <T> but I have a variable.
I find that, for each function I perform, I have to do two initializing functions that end up passing a System.Type parameter to the final function that standardizes.
In order not to need to do this, I would need something like what appears in "MyFunction_Alternative". but:
- It is not valid: System.Type Source_Type = (T! = Null)? T: MyVariable.GetType ();
- It is not valid: <t?>.
I would like to see <T> Nulable, because it would solve the problem.
------------------------------
public static void Function_NoT_Ini(dynamic MyVariable)
{ System.Type Origen_Type = MyVariable.GetType();
MyFunction_(Origen_Type);
}
public static void Function_T_Ini<T>()
{ System.Type Origen_Type = typeof(T);
MyFunction_(Origen_Type);
}
private static void MyFunction_(System.Type Origen_Type)
{ System.Console.WriteLine("The values of the Enum are:");
foreach (int MyEnum_Value in System.Enum.GetValues(Origen_Type))
{ System.Console.WriteLine(MyEnum_Value);
}
}
?>.
private static void MyFunction_Alternative<T>(dynamic MyVariable)
{ System.Type Origen_Type = (T != null) ? T : MyVariable.GetType();
System.Console.WriteLine("The values of the Enum are:");
foreach (int MyEnum_Value in System.Enum.GetValues(Origen_Type))
{ System.Console.WriteLine(MyEnum_Value);
}
}
------------------------------
Question 2:
I have the problem of functions in which I need to do Cast when I don't have <T>.
Is it the right system?
------------------------------
public static void MyFunction_Cast<T>(dynamic MyVariable)
{ dynamic MyValue = 10;
T MyCast_Variable = (T)MyValue;
System.Type Origen_Type = MyVariable.GetType();
dynamic My_Second_Variable_of_MyVariable_Type = (Origen_Type)MyValue;
dynamic My_Second_Variable_of_MyVariable_Type = System.Activator.CreateInstance(Origen_Type);
My_Second_Variable_of_MyVariable_Type_ = MyValue;
}
What I have tried:
in all sites of internet.in all sites of internet.