Exemplo n.º 1
0
        private ValueGenerateBase CreateGenerate(GeneratedValueBaseAttribute attr, EGeneratedPurpose purpose, ValueGenerateBase source)
        {
            if (source == null && (attr.GeneratedPurpose & purpose) == purpose)
            {
                switch (attr.GeneratedOption)
                {
                case EGeneratedOption.Ignore: return(IgnoreValueGenerate);

                case EGeneratedOption.Identity: return(new ValueGenerateIdentity());

                case EGeneratedOption.Database: return(new ValueGenerateDatabase());

                case EGeneratedOption.Memory:
                    var memoryAttr = (GeneratedMemoryValueAttribute)attr;
                    return(new ValueGenerateMemory(memoryAttr.GeneratorType));

                case EGeneratedOption.Expression:
                    var expAttr = (GeneratedExpressionAttribute)attr;
                    return(new ValueGenerateExpression(expAttr.Expression));
                }
            }
            return(source);
        }
Exemplo n.º 2
0
 /// <summary>
 /// 创建表达式生成值特性。
 /// </summary>
 /// <param name="purpose">生成时的目的。</param>
 public GeneratedExpressionAttribute(EGeneratedPurpose purpose)
     : base(purpose)
 {
 }
Exemplo n.º 3
0
 /// <summary>
 /// 创建生成值特性。
 /// </summary>
 /// <param name="purpose">生成值的目的。</param>
 public GeneratedValueBaseAttribute(EGeneratedPurpose purpose)
 {
     GeneratedPurpose = purpose;
 }
Exemplo n.º 4
0
 /// <summary>
 /// 创建内存中生成值特性。
 /// </summary>
 /// <param name="generatorType">生成器类型,该类型必须实现<see cref="IMemoryValueGenerator"/>接口。</param>
 /// <param name="purpose">生成目的。</param>
 public GeneratedMemoryValueAttribute(Type generatorType, EGeneratedPurpose purpose = EGeneratedPurpose.Insert)
     : base(purpose)
 {
     GeneratorType = generatorType;
 }
Exemplo n.º 5
0
 /// <summary>
 /// 创建数据库生成值特性。
 /// </summary>
 /// <param name="purpose">生成目的。</param>
 public GeneratedValueAttribute(EGeneratedPurpose purpose = EGeneratedPurpose.Insert)
     : base(purpose)
 {
 }
Exemplo n.º 6
0
 /// <summary>
 /// 创建忽略值生成特性。
 /// </summary>
 /// <param name="purpose">生成时的目的。</param>
 public GeneratedIgnoreAttribute(EGeneratedPurpose purpose)
     : base(purpose)
 {
 }
Exemplo n.º 7
0
 public GeneratedGuidAttribute(EGeneratedPurpose purpose = EGeneratedPurpose.Insert)
     : base(purpose)
 {
     Expression = Expression.Call(null, typeof(Guid).GetMethod(nameof(Guid.NewGuid)));
 }
Exemplo n.º 8
0
 /// <summary>
 /// 创建序列生成特性。
 /// </summary>
 /// <param name="name">序列名。</param>
 /// <param name="purpose">生成目的。</param>
 public SequenceAttribute(string name, EGeneratedPurpose purpose = EGeneratedPurpose.Insert)
     : base(purpose)
 {
     Name = name;
 }
Exemplo n.º 9
0
 public GeneratedDateTimeAttribute(EGeneratedPurpose purpose = EGeneratedPurpose.Update)
     : base(purpose)
 {
     Expression = Expression.MakeMemberAccess(null, typeof(DateTime).GetProperty(nameof(DateTime.Now)));
 }