예제 #1
0
        protected List<FieldDefinition> GetFields(XmlNode messageNode)
        {
            XmlNodeList fieldNodes = messageNode.SelectNodes("field");
            List<FieldDefinition> fields = new List<FieldDefinition>();

            foreach (XmlNode field in fieldNodes)
            {
                FieldDefinition fieldDefinition = new FieldDefinition(this, field);
                if (fieldDefinition.IsValid)
                {
                    fieldDefinition.OriginalIndex = fields.Count;
                    fields.Add(fieldDefinition);
                }
            }

            // Sort fields at the beginning so we don't need to care about the ordering when serializing/deserializing
            fields.Sort((left, right) =>
            {
                int compareResult = -left.TypeSize.CompareTo(right.TypeSize);
                if (compareResult == 0)
                    return left.OriginalIndex.CompareTo(right.OriginalIndex);

                return compareResult;
            });

            return fields;
        }
예제 #2
0
 private void GenerateProperty(StringBuilder sb, FieldDefinition field, int index, int indent)
 {
     sb.AppendLine();
     AddComment(sb, field.Description, indent);
     sb.AppendLine(string.Format("{0}public {1} {2}", Indent(indent), field.Type, field.Name));
     sb.AppendLine(Indent(indent) + "{");
     sb.AppendLine(Indent(indent + 1) + "get");
     sb.AppendLine(Indent(indent + 1) + "{");
     sb.AppendLine(string.Format("{0}return ({2})_fields[{1}];", Indent(indent + 2), index, field.Type));
     sb.AppendLine(Indent(indent + 1) + "}");
     sb.AppendLine(Indent(indent + 1) + "set");
     sb.AppendLine(Indent(indent + 1) + "{");
     sb.AppendLine(string.Format("{0}if (({2})_fields[{1}] != value)", Indent(indent + 2), index, field.Type));
     sb.AppendLine(Indent(indent + 2) + "{");
     sb.AppendLine(string.Format("{0}_fields[{1}] = value;", Indent(indent + 3), index));
     sb.AppendLine(string.Format("{0}OnPropertyChanged(\"{1}\");", Indent(indent + 3), field.Name));
     sb.AppendLine(Indent(indent + 2) + "}");
     sb.AppendLine(Indent(indent + 1) + "}");
     sb.AppendLine(Indent(indent) + "}");
 }