This for C#? Passing Class type as a parameter
I have a class adapter that implements an Interface. I want to fill an array structure with MyFooClass instances where MyFooClass's name or reference I want to receive it from outside. I'll instantiate them inside my adapter code.
For example:
public void FillWsvcStructs(DataSet ds, ClassType Baz)
{
IFoo.Request = ds.DataTable[0].Request;
IFoo.Modulebq = string.Empty;
IFoo.Clasific = string.Empty;
IFoo.Asignadoa = ds.DataTable[0].Referer;
IFoo.Solicita = "Jean Paul Goitier";
// Go with sub-Elems (Also "Interfaceated")
foreach (DataSet.DataTableRow ar in ds.DataTable[1])
{
if ((int) ar.StatusOT != (int)Props.StatusOT.NotOT)
{
///From HERE!
IElemRequest req = new (Baz)(); // I don't know how to do it here
///To HERE!
req.Id = string.Empty;
req.Type = string.Empty;
req.Num = string.Empty;
req.Message = string.Empty;
req.Trkorr = ar[1];
TRequest.Add(req);
}
}
}
C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...
What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.
In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.
C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.
Generics and their constraints should do what you want, I believe:
public void FillWsvcStructs<ClassType>(DataSet ds) where ClassType : IElemRequest, new()
{
IFoo.Request = ds.DataTable[0].Request;
IFoo.Modulebq = string.Empty;
IFoo.Clasific = string.Empty;
IFoo.Asignadoa = ds.DataTable[0].Referer;
IFoo.Solicita = "Jean Paul Goitier";
// Go with sub-Elems (Also "Interfaceated")
foreach (DataSet.DataTableRow ar in ds.DataTable[1])
{
if ((int) ar.StatusOT != (int)Props.StatusOT.NotOT)
{
IElemRequest req = new ClassType();
req.Id = string.Empty;
req.Type = string.Empty;
req.Num = string.Empty;
req.Message = string.Empty;
req.Trkorr = ar[1];
TRequest.Add(req);
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With