public static CreateObject ( Type type, Array ctypes, Array cparams, bool cache ) : object | ||
type | Type | |
ctypes | Array | |
cparams | Array | |
cache | bool | |
Résultat | object |
protected virtual IList DeserializeArray(JsonReader jreader, JsonSerializer serializer, Type type, IList sourceList) { if (type == null) { while (jreader.Read() && jreader.TokenType != JsonToken.EndArray) { } return(null); } var typeInfo = Serialization.Instance.GetTypeInfo(type); var itemType = typeInfo.ListItemType; var temp = sourceList ?? (IList)EmitInvoker.CreateObject(type); temp.Clear(); while (jreader.Read() && jreader.TokenType != JsonToken.EndArray) { var item = Read(jreader, itemType, serializer, null); if (item == null) { continue; } temp.Add(item); } return(temp); }
public static Pull Fabric(Type type, int blockSize) { Type gtype = type.IsValueType || type.IsEnum ? typeof(NullablePullArray <>).MakeGenericType(type) : typeof(PullArray <>).MakeGenericType(type); return((Pull)EmitInvoker.CreateObject(gtype, ctorTypes, new object[] { blockSize }, true)); }
protected virtual IList DeserializeArray(ref Utf8JsonReader jreader, JsonSerializerOptions options, Type type, IList sourceList) { if (type == null) { while (jreader.Read() && jreader.TokenType != JsonTokenType.EndArray) { } return(null); } var itemType = TypeHelper.GetItemType(type); var client = Client.Provider.GetClient(itemType); var temp = sourceList ?? (IList)EmitInvoker.CreateObject(type); var referenceList = temp as IReferenceList; if (referenceList != null && client != null && referenceList.Owner.SyncStatus == SynchronizedStatus.Load) { var referanceBuffer = new HashSet <ISynchronized>((IEnumerable <ISynchronized>)referenceList); while (jreader.Read() && jreader.TokenType != JsonTokenType.EndArray) { #if NETSTANDARD2_0 var item = Read(ref jreader, itemType, options, null); #else var item = client.Converter.Read(ref jreader, itemType, options); #endif if (item is ISynchronized synched) { referenceList.Add(item); referanceBuffer.Remove(synched); } } foreach (var item in referanceBuffer) { if (!client.Remove(item)) { referenceList.Remove(item); } } } else { temp.Clear(); while (jreader.Read() && jreader.TokenType != JsonTokenType.EndArray) { var item = Read(ref jreader, itemType, options, null); if (item == null) { continue; } temp.Add(item); } } return(temp); }
public static IQueryParameter CreateTreeFilter(Type type) { var parameter = (IQueryParameter)EmitInvoker.CreateObject(typeof(QueryParameter <>).MakeGenericType(type)); parameter.Invoker = (IInvoker)EmitInvoker.CreateObject(typeof(TreeInvoker <>).MakeGenericType(type)); parameter.Comparer = CompareType.Equal; parameter.Value = true; parameter.IsGlobal = true; parameter.FormatIgnore = true; return(parameter); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var itemType = TypeHelper.GetItemType(objectType); var items = (existingValue as IList) ?? (IList)EmitInvoker.CreateObject(objectType); while (reader.Read() && reader.TokenType != JsonToken.EndArray) { items.Add(serializer.Deserialize(reader, itemType)); } return(items); }
public static ValueSerializer GetValueSerializer(Type type) { if (!cacheValueSerializer.TryGetValue(type, out var serializer)) { var attribute = type.GetCustomAttribute <ValueSerializerAttribute>(false); serializer = null; if (attribute != null && attribute.ValueSerializerType != null) { serializer = (ValueSerializer)CreateObject(attribute.ValueSerializerType); } else if (type == typeof(string)) { serializer = StringValueSerializer.Instance; } else if (type == typeof(int)) { serializer = IntValueSerializer.Instance; } else if (type == typeof(double)) { serializer = DoubleValueSerializer.Instance; } else if (type == typeof(DateTime)) { serializer = DateTimeValueSerializer.Instance; } else if (type == typeof(Type)) { serializer = TypeValueSerializer.Instance; } else if (type == typeof(CultureInfo)) { serializer = CultureInfoValueSerializer.Instance; } else if (type.IsEnum) { serializer = (ValueSerializer)EmitInvoker.CreateObject(typeof(EnumValueSerializer <>).MakeGenericType(type)); } else { var converter = GetTypeConverter(type); if (converter != null) { serializer = new TypeConverterValueSerializer { Converter = converter }; } } return(cacheValueSerializer[type] = serializer); } return(serializer); }
public void Load() { if (File.Exists(FileName)) { if (Project is IFileSerialize) { ((IFileSerialize)Project).Load(FileName); } else { Project = Serialization.Deserialize(FileName, Project); } } if (Editor == null && type != null) { Editor = EmitInvoker.CreateObject(type.Editor, true) as IProjectEditor; } synch = true; }
protected virtual IList ReadArray(JsonReader jreader, JsonSerializer serializer, Type type, IList sourceList) { if (type == null) { while (jreader.Read() && jreader.TokenType != JsonToken.EndArray) { } return(null); } var typeInfo = Serialization.Instance.GetTypeInfo(type); var itemType = typeInfo.ListItemType; var client = Client.Provider.GetClient(itemType); var temp = sourceList ?? (IList)EmitInvoker.CreateObject(type); var referenceList = temp as IReferenceList; if (referenceList != null && client != null) { var isLoad = referenceList.Owner.SyncStatus == SynchronizedStatus.Load || referenceList.Owner.SyncStatus == SynchronizedStatus.Actual; if (isLoad) { foreach (ISynchronized item in referenceList) { item.SyncStatus = SynchronizedStatus.Actual; } } while (jreader.Read() && jreader.TokenType != JsonToken.EndArray) { #if NETSTANDARD2_0 var item = client.Converter.Read(jreader, null, serializer); #else var item = Read(jreader, itemType, serializer, null); #endif if (item is ISynchronized synched) { referenceList.Add(item); } } //foreach (var item in referanceBuffer) //{ // if (!client.Remove(item)) // { // referenceList.Remove(item); // } //} } else { temp.Clear(); while (jreader.Read() && jreader.TokenType != JsonToken.EndArray) { var item = Read(jreader, itemType, serializer, null); if (item == null) { continue; } temp.Add(item); } } return(temp); }
public static IList Create(Type type, int capacity) { return((IList)EmitInvoker.CreateObject(type, new Type[] { typeof(int) }, new object[] { capacity }, true)); }
public static IComparer CreateTreeComparer(Type type) { return((IComparer)EmitInvoker.CreateObject(typeof(TreeComparer <>).MakeGenericType(type))); }