public static CreateSet ( |
||
field | ||
return | object>.Action |
object GetObjectOfTypeFromNode(Type t, XmlNode node) { if (t.IsSimpleType() || t == typeof(Uri) || t.IsNullableType()) { return(GetPropertyValue(t, node)); } if (typeof(IEnumerable).IsAssignableFrom(t)) { return(GetPropertyValue(t, node)); } var result = mapper.CreateInstance(t); foreach (XmlNode n in node.ChildNodes) { Type type = null; if (n.Name.Contains(":")) { type = Type.GetType($"System.{n.Name.Substring(0, n.Name.IndexOf(":"))}", false, true); } if (!cache.typeMembers.TryGetValue(t, out var typeMembers)) { cache.InitType(t); cache.typeMembers.TryGetValue(t, out typeMembers); } var prop = GetProperty(typeMembers?.Item2, n.Name); if (prop != null) { var val = GetPropertyValue(type ?? prop.PropertyType, n); if (val != null) { var propertySet = DelegateFactory.CreateSet(prop); propertySet.Invoke(result, val); continue; } } var field = GetField(typeMembers?.Item1, n.Name); if (field != null) { var val = GetPropertyValue(type ?? field.FieldType, n); if (val != null) { var fieldSet = DelegateFactory.CreateSet(field); fieldSet.Invoke(result, val); } } } return(result); }
public static void SetValue(this MemberInfo member, object target, object value) { var fieldInfo = member as FieldInfo; if (fieldInfo != null) { var fieldSet = DelegateFactory.CreateSet(fieldInfo); fieldSet.Invoke(target, value); } else { var propertyInfo = member as PropertyInfo; var propertySet = DelegateFactory.CreateSet(propertyInfo); propertySet.Invoke(target, value); } }
internal List <DataBusPropertyInfo> GetDataBusProperties(object message) { return(cache.GetOrAdd(message.GetType(), messageType => { var properties = new List <DataBusPropertyInfo>(); foreach (var propertyInfo in messageType.GetProperties()) { if (IsDataBusProperty(propertyInfo)) { properties.Add(new DataBusPropertyInfo { Name = propertyInfo.Name, Getter = DelegateFactory.CreateGet(propertyInfo), Setter = DelegateFactory.CreateSet(propertyInfo) }); } } return properties; })); }
internal IEnumerable <DataBusPropertyInfo> GetDataBusProperties(object message) { var messageType = message.GetType(); List <DataBusPropertyInfo> value; if (!cache.TryGetValue(messageType, out value)) { value = messageType.GetProperties() .Where(IsDataBusProperty) .Select(property => new DataBusPropertyInfo { Name = property.Name, Getter = DelegateFactory.CreateGet(property), Setter = DelegateFactory.CreateSet(property), }).ToList(); cache[messageType] = value; } return(value); }