c# - Getting an array with the content of attributes -
i have class in code in c# want attributes nested class in array size of number of parameters , content of of them in array of objects. these:
class myclass { class parameters { public const string = "a"; public const string b = "b"; public const string c = "c"; public const string d = "d"; public const string e = "e"; public const string f = "f"; } public object[] getallparameters() { object[] array = new object[6]; array[0] = parameters.a; array[1] = parameters.b; array[2] = parameters.c; array[3] = parameters.d; array[4] = parameters.e; array[5] = parameters.f; } //more methods , code
}
but if want add together example, g
, h
parameters, have update size of method getallparameters
, initialization , more stuff in other parts of code.
could "getallparameters
" method more generic, without taking business relationship of explicit parameters? reflection maybe?
because fields constants, don't need object instance utilize null
in getvalue
. - these fields, not properties.
var fields = typeof(parameters).getfields(); object[] array = new object[fields.count()]; (int = 0; < fields.count(); i++) { array[i] = fields[i].getvalue(null); } homecoming array;
c#
No comments:
Post a Comment