StackAsk is a community where developers ask questions, share answers and learn from each others real-world experience, so every solved problem helps the next person who runs into it.
public class AdminLoginByAccountRequestData : LoginByAccountRequestData { [StringDataMember(GNParameterCode.Username, minLength = 6, maxLength = 32, mustNonNull = true)] public new string username; } public class LoginByAccountRequestData { [StringDataMember(GNParameterCode.Username, minLength = 6, maxLength = 32, mustNonNull = true)] public string username; [StringDataMember(GNParameterCode.Password, minLength = 6, maxLength = 64, mustNonNull = true)] public string password; [StringDataMember (GNParameterCode.InfoRequestParam, mustNonNull = true)] public InfoRequestParam infoRequestParam; }
public enum GNParameterCode { Username, Password, InfoRequestParam } public class InfoRequestParam { } [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)] public class StringDataMemberAttribute : Attribute { public GNParameterCode parameterCode; public int minLength; public int maxLength; public bool mustNonNull; public StringDataMemberAttribute(GNParameterCode parameterCode) { this.parameterCode = parameterCode; } public StringDataMemberAttribute(GNParameterCode parameterCode, int minLength, int maxLength, bool mustNonNull) { this.parameterCode = parameterCode; this.minLength = minLength; this.maxLength = maxLength; this.mustNonNull = mustNonNull; } } public class AdminLoginByAccountRequestData : LoginByAccountRequestData { [StringDataMember(GNParameterCode.Username, minLength = 6, maxLength = 32, mustNonNull = true)] public new string username; } public class LoginByAccountRequestData { [StringDataMember(GNParameterCode.Username, minLength = 6, maxLength = 32, mustNonNull = true)] public string username; [StringDataMember(GNParameterCode.Password, minLength = 6, maxLength = 64, mustNonNull = true)] public string password; [StringDataMember(GNParameterCode.InfoRequestParam, mustNonNull = true)] public InfoRequestParam infoRequestParam; }
class Program { public static void Main(string[] args) { // Create an instance of the class AdminLoginByAccountRequestData requestData = new AdminLoginByAccountRequestData(); requestData.username = "Hello"; requestData.password = "World"; // Get the type of the class Type type = requestData.GetType(); // Get all fields of the class FieldInfo[] fields = type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); // Loop through the fields foreach (FieldInfo field in fields) { // Check if the field has the StringDataMemberAttribute if (Attribute.IsDefined(field, typeof(StringDataMemberAttribute))) { StringDataMemberAttribute attribute = (StringDataMemberAttribute)Attribute.GetCustomAttribute(field, typeof(StringDataMemberAttribute)); // Access the attribute properties GNParameterCode parameterCode = attribute.parameterCode; int minLength = attribute.minLength; int maxLength = attribute.maxLength; bool mustNotBeNull = attribute.mustNonNull; Console.WriteLine($"Field: {field.Name} value: {field.GetValue(requestData)}"); Console.WriteLine($"ParameterCode: {parameterCode}"); Console.WriteLine($"MinLength: {minLength}"); Console.WriteLine($"MaxLength: {maxLength}"); Console.WriteLine($"MustNotBeNull: {mustNotBeNull}"); } } } }
2.2K Point(s)
1.2K Point(s)
313 Point(s)
178 Point(s)
138 Point(s)
Your account is signed in on the device(s) below. Sign out of at least one of them to continue signing in on this device.
Your account is signed in on the device(s) below. Sign out directly on one of those devices, or wait until the sign-in again time shown below.
If you cant access those devices, please contact the administrator to sign them out for you.
Input your email to receive reset password link, or if you remember your password, you can click