コード例 #1
0
    public static void Override(Type type, EntityKindAttribute attr)
    {
        if (type == null)
        {
            throw new ArgumentNullException(nameof(attr));
        }

        if (attr == null)
        {
            throw new ArgumentNullException(nameof(attr));
        }

        dictionary.AddOrUpdate(type, attr, (t, _) => attr);
    }
コード例 #2
0
        public string GetEntityOperation()
        {
            if (this.Def.OperationCreate == null &&
                this.Def.OperationSave == null &&
                this.Def.OperationDelete == null)
            {
                return(null);
            }

            StringBuilder sb = new StringBuilder();

            sb.AppendLine($"[AutoInit]"); //Only for ReflectionServer
            sb.AppendLine($"public static class {this.TypeName}Operation");
            sb.AppendLine("{");

            if (this.Def.OperationCreate != null)
            {
                sb.AppendLine($"    public static readonly ConstructSymbol<{this.TypeName}Entity>.Simple Create = OperationSymbol.Construct<{this.TypeName}Entity>.Simple(typeof({ this.TypeName}Operation), \"Create\");");
            }


            var requiresSaveOperation = (this.Def.EntityKind != null && EntityKindAttribute.CalculateRequiresSaveOperation(this.Def.EntityKind.Value));

            if ((this.Def.OperationSave != null) && !requiresSaveOperation)
            {
                throw new InvalidOperationException($"DynamicType '{this.TypeName}' defines Save but has EntityKind = '{this.Def.EntityKind}'");
            }
            else if (this.Def.OperationSave == null && requiresSaveOperation)
            {
                throw new InvalidOperationException($"DynamicType '{this.TypeName}' does not define Save but has EntityKind = '{this.Def.EntityKind}'");
            }

            if (this.Def.OperationSave != null)
            {
                sb.AppendLine($"    public static readonly ExecuteSymbol<{this.TypeName}Entity> Save = OperationSymbol.Execute<{this.TypeName}Entity>(typeof({ this.TypeName}Operation), \"Save\");");
            }

            if (this.Def.OperationDelete != null)
            {
                sb.AppendLine($"    public static readonly DeleteSymbol<{this.TypeName}Entity> Delete = OperationSymbol.Delete<{this.TypeName}Entity>(typeof({ this.TypeName}Operation), \"Delete\");");
            }

            sb.AppendLine("}");

            return(sb.ToString());
        }