private static IEnumerable <RuntimeMemberInfo> CreateRuntimeMemberInfo(Type type, Dictionary <Type, RuntimeInfo> tempCache) { var typeMembers = type.GetFields(bindingFlags).Where(f => !f.FieldType.IsValueType && f.FieldType != typeof(string)) .Cast <MemberInfo>() .Concat(type.GetProperties(bindingFlags).Where(p => !p.PropertyType.IsValueType && p.PropertyType != typeof(string))) .Select(m => MemberInfoFactory.Create(m)) .Where(m => m != null) .ToArray(); foreach (var memberInfo in typeMembers) { // Don't loop through dictionary twice. if (memberInfo.MemberName == "Keys" && memberInfo.FieldOrPropertyType.Name == "KeyCollection") { continue; } if (memberInfo.MemberName == "Values" && memberInfo.FieldOrPropertyType.Name == "ValueCollection") { continue; } var runtimeInfo = RuntimeInfo.Create(memberInfo.FieldOrPropertyType, tempCache); if (runtimeInfo != null) { yield return new RuntimeMemberInfo() { MemberInfo = memberInfo, RuntimeInfo = runtimeInfo } } ; } }
public static RuntimeInfo GetRuntimeInfo(Type type) { RuntimeInfo value = null; if (_cache.TryGetValue(type, out value)) { return(value); } var newCreatedInfo = new Dictionary <Type, RuntimeInfo>(); RuntimeInfo.Create(type, newCreatedInfo); var reducedDict = new Dictionary <Type, RuntimeInfo>(); foreach (var element in newCreatedInfo) { if (!_cache.ContainsKey(element.Key)) { _cache[element.Key] = element.Value?.Reduce(reducedDict); } } return(_cache[type]); }
public static RuntimeInfo Create(Type type, Dictionary <Type, RuntimeInfo> tempCache) { if (type == null) { return(null); } if ((type.IsValueType && !type.IsGenericType) || type == typeof(string)) { tempCache[type] = null; return(null); } RuntimeInfo existing = null; if (InternalCache.TryGet(type, out existing)) { return(existing); } if (tempCache.TryGetValue(type, out existing)) { return(existing); } RuntimeInfo runtimeInfo = null; tempCache[type] = runtimeInfo = new RuntimeInfo() { _type = type, _actionInfo = GetRuntimeActionForType(type) }; runtimeInfo._runtimeCollectionElementInfo = RuntimeInfo.Create(GetGenericCollectionElementType(type), tempCache); runtimeInfo._runtimeMembers = CreateRuntimeMemberInfo(type, tempCache).ToArray(); return(runtimeInfo); }