コード例 #1
0
        public object ConvertToObject(MtObject mtObject)
        {
            var instance = Activator.CreateInstance(mtObject.MtTypeDefinition.ClrType);

            var properties = mtObject.MtTypeDefinition.ClrType.GetProperties(BindingFlags.Instance | BindingFlags.Public);

            foreach (var propertyInfo in properties)
            {
                if (!propertyInfo.CanWrite || propertyInfo.GetIndexParameters().Length > 0)
                {
                    continue;
                }

                var mtProp = mtObject.MtTypeDefinition.Properties.FirstOrDefault(x => x.Name == propertyInfo.Name);
                if (mtProp == null)
                {
                    continue;
                }

                var value = mtObject.Values[mtProp.Index];

                // if property is of value type but we have null - skip
                if (!(propertyInfo.PropertyType.IsValueType) && value == null)
                {
                    continue;
                }

                propertyInfo.SetValue(instance, ConvertFromDbCanonicalFormat(value, mtProp.MtPropertyType));
            }

            return(instance);
        }
コード例 #2
0
 public MtObjectChange(MtObject o, MtObjectChangeType type, AstNode constraint, string fr8AccountId)
 {
     Object       = o;
     Type         = type;
     Constraint   = constraint;
     Fr8AccountId = fr8AccountId;
 }
コード例 #3
0
        public MtObject ConvertToMt(object instance, MtTypeDefinition mtTypeDefinition)
        {
            var mtObject   = new MtObject(mtTypeDefinition);
            var properties = instance.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public);

            foreach (var propertyInfo in properties)
            {
                if (!propertyInfo.CanRead || propertyInfo.GetIndexParameters().Length > 0)
                {
                    continue;
                }

                var mtProp = mtTypeDefinition.Properties.FirstOrDefault(x => x.Name == propertyInfo.Name);
                if (mtProp == null)
                {
                    continue;
                }

                var value = propertyInfo.GetValue(instance);

                mtObject.Values[mtProp.Index] = ConvertToDbCanonicalFormat(value);
            }

            return(mtObject);
        }