public ActionResult EditProperty(int id, int mid) { var model = new GeneratedProperty { }; if (id > -1) { model = repo.GetGeneratedProperty().FirstOrDefault(x => x.ID == id); } ViewBag.mid = mid; return(View(model)); }
public override CodeGeneratedMethod CreateParseMethodBody(ParserCodeGenContext context) { // We have to implement two items: The table class and the overall "read" method. // Let's start with the read method. string className = "structReader_" + Guid.NewGuid().ToString("n"); string classDefinition; // Implement the class { // Build up a list of property overrides. var propertyOverrides = new List <GeneratedProperty>(); for (int index = 0; index < this.Members.Count; ++index) { var value = this.Members[index]; PropertyInfo propertyInfo = value.PropertyInfo; Type propertyType = propertyInfo.PropertyType; GeneratedProperty generatedProperty = new GeneratedProperty(context.Options, index, propertyInfo); var propContext = context.With(offset: $"({context.OffsetVariableName} + {value.Offset})", inputBuffer: "buffer"); // These are always inline as they are only invoked from one place. generatedProperty.ReadValueMethodDefinition = $@" [MethodImpl(MethodImplOptions.AggressiveInlining)] private static {CSharpHelpers.GetCompilableTypeName(propertyType)} {generatedProperty.ReadValueMethodName}({context.InputBufferTypeName} buffer, int offset) {{ return {propContext.GetParseInvocation(propertyType)}; }} "; propertyOverrides.Add(generatedProperty); } classDefinition = CSharpHelpers.CreateDeserializeClass( className, this.ClrType, propertyOverrides, context.Options); } return(new CodeGeneratedMethod { ClassDefinition = classDefinition, MethodBody = $"return new {className}<{context.InputBufferTypeName}>({context.InputBufferVariableName}, {context.OffsetVariableName});", }); }
public ActionResult EditProperty(int mid, GeneratedProperty gp) { var success = false; var message = string.Empty; var _id = -1; try { if (ModelState.Any(x => x.Value.Errors.Any())) { var errs = string.Join("<br/>", ModelState.SelectMany(x => x.Value.Errors.Select(xx => "<br/>" + xx.ErrorMessage))); throw new Exception(errs); } if (gp.ID < 1) { var mod = repo.GetGeneratedModel().Where(x => x.ID == mid).FirstOrDefault(); if (DuplicateProperty(mod.Name, mod)) { throw new Exception("duplicate property: " + mod.Name); } mod.Properties.Add(gp); } else { var mod = repo.GetGeneratedProperty().Where(x => x.ID == gp.ID).FirstOrDefault(); mod.Name = gp.Name; mod.Type = gp.Type; } repo.SaveChanges(); _id = gp.ID; } catch (Exception ex) { message = ex.Message; } return(Json(new { success = true, message = message, id = _id })); }
public void DeleteGeneratedProperty(GeneratedProperty gp) { throw new NotImplementedException(); //repo.GeneratedProperty.Remove(gp); }
public void AddGeneratedProperty(GeneratedProperty gp) { throw new NotImplementedException(); //repo.GeneratedProperty.Add(gp); }