Deveel.Data.Serialization.BinarySerializer.GetObjectValues C# (CSharp) Method

GetObjectValues() private static method

private static GetObjectValues ( Type objType, object obj, SerializationInfo graph ) : void
objType System.Type
obj object
graph System.Runtime.Serialization.SerializationInfo
return void
		private static void GetObjectValues(Type objType, object obj, SerializationInfo graph) {
#if PCL
			var fields =
				objType.GetRuntimeFields()
					.Where(x => !x.IsStatic && !x.IsDefined(typeof (NonSerializedAttribute)) && !x.Name.EndsWith("_BackingField"));
			var properties = objType.GetRuntimeProperties()
				.Where(x => !x.IsStatic() && x.CanWrite && !x.IsDefined(typeof (NonSerializedAttribute)));
#else
			var fields = objType.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)
				.Where(x => !x.IsDefined(typeof (NonSerializedAttribute), false) && !x.Name.EndsWith("_BackingField"));
			var properties = objType.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
				.Where(x => !x.IsDefined(typeof (NonSerializedAttribute), false) && x.CanRead);
#endif

			var members = new List<MemberInfo>();
			members.AddRange(fields.Cast<MemberInfo>());
			members.AddRange(properties.Cast<MemberInfo>());

			foreach (var member in members) {
				var memberName = member.Name;
				Type memberType;

				object value;
				if (member is FieldInfo) {
					value = ((FieldInfo) member).GetValue(obj);
					memberType = ((FieldInfo) member).FieldType;
				} else if (member is PropertyInfo) {
					value = ((PropertyInfo) member).GetValue(obj, null);
					memberType = ((PropertyInfo) member).PropertyType;
				} else {
					throw new NotSupportedException();
				}

				graph.AddValue(memberName, value, memberType);
			}
		}