public object Get(IFormatReader parameter) { var elementType = _classification.GetClassification(parameter, _declaredType).GetElementType(); var result = _reader.Get(parameter).ToArray(elementType ?? throw new InvalidOperationException("Element type not found.")); return(result); }
private object ReadCollectionProperty_InitializeCollection(PropertyInfo property, Type targetType, IReader reader) { object collection = null; if (reader.CanSet(property)) { if (property.PropertyType.IsArray) { collection = Activator.CreateInstance(typeof(List <>).MakeGenericType(targetType)); } else { collection = Activator.CreateInstance(property.PropertyType); } } else { if (reader.CanGet(property)) { collection = reader.Get(property); } if (collection == null) { throw new InvalidOperationException($"The value of the property {property.DeclaringType.FullName}.{property.Name} has no set accessor and is not initialized by default"); } } return(collection); }
public T Get(IFormatReader parameter) { var result = _reader.Get(parameter); _configuration.Execute(parameter); return(result); }
public TypeInfo Get(IFormatReader parameter) { var isSatisfiedBy = parameter.IsSatisfiedBy(SchemaType.Instance); return(isSatisfiedBy ? _reader.Get(parameter) : _classification.Get(parameter)); }
public object Get(IFormatReader parameter) { var dimensions = _map.Get(parameter); var source = _reader.Get(parameter).AsValid <Array>(); var result = Array.CreateInstance(_root, dimensions.ToArray()); Buffer.BlockCopy(source, 0, result, 0, source.Length * sizeof(int)); return(result); }
public TypeInfo Get(IFormatReader parameter) { var element = _reader.Get(parameter); var result = element != null ? TypeInfo(parameter, element) .GetTypeInfo() : null; return(result); }
public object Get(IFormatReader parameter) { var classification = _classification.Get(parameter); var result = _specification.IsSatisfiedBy(classification) ? _activators.Get(classification) .Get() : _activator.Get(parameter); return(result); }
public IActionResult Find([FromServices] IReader <TEntity> reader, TId id) { var record = reader.Get(entity => entity.Id.Equals(id), Queryable.SingleOrDefault); if (record == null) { return(this.NotFound()); } return(this.Ok(record)); }
public IInnerContent Get(IFormatReader parameter) { var xml = (System.Xml.XmlReader) parameter.Get(); var attributes = xml.HasAttributes ? new XmlAttributes(xml) : (XmlAttributes?) null; var depth = XmlDepth.Default.Get(xml); var content = depth.HasValue ? new XmlElements(xml, depth.Value) : (XmlElements?) null; var result = parameter.IsAssigned() ? _contents.Create(parameter, _activator.Get(parameter), new XmlContent(attributes, content)) : null; return result; }
public object Get(IFormatReader parameter) { var declared = Identity(parameter); var result = _activator.Get(parameter); var identity = declared ?? (result != null ? Entity(parameter, result) : null); if (identity != null) { _maps.Get(parameter).Assign(identity.Value, result); } return(result); }
static void Main() { Test <string> t1 = new Test <string>(); t1.Put("covariance"); IReader <object> rdr = (IReader <object>)t1; Console.WriteLine(rdr.Get()); Test <object> t2 = new Test <object>(); IWriter <string> wrtr = t1; wrtr.Put("contravariance"); Console.WriteLine(t2.Get()); }
public IInnerContent Get(IFormatReader parameter) { var xml = (System.Xml.XmlReader)parameter.Get(); var attributes = xml.HasAttributes ? new XmlAttributes(xml) : (XmlAttributes?)null; var depth = XmlDepth.Default.Get(xml); var content = depth.HasValue ? new XmlElements(xml, depth.Value) : (XmlElements?)null; var result = IdentityComparer.Default.Equals(parameter, NullElementIdentity.Default) || parameter.IsSatisfiedBy(NullValueIdentity.Default) ? null : _contents.Create(parameter, _activator.Get(parameter), new XmlContent(attributes, content)); return(result); }
public object Get(IFormatReader parameter) { if (parameter.IsSatisfiedBy(ExplicitTypeProperty.Default)) { var classification = _classification.Get(parameter); if (classification != null && !classification.IsArray) { return(_activators.Get(classification.AsType()) .Get()); } } var result = _activator.Get(parameter); return(result); }
/// <summary> /// Mapper method that maps data from an <see cref="IReader"/> to a POCO object using the /// names of the properties. The process uses a very simple reflection based approach, that /// is not really "production ready" - use an explicit and specific implementation in production /// to prevent the overhead of reflection. /// </summary> /// <typeparam name="T">The type of the target POCO objects.</typeparam> /// <param name="reader">The reader implementation.</param> /// <returns>The initialized object instance.</returns> public static async Task <T> To <T>(IReader reader) where T : new() { reader.MustNotBeNull(nameof(reader)); var properties = typeof(T).GetProperties(); var value = new T(); foreach (var property in properties) { var index = reader.IndexByName(property.Name); property.SetValue(value, await reader.Get(index, property.PropertyType).ConfigureAwait(false)); } return(value); }
public object Get(IFormatReader parameter) { var element = IsElement.Default.IsSatisfiedBy(parameter); var declared = element ? Identity(parameter) : null; var result = _activator.Get(parameter); var identity = declared ?? (element && result != null ? Entity(parameter, result) : null); if (identity != null) { _maps.Get(parameter) .Assign(identity.Value, result); } return(result); }
public object Get(IFormatReader parameter) { var element = !string.IsNullOrEmpty(parameter.Identifier); var declared = element ? Identity(parameter) : null; var result = _activator.Get(parameter); var identity = declared ?? (element && result != null ? Entity(parameter, result) : null); if (identity != null) { _maps.Get(parameter) .Assign(identity.Value, result); } return(result); }
public object Get(IFormatReader parameter) { var element = parameter.Get().To <XmlReader>().NodeType != XmlNodeType.Attribute || MemberProperty.Default.Get(parameter); var declared = element ? Identity(parameter) : null; var result = _activator.Get(parameter); var identity = declared ?? (element && result != null ? Entity(parameter, result) : null); if (identity != null) { _maps.Get(parameter) .Assign(identity.Value, result); } return(result); }
public object Get(IFormatReader parameter) { var key = parameter.Get() .AsValid <XmlReader>(); var result = _instances.IsSatisfiedBy(key) ? _instances.Get(key) : _reader.Get(parameter); return(result); }
public object Get(IFormatReader parameter) => _reader.Get(parameter);
public T Get(IFormatReader parameter) => _reader.Get(parameter);
public static object GetIfAssigned(this IReader @this, IFormatReader reader) => reader.IsAssigned() ? @this.Get(reader) : null;
public static T GetIfAssigned <T>(this IReader <T> @this, IFormatReader reader) => reader.IsAssigned() ? @this.Get(reader) : default;
public TypeInfo Get(IFormatReader parameter) => _reader.Get(parameter)?.AsValid <TypeInfo>();
public async Task <YoutubeDto> Search(string query) { var youtubeConfigs = _config.GetSection("YoutubeConfigs"); var baseUrl = youtubeConfigs["baseUrl"].ToString(); var key = youtubeConfigs["key"].ToString(); var readerParams = new ReaderParams { urlParams = new Dictionary <string, string> { { "part", "snippet" }, { "q", query }, { "key", key } } }; var youtubeResponse = await _reader.Get <YoutubeResponse>(baseUrl + "search?", readerParams); var youtubeDto = new YoutubeDto { NextPageToken = youtubeResponse.nextPageToken, }; foreach (var item in youtubeResponse.items) { var ytModel = new YoutubeModel(); ytModel.Title = item.snippet.title; ytModel.Description = item.snippet.description; ytModel.PublishedAt = item.snippet.publishedAt; ytModel.IsChannel = false; ytModel.ChannelName = item.snippet.channelTitle; ytModel.ThumbnailUrl = item.snippet.thumbnails.medium.url; if (item.id.kind == "youtube#channel") { ytModel.IsChannel = true; ytModel.youtubeId = item.id.channelId; } else if (item.id.kind == "youtube#video") { ytModel.youtubeId = item.id.videoId; } else { ytModel.youtubeId = item.id.playlistId; } if (_youtubeRepository.Exists(x => x.youtubeId == ytModel.youtubeId)) { var res = _youtubeRepository.ListBy(x => x.youtubeId == ytModel.youtubeId).Result.FirstOrDefault(); ytModel.Id = res.Id; await _youtubeRepository.Update(ytModel); } else { await _youtubeRepository.Create(ytModel); } youtubeDto.Items.Add(ytModel); } return(youtubeDto); }
public T Get(IFormatReader parameter) => (T)_serializer.Get(parameter);
public RuleBaseModel GetRule(string name) { var config = _reader.Get <ConfigFileModel>(ConfigFilePath); return(config.Rules.FirstOrDefault(conf => conf.Name.Equals(name))); }
public IActionResult Get([FromServices] IReader <TEntity> reader) { return(this.Ok(reader.Get(entity => entity, Queryable.Select))); }
public IInnerContent Get(IFormatReader parameter) => parameter.IsAssigned() ? _contents.Create(parameter, _activator.Get(parameter), Content(parameter.Get() .To <System.Xml.XmlReader>())) : null;