示例#1
0
        private void OnMetadataMismatch(string stName, string propName, MetadataMismatchType mmType, String detail = null)
        {
            var message = MetadataStore.Instance.OnMetadataMismatch(stName, propName, mmType, detail);

            if (message.IsError)
            {
                _errorMessages.Add(message);
            }
        }
        internal Message OnMetadataMismatch(String entityTypeName, String propertyName, MetadataMismatchType mmType, String detail = null)
        {
            EventHandler <MetadataMismatchEventArgs> handler = MetadataMismatch;
            var allow = (AllowedMetadataMismatchTypes & mmType) > 0;
            var args  = new MetadataMismatchEventArgs()
            {
                StructuralTypeName   = entityTypeName,
                PropertyName         = propertyName,
                MetadataMismatchType = mmType,
                Detail = detail,
                Allow  = allow
            };

            if (handler != null)
            {
                try {
                    handler(this, args);
                    allow = args.Allow;
                }
                catch {
                    // Eat any handler exceptions but throw later.
                    allow = false;
                }
            }
            // don't allow NotAllowable thru no matter what the dev says.
            allow = allow && (MetadataMismatchType.NotAllowable & mmType) == 0;
            return(AddMessage(args.Message, allow ? MessageType.Message : MessageType.Error, false));
        }