We want to connect the people who have knowledge to the people who need it, to bring together people with different perspectives so they can understand each other better, and to empower everyone to share their knowledge.
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)
Input your email to receive reset password link, or if you remember your password, you can click