public static MakeList ( |
||
t | ||
source | System | |
Результат | System.Collections.IList |
object DecodeAttribute(Datamodel dm, bool prefix) { var type = IdToType(Reader.ReadByte()); if (!Datamodel.IsDatamodelArrayType(type)) { return(ReadValue(dm, type, EncodingVersion < 4 || prefix)); } else { var count = Reader.ReadInt32(); var inner_type = Datamodel.GetArrayInnerType(type); var array = CodecUtilities.MakeList(inner_type, count); foreach (var x in Enumerable.Range(0, count)) { array.Add(ReadValue(dm, inner_type, true)); } return(array); } }
object DecodeAttribute(Datamodel dm) { var types = IdToType(Reader.ReadByte()); if (types.Item2 == null) { return(ReadValue(dm, types.Item1, EncodingVersion < 4)); } else { var count = Reader.ReadInt32(); var inner_type = types.Item2; var array = CodecUtilities.MakeList(inner_type, count); foreach (var x in Enumerable.Range(0, count)) { array.Add(ReadValue(dm, inner_type, true)); } return(array); } }
Element Decode_ParseElement(string class_name) { string elem_class = class_name ?? Decode_NextToken(); string elem_name = null; string elem_id = null; Element elem = null; string next = Decode_NextToken(); if (next != "{") { throw new CodecException(String.Format("Expected Element opener, got '{0}'.", next)); } while (true) { next = Decode_NextToken(); if (next == "}") { break; } var attr_name = next; var attr_type_s = Decode_NextToken(); var attr_type = TypeNames.FirstOrDefault(kv => kv.Value == attr_type_s.Split('_')[0]).Key; if (elem == null && attr_name == "id" && attr_type_s == "elementid") { elem_id = Decode_NextToken(); var id = new Guid(elem_id); var local_element = DM.AllElements[id]; if (local_element != null) { elem = local_element; elem.Name = elem_name; elem.ClassName = elem_class; elem.Stub = false; } else if (elem_class != "$prefix_element$") { elem = new Element(DM, elem_name, new Guid(elem_id), elem_class); } continue; } if (attr_name == "name" && attr_type == typeof(string)) { elem_name = Decode_NextToken(); if (elem != null) { elem.Name = elem_name; } continue; } if (elem == null) { continue; } if (attr_type_s == "element") { elem.Add(attr_name, Decode_ParseElementId()); continue; } object attr_value = null; if (attr_type == null) { attr_value = Decode_ParseElement(attr_type_s); } else if (attr_type_s.EndsWith("_array")) { var array = CodecUtilities.MakeList(attr_type, 5); // assume 5 items attr_value = array; next = Decode_NextToken(); if (next != "[") { throw new CodecException(String.Format("Expected array opener, got '{0}'.", next)); } while (true) { next = Decode_NextToken(); if (next == "]") { break; } if (next == "element") // Element ID reference { array.Add(Decode_ParseElementId()); } else if (attr_type == typeof(Element)) // inline Element { array.Add(Decode_ParseElement(next)); } else // normal value { array.Add(Decode_ParseValue(attr_type, next)); } } } else { attr_value = Decode_ParseValue(attr_type, Decode_NextToken()); } if (elem != null) { elem.Add(attr_name, attr_value); } else { DM.PrefixAttributes[attr_name] = attr_value; } } return(elem); }