I have this bit of code that has to iterate trough a enum and make some calculations.
This is the enum
namespace PantaRei.Classes.Enums
{
public class ProductTypeA1Enum
{
#region Reports Enum
public enum Types
{
[StringValue("K01")]
K01 = 1,
[StringValue("K03")]
K03 = 2,
[StringValue("K05")]
K05 = 3,
[StringValue("M01")]
M01 = 4
}
#endregion
}
}
This is my function that takes a enum as parameter being Types the enum
GetData(ref secA1, ddr, ddrs, ProductTypeA1Enum.Types);
this is the code where I itereate through the enum
public static void GetData(ref Dars secA1, Ddr ddr, Ddrs ddrs, Enum pTypes)
{
Array typesEnum = Enum.GetValues(pTypes.GetType());
foreach (var types in typesEnum)
{
string pType = StringEnum.GetStringValue((Enum) types);
secA1.OpBal = ddrs.Out.Sum(o => o.Amount);
secA1.MiCaCol +=
ddr.Rec.Where(
rec =>
ddr.Acc.Exists(
acc =>
acc.Contract == rec.Contract && !acc.TransactionType.Equals("D9") && rec.ProductType == pType)).
Sum(rec => rec.Amount);
}
}
And this is the error I get
PantaRei.Classes.Enums.ProductTypeA1Enum.Types' is a 'type', which is not valid in the given context
The error comes from here
GetData(ref secA1, ddr, ddrs, **ProductTypeA1Enum.Types**);
Types is a enum, so why am I getting this error? Any ideas? Tks in advance Rui Martins
You should do so:
GetData(ref secA1, ddr, ddrs, typeof(ProductTypeA1Enum.Types));
and
public static void GetData(ref Dars secA1, Ddr ddr, Ddrs ddrs, Type pTypes)
{
Array typesEnum = Enum.GetValues(pTypes);
// ....
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.