public IEditable CloneAsEditable(bool frozen) { var c = new EditableObject(factory, schema, nullable); c.Set(this); if (frozen) { c.Freeze(); } return(c); }
public IEditable Create(Schema schema, bool nullable) { if (schema == null) { throw new ArgumentNullException("schema"); } if (EditablePrimitive.IsSupportedType(schema.DataType)) { var x = new EditablePrimitive(this, schema, nullable); if (!nullable && schema.DataType == DataType.Choice && schema.DeclarationItem != null) { var defaults = schema.DeclarationItem.NavigateTo(FieldPath.Create("Data", "Defaults")); if (!defaults.IsNull && defaults.Count > 0) { x.Set(defaults.GoTo(0).Get <int>()); } } return(x); } if (schema.DataType == DataType.Class) { if (schema == Schema.BuiltIn[BuiltInSchema.Variable]) { return(new EditableVariable(this, nullable)); } var x = new EditableObject(this, schema, nullable); if (!nullable && schema.DeclarationItem != null) { } return(x); } else if (schema.DataType == DataType.List || schema.DataType == DataType.MultiChoice) { var x = new EditableList(this, schema, nullable); if (!nullable && schema.DataType == DataType.MultiChoice && schema.DeclarationItem != null) { var defaults = schema.DeclarationItem.NavigateTo(FieldPath.Create("Data", "Defaults")); foreach (var d in defaults.Children) { x.Add().Set(d.Get <int>()); } } return(x); } else { throw new ArgumentException("Unsupported schema specified", "schema"); } }
protected virtual int CalculateSerializedSize() { int variableSize = this.IsNull ? 0 : EditablePrimitive.GetTotalFieldSize(this.DataSize); return(EditableObject.CalculateSerializedSize(this.Schema, variableSize)); }