Exemplo n.º 1
0
        protected virtual void CheckAndSetId(object entityAsObj)
        {
            var entity1 = entityAsObj as IEntity <Guid>;

            if (entity1 != null && entity1.Id == Guid.Empty)
            {
                Type         entityType      = entityAsObj.GetType();
                PropertyInfo idProperty      = entityType.GetProperty("Id");
                var          dbGeneratedAttr = SurgingReflection.ReflectionHelper.GetSingleAttributeOrDefault <DatabaseGeneratedAttribute>(idProperty);
                if (dbGeneratedAttr == null || dbGeneratedAttr.DatabaseGeneratedOption == DatabaseGeneratedOption.None)
                {
                    entity1.Id = GuidGenerator.Create();
                }
            }
            var entity2 = entityAsObj as IEntity <string>;

            if (entity2 != null && string.IsNullOrEmpty(entity2.Id))
            {
                Type         entityType      = entityAsObj.GetType();
                PropertyInfo idProperty      = entityType.GetProperty("Id");
                var          dbGeneratedAttr = SurgingReflection.ReflectionHelper.GetSingleAttributeOrDefault <DatabaseGeneratedAttribute>(idProperty);
                if (dbGeneratedAttr == null || dbGeneratedAttr.DatabaseGeneratedOption == DatabaseGeneratedOption.None)
                {
                    entity2.Id = GuidGenerator.CreateGuidStrWithNoUnderline();
                }
            }
        }
Exemplo n.º 2
0
 public TransportMessage([NotNull] object content)
 {
     if (content == null)
     {
         throw new ArgumentNullException(nameof(content));
     }
     Id          = GuidGenerator.CreateGuidStrWithNoUnderline();
     Content     = content;
     ContentType = content.GetType().FullName;
     if (ContentType != TransportMessageType.RemoteInvokeMessage &&
         ContentType != TransportMessageType.RemoteResultMessage)
     {
         throw new ArgumentException(nameof(content));
     }
 }