public override object Read(object value, ProtoReader source) { int field = source.FieldNumber; BasicList list = new BasicList(); if (packedWireType != WireType.None && source.WireType == WireType.String) { SubItemToken token = ProtoReader.StartSubItem(source); while (ProtoReader.HasSubValue(packedWireType, source)) { list.Add(Tail.Read(null, source)); } ProtoReader.EndSubItem(token, source); } else { do { list.Add(Tail.Read(null, source)); } while (source.TryReadFieldHeader(field)); } int oldLen = AppendToCollection ? ((value == null ? 0 : ((Array)value).Length)) : 0; Array result = Array.CreateInstance(itemType, oldLen + list.Count); if (oldLen != 0) { ((Array)value).CopyTo(result, 0); } list.CopyTo(result, oldLen); return(result); }
public override object Read(object value, ProtoReader source) { int field = source.FieldNumber; BasicList basicList = new BasicList(); if (packedWireType != WireType.None && source.WireType == WireType.String) { SubItemToken token = ProtoReader.StartSubItem(source); while (ProtoReader.HasSubValue(packedWireType, source)) { basicList.Add(base.Tail.Read(null, source)); } ProtoReader.EndSubItem(token, source); } else { do { basicList.Add(base.Tail.Read(null, source)); }while (source.TryReadFieldHeader(field)); } int num = AppendToCollection ? ((value != null) ? ((Array)value).Length : 0) : 0; Array array = Array.CreateInstance(itemType, num + basicList.Count); if (num != 0) { ((Array)value).CopyTo(array, 0); } basicList.CopyTo(array, num); return(array); }
public override object Read(object value, ProtoReader source) { int fieldNumber = source.FieldNumber; BasicList list = new BasicList(); if ((this.packedWireType != WireType.None) && (source.WireType == WireType.String)) { SubItemToken token = ProtoReader.StartSubItem(source); while (ProtoReader.HasSubValue(this.packedWireType, source)) { list.Add(base.Tail.Read(null, source)); } ProtoReader.EndSubItem(token, source); } else { do { list.Add(base.Tail.Read(null, source)); }while (source.TryReadFieldHeader(fieldNumber)); } int offset = this.AppendToCollection ? ((value == null) ? 0 : ((Array)value).Length) : 0; Array array = Array.CreateInstance(this.itemType, (int)(offset + list.Count)); if (offset != 0) { ((Array)value).CopyTo(array, 0); } list.CopyTo(array, offset); return(array); }
public BasicList <string> GetList(string strFirst, bool showErrors = true) { string tempStr; tempStr = Body; if (tempStr == "") { throw new CustomBasicException("Blank list"); } var tGetList = new BasicList <string>(); do { if (DoesExist(strFirst) == false) { if (tGetList.Count == 0) { if (showErrors == true) { throw new ParserException("There are no items on the list", EnumMethod.GetList) { OriginalBody = tempStr, RemainingHtml = Body, FirstTag = strFirst } } } ; tGetList.Add(Body); Body = tempStr; return(tGetList); } tGetList.Add(GetTopInfo(strFirst)); Body = GetBottomInfo(strFirst, true); }while (true); }
public CacheMultiShard(CacheShard first) { if (first == null) { throw new ArgumentNullException("first"); } count = first.Count; if (count != ShardSize) { throw new ArgumentException("First shard must be exactly full", "first"); } shards.Add(first); }
public BasicList <string> GetList(string strFirst, string strSecond, bool showErrors = true) { string tempStr; tempStr = Body; if (tempStr == "") { throw new CustomBasicException("Blank list"); } var tGetList = new BasicList <string>(); string thisItem; do { if (DoesExist(strFirst, strSecond) == false) { if (tGetList.Count == 0) { if (showErrors == true) { throw new ParserException("There are no items on the list", EnumMethod.GetList) { OriginalBody = tempStr, RemainingHtml = Body, FirstTag = strFirst, SecondTag = strSecond } } } ; Body = tempStr; return(tGetList); } thisItem = GetSomeInfo(strFirst, strSecond, true); tGetList.Add(thisItem); }while (true); }
internal void SetKeyedObject(int key, object value) { if (key-- == Root) { if (value == null) { throw new ArgumentNullException("value"); } if (rootObject != null && ((object)rootObject != (object)value)) { throw new ProtoException("The root object cannot be reassigned"); } rootObject = value; } else { BasicList list = List; if (key < list.Count) { if (!ReferenceEquals(list[key], value)) { throw new ProtoException("Reference-tracked objects cannot change reference"); } } else if (key != list.Add(value)) { throw new ProtoException("Internal error; a key mismatch occurred"); } } }
void ReadSInstance(ProtoReader reader, SInstance sInstance, CLS_Environment environment) { List <CLS_Content.Value> values; List <string> keywords; GetSortMembers(sInstance, out values, out keywords); int fieldNumber = 0; while ((fieldNumber = reader.ReadFieldHeader()) > 0) { Type memberT = values[fieldNumber - 1].type; CLS_Content.Value memberV = values[fieldNumber - 1]; string sClassName = keywords[fieldNumber - 1]; if (memberT == null) { memberT = typeof(SInstance); sClassName = ((SType)memberV.type).Name; } Type itemType = GetItemType(memberT); if (itemType != null) { sClassName = sInstance.type.members[sClassName].type.keyword; // 数组判断 if (memberT.IsArray) { string itemClass = sClassName.Substring(0, sClassName.Length - 2); // 从 xxx[] 中提取xxx BasicList list = new BasicList(); do { list.Add(ReadField(reader, itemType, itemClass, environment)); } while (reader.TryReadFieldHeader(fieldNumber)); Array result = Array.CreateInstance(itemType, list.Count); list.CopyTo(result, 0); memberV.value = result; } // 列表判断 else { string itemClass = sClassName.Substring(5, sClassName.Length - 6); // 从 List<xxx> 中提取xxx ICLS_Type iType = environment.GetTypeByKeywordQuiet(sClassName); CLS_Content content = CLS_Content.NewContent(environment); memberV.value = iType.function.New(content, m_emptyParams).value; CLS_Content.PoolContent(content); IList list = (IList)memberV.value; do { list.Add(ReadField(reader, itemType, itemClass, environment)); } while (reader.TryReadFieldHeader(fieldNumber)); } } else { memberV.value = ReadField(reader, memberT, sClassName, environment); } } }
public static BasicList <ICondition> AppendContains(this BasicList <ICondition> tempList, BasicList <int> containList) { SpecificListCondition thisCon = new(); thisCon.ItemList = containList; tempList.Add(thisCon); return(tempList); }
public static BasicList <SortInfo> Append(this BasicList <SortInfo> sortList, string property, EnumOrderBy orderBy) { sortList.Add(new SortInfo() { Property = property, OrderBy = orderBy }); return(sortList); }
public static BasicList <UpdateFieldInfo> Append(this BasicList <UpdateFieldInfo> tempList, BasicList <string> propList) { propList.ForEach(items => { tempList.Add(new UpdateFieldInfo(items)); }); return(tempList); }
public static BasicList <ICondition> AppendsNot(this BasicList <ICondition> tempList, BasicList <int> notList) { NotListCondition thiscon = new(); thiscon.ItemList = notList; tempList.Add(thiscon); return(tempList); }
public static BasicList <ICondition> AppendCondition(this BasicList <ICondition> tempList, string property, string toperator, object value) { AndCondition thisCon = new(); thisCon.Property = property; thisCon.Operator = toperator; thisCon.Value = value; tempList.Add(thisCon); return(tempList); }
internal int AddObjectKey(object value, out bool existing) { int num; if (value == null) { throw new ArgumentNullException("value"); } if (value == this.rootObject) { existing = true; return(0); } string str = value as string; BasicList list = this.List; if (str == null) { if (this.objectKeys == null) { this.objectKeys = new Dictionary <object, int>(NetObjectCache.ReferenceComparer.Default); num = -1; } else if (!this.objectKeys.TryGetValue(value, out num)) { num = -1; } } else if (this.stringKeys == null) { this.stringKeys = new Dictionary <string, int>(); num = -1; } else if (!this.stringKeys.TryGetValue(str, out num)) { num = -1; } bool flag = num >= 0; bool flag1 = flag; existing = flag; if (!flag1) { num = list.Add(value); if (str != null) { this.stringKeys.Add(str, num); } else { this.objectKeys.Add(value, num); } } return(num + 1); }
public override object Read(object value, ProtoReader source) { int num; int fieldNumber = source.FieldNumber; BasicList basicLists = new BasicList(); if (this.packedWireType == WireType.None || source.WireType != WireType.String) { do { basicLists.Add(this.Tail.Read(null, source)); }while (source.TryReadFieldHeader(fieldNumber)); } else { SubItemToken subItemToken = ProtoReader.StartSubItem(source); while (ProtoReader.HasSubValue(this.packedWireType, source)) { basicLists.Add(this.Tail.Read(null, source)); } ProtoReader.EndSubItem(subItemToken, source); } if (this.AppendToCollection) { num = (value == null ? 0 : ((Array)value).Length); } else { num = 0; } int num1 = num; Array arrays = Array.CreateInstance(this.itemType, num1 + basicLists.Count); if (num1 != 0) { ((Array)value).CopyTo(arrays, 0); } basicLists.CopyTo(arrays, num1); return(arrays); }
internal int AddObjectKey(object value, out bool existing) { if (value == null) { throw new ArgumentNullException("value"); } if (value == rootObject) { existing = true; return(0); } string text = value as string; BasicList list = List; int value2; if (text == null) { if (objectKeys == null) { objectKeys = new Dictionary <object, int>(ReferenceComparer.Default); value2 = -1; } else if (!objectKeys.TryGetValue(value, out value2)) { value2 = -1; } } else if (stringKeys == null) { stringKeys = new Dictionary <string, int>(); value2 = -1; } else if (!stringKeys.TryGetValue(text, out value2)) { value2 = -1; } if (!(existing = (value2 >= 0))) { value2 = list.Add(value); if (text == null) { objectKeys.Add(value, value2); } else { stringKeys.Add(text, value2); } } return(value2 + 1); }
static string GetSchema(RuntimeTypeModel runtimeTypeModel, CliArgs args) { BasicList requiredTypes = new BasicList(); foreach (MetaType meta in runtimeTypeModel.GetTypes()) { MetaType tmp = meta.GetSurrogateOrBaseOrSelf(false); if (!requiredTypes.Contains(tmp)) { requiredTypes.Add(tmp); } } StringBuilder headerBuilder = new StringBuilder(); headerBuilder.Append("syntax = \"proto2\";").AppendLine(); headerBuilder.AppendLine(); headerBuilder.Append("option java_package = \"").Append(args.JavaPackage).Append("\";").AppendLine(); headerBuilder.Append("option java_multiple_files = true;").AppendLine(); bool requiresBclImport = false; StringBuilder bodyBuilder = new StringBuilder(); // sort them by schema-name MetaType[] metaTypesArr = new MetaType[requiredTypes.Count]; requiredTypes.CopyTo(metaTypesArr, 0); Array.Sort(metaTypesArr, MetaType.Comparer.Default); // write the messages for (int i = 0; i < metaTypesArr.Length; i++) { MetaType tmp = metaTypesArr[i]; if (tmp.IsList) { continue; } tmp.WriteSchema(bodyBuilder, 0, ref requiresBclImport); bodyBuilder.AppendLine(); } if (requiresBclImport) { headerBuilder.AppendLine(); headerBuilder.Append("import \"dotnettype.proto\";").AppendLine(); } return(headerBuilder.Append(bodyBuilder).ToString()); }
private static void TestEnumerableListPatterns(TypeModel model, BasicList candidates, Type iType) { if (iType.IsGenericType) { Type typeDef = iType.GetGenericTypeDefinition(); if (typeDef == model.MapType(typeof(IEnumerable <>)) || typeDef == model.MapType(typeof(ICollection <>)) || typeDef.FullName == "System.Collections.Concurrent.IProducerConsumerCollection`1") { Type[] iTypeArgs = iType.GetGenericArguments(); if (!candidates.Contains(iTypeArgs[0])) { candidates.Add(iTypeArgs[0]); } } } }
internal int AddObjectKey(object value, out bool existing) { if (value == null) { throw new ArgumentNullException("value"); } if ((object)value == (object)rootObject) // (object) here is no-op, but should be { // preserved even if this was typed - needs ref-check existing = true; return(Root); } string s; BasicList list = List; int index = ((s = value as string) == null) ? list.IndexOfReference(value) : list.IndexOf(new StringMatch(s)); if (!(existing = index >= 0)) { index = list.Add(value); } return(index + 1); }
internal int AddObjectKey(object value, out bool existing) { if (value == null) { throw new ArgumentNullException("value"); } if ((object)value == (object)rootObject) // (object) here is no-op, but should be { // preserved even if this was typed - needs ref-check existing = true; return(Root); } string s = value as string; BasicList list = List; int index; #if NO_GENERICS if (s == null) { if (objectKeys == null) { objectKeys = new ReferenceHashtable(); index = -1; } else { object tmp = objectKeys[value]; index = tmp == null ? -1 : (int)tmp; } } else { if (stringKeys == null) { stringKeys = new Hashtable(); index = -1; } else { object tmp = stringKeys[s]; index = tmp == null ? -1 : (int)tmp; } } #else if (s == null) { #if CF || PORTABLE // CF has very limited proper object ref-tracking; so instead, we'll search it the hard way index = list.IndexOfReference(value); #else if (objectKeys == null) { objectKeys = new System.Collections.Generic.Dictionary <object, int>(ReferenceComparer.Default); index = -1; } else { if (!objectKeys.TryGetValue(value, out index)) { index = -1; } } #endif } else { if (stringKeys == null) { stringKeys = new System.Collections.Generic.Dictionary <string, int>(); index = -1; } else { if (!stringKeys.TryGetValue(s, out index)) { index = -1; } } } #endif if (!(existing = index >= 0)) { index = list.Add(value); if (s == null) { #if !CF && !PORTABLE // CF can't handle the object keys very well objectKeys.Add(value, index); #endif } else { stringKeys.Add(s, index); } } return(index + 1); }
internal int AddObjectKey(object value, out bool existing) { if (value == null) { throw new ArgumentNullException(nameof(value)); } if ((object)value == (object)rootObject) // (object) here is no-op, but should be { // preserved even if this was typed - needs ref-check existing = true; return(Root); } string s = value as string; BasicList list = List; int index; if (s == null) { if (objectKeys == null) { objectKeys = new Dictionary <object, int>(ReferenceComparer.Default); index = -1; } else { if (!objectKeys.TryGetValue(value, out index)) { index = -1; } } } else { if (stringKeys == null) { stringKeys = new Dictionary <string, int>(); index = -1; } else { if (!stringKeys.TryGetValue(s, out index)) { index = -1; } } } if (!(existing = index >= 0)) { index = list.Add(value); if (s == null) { objectKeys.Add(value, index); } else { stringKeys.Add(s, index); } } return(index + 1); }
/// <summary> /// All this does is call GetExtendedValuesTyped with the correct type for "instance"; /// this ensures that we don't get issues with subclasses declaring conflicting types - /// the caller must respect the fields defined for the type they pass in. /// </summary> internal static IEnumerable GetExtendedValues(TypeModel model, Type type, IExtensible instance, int tag, DataFormat format, bool singleton, bool allowDefinedTag) { #if FEAT_IKVM throw new NotSupportedException(); #else if (instance == null) { throw new ArgumentNullException("instance"); } if (tag <= 0) { throw new ArgumentOutOfRangeException("tag"); } IExtension extn = instance.GetExtensionObject(false); if (extn == null) { #if FX11 return(new object[0]); #else yield break; #endif } #if FX11 BasicList result = new BasicList(); #endif Stream stream = extn.BeginQuery(); object value = null; ProtoReader reader = null; try { SerializationContext ctx = new SerializationContext(); reader = ProtoReader.Create(stream, model, ctx, ProtoReader.TO_EOF); while (model.TryDeserializeAuxiliaryType(reader, format, tag, type, ref value, true, false, false, false) && value != null) { if (!singleton) { #if FX11 result.Add(value); #else yield return(value); #endif value = null; // fresh item each time } } if (singleton && value != null) { #if FX11 result.Add(value); #else yield return(value); #endif } #if FX11 object[] resultArr = new object[result.Count]; result.CopyTo(resultArr, 0); return(resultArr); #endif } finally { ProtoReader.Recycle(reader); extn.EndQuery(stream); } #endif }
public override string GetSchema(Type type) { BasicList requiredTypes = new BasicList(); MetaType primaryType = null; bool isInbuiltType = false; if (type == null) { BasicList.NodeEnumerator enumerator = this.types.GetEnumerator(); while (enumerator.MoveNext()) { MetaType meta = (MetaType)enumerator.Current; MetaType tmp = meta.GetSurrogateOrBaseOrSelf(false); if (!requiredTypes.Contains(tmp)) { requiredTypes.Add(tmp); this.CascadeDependents(requiredTypes, tmp); } } } else { Type tmp2 = Helpers.GetUnderlyingType(type); if (tmp2 != null) { type = tmp2; } WireType defaultWireType; isInbuiltType = (ValueMember.TryGetCoreSerializer(this, DataFormat.Default, type, out defaultWireType, false, false, false, false) != null); if (!isInbuiltType) { int index = this.FindOrAddAuto(type, false, false, false); if (index < 0) { throw new ArgumentException("The type specified is not a contract-type", "type"); } primaryType = ((MetaType)this.types[index]).GetSurrogateOrBaseOrSelf(false); requiredTypes.Add(primaryType); this.CascadeDependents(requiredTypes, primaryType); } } StringBuilder headerBuilder = new StringBuilder(); string package = null; if (!isInbuiltType) { IEnumerable typesForNamespace = (primaryType == null) ? this.types : requiredTypes; foreach (MetaType meta2 in typesForNamespace) { if (!meta2.IsList) { string tmp3 = meta2.Type.Namespace; if (!Helpers.IsNullOrEmpty(tmp3) && !tmp3.StartsWith("System.")) { if (package == null) { package = tmp3; } else { if (!(package == tmp3)) { package = null; break; } } } } } } if (!Helpers.IsNullOrEmpty(package)) { headerBuilder.Append("package ").Append(package).Append(';'); Helpers.AppendLine(headerBuilder); } bool requiresBclImport = false; StringBuilder bodyBuilder = new StringBuilder(); MetaType[] metaTypesArr = new MetaType[requiredTypes.Count]; requiredTypes.CopyTo(metaTypesArr, 0); Array.Sort <MetaType>(metaTypesArr, MetaType.Comparer.Default); if (isInbuiltType) { Helpers.AppendLine(bodyBuilder).Append("message ").Append(type.Name).Append(" {"); MetaType.NewLine(bodyBuilder, 1).Append("optional ").Append(this.GetSchemaTypeName(type, DataFormat.Default, false, false, ref requiresBclImport)).Append(" value = 1;"); Helpers.AppendLine(bodyBuilder).Append('}'); } else { for (int i = 0; i < metaTypesArr.Length; i++) { MetaType tmp4 = metaTypesArr[i]; if (!tmp4.IsList || tmp4 == primaryType) { tmp4.WriteSchema(bodyBuilder, 0, ref requiresBclImport); } } } if (requiresBclImport) { headerBuilder.Append("import \"bcl.proto\"; // schema for protobuf-net's handling of core .NET types"); Helpers.AppendLine(headerBuilder); } return(Helpers.AppendLine(headerBuilder.Append(bodyBuilder)).ToString()); }
internal int AddObjectKey(object value, out bool existing) { if (value == null) { throw new ArgumentNullException("value"); } if ((object)value == (object)rootObject) // (object) here is no-op, but should be { // preserved even if this was typed - needs ref-check existing = true; return(Root); } string s = value as string; BasicList list = List; int index; #if NO_GENERICS //index = s == null ? list.IndexOfReference(value) : list.IndexOf(new StringMatch(s)); if (s == null) { if (objectKeys == null) { objectKeys = new ReferenceHashtable(); index = -1; } else { object tmp = objectKeys[value]; index = tmp == null ? -1 : (int)tmp; } } else { if (stringKeys == null) { stringKeys = new Hashtable(); index = -1; } else { object tmp = stringKeys[s]; index = tmp == null ? -1 : (int)tmp; } } #else if (s == null) { if (objectKeys == null) { objectKeys = new System.Collections.Generic.Dictionary <object, int>(ReferenceComparer.Default); index = -1; } else { if (!objectKeys.TryGetValue(value, out index)) { index = -1; } } } else { if (stringKeys == null) { stringKeys = new System.Collections.Generic.Dictionary <string, int>(); index = -1; } else { if (!stringKeys.TryGetValue(s, out index)) { index = -1; } } } #endif if (!(existing = index >= 0)) { index = list.Add(value); if (s == null) { objectKeys.Add(value, index); } else { stringKeys.Add(s, index); } } return(index + 1); }
private void CascadeDependents(BasicList list, MetaType metaType) { if (metaType.IsList) { Type itemType = TypeModel.GetListItemType(this, metaType.Type); WireType defaultWireType; if (ValueMember.TryGetCoreSerializer(this, DataFormat.Default, itemType, out defaultWireType, false, false, false, false) == null) { int index = this.FindOrAddAuto(itemType, false, false, false); if (index >= 0) { MetaType tmp = ((MetaType)this.types[index]).GetSurrogateOrBaseOrSelf(false); if (!list.Contains(tmp)) { list.Add(tmp); this.CascadeDependents(list, tmp); return; } } } } else { MetaType tmp; if (metaType.IsAutoTuple) { MemberInfo[] mapping; if (MetaType.ResolveTupleConstructor(metaType.Type, out mapping) != null) { for (int i = 0; i < mapping.Length; i++) { Type type = null; if (mapping[i] is PropertyInfo) { type = ((PropertyInfo)mapping[i]).PropertyType; } else { if (mapping[i] is FieldInfo) { type = ((FieldInfo)mapping[i]).FieldType; } } WireType defaultWireType2; if (ValueMember.TryGetCoreSerializer(this, DataFormat.Default, type, out defaultWireType2, false, false, false, false) == null) { int index2 = this.FindOrAddAuto(type, false, false, false); if (index2 >= 0) { tmp = ((MetaType)this.types[index2]).GetSurrogateOrBaseOrSelf(false); if (!list.Contains(tmp)) { list.Add(tmp); this.CascadeDependents(list, tmp); } } } } } } else { foreach (ValueMember member in metaType.Fields) { Type type2 = member.ItemType; if (type2 == null) { type2 = member.MemberType; } WireType defaultWireType3; if (ValueMember.TryGetCoreSerializer(this, DataFormat.Default, type2, out defaultWireType3, false, false, false, false) == null) { int index3 = this.FindOrAddAuto(type2, false, false, false); if (index3 >= 0) { tmp = ((MetaType)this.types[index3]).GetSurrogateOrBaseOrSelf(false); if (!list.Contains(tmp)) { list.Add(tmp); this.CascadeDependents(list, tmp); } } } } } if (metaType.HasSubtypes) { SubType[] subtypes = metaType.GetSubtypes(); for (int j = 0; j < subtypes.Length; j++) { SubType subType = subtypes[j]; tmp = subType.DerivedType.GetSurrogateOrSelf(); if (!list.Contains(tmp)) { list.Add(tmp); this.CascadeDependents(list, tmp); } } } tmp = metaType.BaseType; if (tmp != null) { tmp = tmp.GetSurrogateOrSelf(); } if (tmp != null && !list.Contains(tmp)) { list.Add(tmp); this.CascadeDependents(list, tmp); } } }
public static BasicList <UpdateEntity> Append(this BasicList <UpdateEntity> tempList, string thisProperty, object value) { tempList.Add(new UpdateEntity(thisProperty, value)); return(tempList); }
internal static Type GetListItemType(TypeModel model, Type listType) { if (listType == model.MapType(typeof(string)) || listType.IsArray || !model.MapType(typeof(IEnumerable)).IsAssignableFrom(listType)) { return(null); } BasicList candidates = new BasicList(); MethodInfo[] methods = listType.GetMethods(); for (int i = 0; i < methods.Length; i++) { MethodInfo method = methods[i]; if (!method.IsStatic && !(method.Name != "Add")) { ParameterInfo[] parameters = method.GetParameters(); Type paramType; if (parameters.Length == 1 && !candidates.Contains(paramType = parameters[0].ParameterType)) { candidates.Add(paramType); } } } string name = listType.Name; if (name == null || (name.IndexOf("Queue") < 0 && name.IndexOf("Stack") < 0)) { TypeModel.TestEnumerableListPatterns(model, candidates, listType); Type[] interfaces = listType.GetInterfaces(); for (int j = 0; j < interfaces.Length; j++) { Type iType = interfaces[j]; TypeModel.TestEnumerableListPatterns(model, candidates, iType); } } PropertyInfo[] properties = listType.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); for (int k = 0; k < properties.Length; k++) { PropertyInfo indexer = properties[k]; if (!(indexer.Name != "Item") && !candidates.Contains(indexer.PropertyType)) { ParameterInfo[] args = indexer.GetIndexParameters(); if (args.Length == 1 && !(args[0].ParameterType != model.MapType(typeof(int)))) { candidates.Add(indexer.PropertyType); } } } switch (candidates.Count) { case 0: return(null); case 1: return((Type)candidates[0]); case 2: if (TypeModel.CheckDictionaryAccessors(model, (Type)candidates[0], (Type)candidates[1])) { return((Type)candidates[0]); } if (TypeModel.CheckDictionaryAccessors(model, (Type)candidates[1], (Type)candidates[0])) { return((Type)candidates[1]); } break; } return(null); }
public static BasicList <UpdateFieldInfo> Append(this BasicList <UpdateFieldInfo> tempList, string thisProperty) { tempList.Add(new UpdateFieldInfo(thisProperty)); return(tempList); }
private bool TryDeserializeList(TypeModel model, ProtoReader reader, DataFormat format, int tag, Type listType, Type itemType, ref object value) { bool isList; MethodInfo addMethod = TypeModel.ResolveListAdd(model, listType, itemType, out isList); if (addMethod == null) { throw new NotSupportedException("Unknown list variant: " + listType.FullName); } bool found = false; object nextItem = null; IList list = value as IList; object[] args = isList ? null : new object[1]; BasicList arraySurrogate = listType.IsArray ? new BasicList() : null; while (this.TryDeserializeAuxiliaryType(reader, format, tag, itemType, ref nextItem, true, true, true, true)) { found = true; if (value == null && arraySurrogate == null) { value = TypeModel.CreateListInstance(listType, itemType); list = (value as IList); } if (list != null) { list.Add(nextItem); } else { if (arraySurrogate != null) { arraySurrogate.Add(nextItem); } else { args[0] = nextItem; addMethod.Invoke(value, args); } } nextItem = null; } if (arraySurrogate != null) { if (value != null) { if (arraySurrogate.Count != 0) { Array existing = (Array)value; Array newArray = Array.CreateInstance(itemType, existing.Length + arraySurrogate.Count); Array.Copy(existing, newArray, existing.Length); arraySurrogate.CopyTo(newArray, existing.Length); value = newArray; } } else { Array newArray = Array.CreateInstance(itemType, arraySurrogate.Count); arraySurrogate.CopyTo(newArray, 0); value = newArray; } } return(found); }