Пример #1
0
        protected virtual object ResolveRecord(RecordSchema writerSchema, RecordSchema readerSchema, IReader dec, Type type)
        {
            object result = FormatterServices.GetUninitializedObject(type);

            foreach (Field wf in writerSchema)
            {
                if (readerSchema.Contains(wf.Name))
                {
                    Field  rf   = readerSchema.GetField(wf.Name);
                    string name = rf.aliases?[0] ?? wf.Name;

                    PropertyInfo propertyInfo = type.GetProperty(name);
                    if (propertyInfo != null)
                    {
                        object value = Resolve(wf.Schema, rf.Schema, dec, propertyInfo.PropertyType) ?? wf.DefaultValue?.ToObject(typeof(object));
                        propertyInfo.SetValue(result, value, null);
                    }

                    FieldInfo fieldInfo = type.GetField(name);
                    if (fieldInfo != null)
                    {
                        object value = Resolve(wf.Schema, rf.Schema, dec, fieldInfo.FieldType) ?? wf.DefaultValue?.ToObject(typeof(object));
                        fieldInfo.SetValue(result, value);
                    }
                }
                else
                {
                    _skipper.Skip(wf.Schema, dec);
                }
            }

            return(result);
        }
Пример #2
0
        protected virtual IDictionary <string, object> ResolveRecord(RecordSchema writerSchema, RecordSchema readerSchema, IReader dec)
        {
            Record result = new Record(readerSchema);

            foreach (Field wf in writerSchema)
            {
                if (readerSchema.Contains(wf.Name))
                {
                    Field  rf    = readerSchema.GetField(wf.Name);
                    object value = Resolve(wf.Schema, rf.Schema, dec) ?? wf.DefaultValue?.ToObject(typeof(object));

                    AddField(result, rf.aliases?[0] ?? wf.Name, rf.Pos, value);
                }
                else
                {
                    _skipper.Skip(wf.Schema, dec);
                }
            }
            return(result.Contents);
        }