/// <summary> /// Implementation of the abstract base function 'Validate'. /// </summary> /// <param name="propertyMetaInfo"></param> /// <param name="parameterObject"></param> public override void Validate(PropertyMetaInfo propertyMetaInfo, ParameterBase parameterObject) { MethodBase? methodBase = MethodBase.GetCurrentMethod(); string? value; // // Make sure the 'ValidationAttribute' is assigned to the right // property type. (A string in this case) // #pragma warning disable CS8604 if (propertyMetaInfo.Type.ToLower().IndexOf("string") < 0) { propertyMetaInfo.ValidationError = new ValidationError(propertyMetaInfo, propertyMetaInfo.PropertyInfo.GetValue(parameterObject)?.ToString(), $"The attribute '{methodBase?.DeclaringType}' is not allowed on properties of type: '{propertyMetaInfo.Type}'."); return; } // // The actual validation. // value = propertyMetaInfo.PropertyInfo.GetValue(parameterObject)?.ToString(); try { var mailAddress = new System.Net.Mail.MailAddress(value); if(mailAddress.Address.LastIndexOf('.') < mailAddress.Address.LastIndexOf('@') + 2) { throw new Exception(); } } catch { propertyMetaInfo.ValidationError = new ValidationError(propertyMetaInfo, propertyMetaInfo.PropertyInfo.GetValue(parameterObject)?.ToString(), $"{ValidationErrorMessage}"); return; } #pragma warning restore CS8604 // // The validation passed. // propertyMetaInfo.ValidationError = null; }
ClassMeta CreateClassMeta(Type type, string appName, out List <Type> types, bool enableDefaultSeralize) { var isEventType = type.GetInterfaces().Where(x => x == typeof(IMQEvent)).Count() > 0; var meta = new ClassMeta() { Name = type.Name, IsEventType = isEventType, DefaultSeralize = enableDefaultSeralize }; types = new List <Type>(); foreach (var p in type.GetProperties()) { var pinfo = new PropertyMetaInfo() { Name = p.Name, Type = GetBaseTypeName(p.PropertyType.Name), SeralizeIndex = ((SeralizeIndex)p.GetCustomAttribute(typeof(SeralizeIndex), false)).Index }; if (pinfo.Type == string.Empty) { if (p.PropertyType.IsGenericType && p.PropertyType.GetInterfaces().Contains(typeof(IList))) { var s_list = PropertyMetaInfo.P_Array + separator; var t_args = p.PropertyType.GenericTypeArguments; for (var i = 0; i < t_args.Length; i++) { var pname = GetBaseTypeName(t_args[i].Name); if (string.IsNullOrEmpty(pname)) { pname = t_args[i].Name; } s_list += pname; if (i != t_args.Length - 1) { s_list += separator; } } pinfo.Type = s_list; } else if (p.PropertyType.IsArray) { var pname = p.PropertyType.Name; pname = pname.Substring(0, pname.IndexOf('[')); var name = GetBaseTypeName(pname); if (string.IsNullOrEmpty(name)) { name = pname; } pinfo.Type = PropertyMetaInfo.P_Array + separator + name; } else { if (p.PropertyType.IsEnum) { pinfo.Type = PropertyMetaInfo.P_Enum + separator + p.PropertyType.Name; } else { pinfo.Type = p.PropertyType.Name; } if (!p.PropertyType.IsSubclassOf(typeof(IMQEvent))) { types.Add(p.PropertyType); } } } var attrs = p.GetCustomAttributes(typeof(KeyIndex), false); if (attrs.Length != 0) { pinfo.Attr = new MetaAttr() { AttrType = AttrType.Index, Value = ((KeyIndex)attrs[0]).Index.ToString() } } ; meta.Properties.Add(pinfo); } return(meta); }
/// <summary> /// Initializes a new instance of the <see cref="OperationContainerHelper"/> class. /// </summary> /// <param name="containerInfo"> /// The container Info used to resolve . /// </param> /// <param name="propertyInfo"> /// The property info. /// </param> public OperationContainerHelper(Tuple <string, Guid> containerInfo, PropertyMetaInfo propertyInfo) { this.SetProperties(containerInfo, null, propertyInfo, ResolveStatus.NotResolved); }
/// <summary> /// Initializes a new instance of the <see cref="OperationContainerHelper"/> class. /// </summary> /// <param name="container"> /// The container. /// </param> /// <param name="propertyInfo"> /// The property info. /// </param> /// <param name="order"> /// The order. /// </param> public OperationContainerHelper(Thing container, PropertyMetaInfo propertyInfo, long order) { this.SetProperties(null, container, propertyInfo, ResolveStatus.Resolved); this.ContainmentSequence = order; }
/// <summary> /// Initializes a new instance of the <see cref="OperationContainerHelper"/> class. /// </summary> /// <param name="container"> /// The container. /// </param> /// <param name="propertyInfo"> /// The property info. /// </param> public OperationContainerHelper(Thing container, PropertyMetaInfo propertyInfo) { this.SetProperties(null, container, propertyInfo, ResolveStatus.Resolved); }
/// <summary> /// Set the properties from both overloaded constructors. /// </summary> /// <param name="containerInfo"> /// The container Info if applicable. /// </param> /// <param name="container"> /// The container if applicable. /// </param> /// <param name="propertyInfo"> /// The property info. /// </param> /// <param name="resolveStatus"> /// The resolve Status. /// </param> private void SetProperties(Tuple <string, Guid> containerInfo, Thing container, PropertyMetaInfo propertyInfo, ResolveStatus resolveStatus) { this.ContainerPlaceHolder = containerInfo; this.Container = container; this.PropertyInfo = propertyInfo; this.ResolveStatus = resolveStatus; }
/// <summary> /// Initializes a new instance of the <see cref="OperationContainerHelper"/> class. /// </summary> /// <param name="containerInfo"> /// The container Info. /// </param> /// <param name="propertyInfo"> /// The property info. /// </param> /// <param name="order"> /// The order. /// </param> public OperationContainerHelper(Tuple <string, Guid> containerInfo, PropertyMetaInfo propertyInfo, long order) { this.SetProperties(containerInfo, null, propertyInfo, ResolveStatus.NotResolved); this.ContainmentSequence = order; }