I stored in an array the types of 2 objects that I'm passing as arguments.
I´m trying to cast them in a loop but it doesn't seem to work.
I noticed when I debug that the value of the object's Type (returned by key.GetType()), it shows Name=RunTimeType FullName=System.RuntimeType
instead of the expected Name=Label
.
I'm not sure what am I doing wrong. Any suggestions?
public static void GetUserGUIDandSID(string username, Object b, Object c) {
PrincipalContext ctx = new PrincipalContext(ContextType.Domain,
"domainName.com");
UserPrincipal user = (UserPrincipal.FindByIdentity(ctx, username));
var empIdNum = user.Guid.Value;
var empSID = user.Sid.Value;
List<object> types = new List<object>();
types.Add(b.GetType());
types.Add(c.GetType());
foreach(var key in types) {
if (key.GetType() == typeof(Label)) {
((Label)b).FontSize = 10;
((Label)b).Content = empIdNum;
}
if (key.GetType() == typeof(TextBox)) {
((TextBox)b).FontSize = 10;
((TextBox)b).Text = empIdNum.ToString();
}
if (key.GetType() == typeof(TextBlock)) {
((TextBlock)b).FontSize = 10;
((TextBlock)b).Text = empIdNum.ToString();
}
}
}