Example #1
0
        private JNode DataToJNode(StructuralAspect aspect)
        {
            var jn    = new JNode();
            var stype = aspect.StructuralType;

            stype.DataProperties.ForEach(dp => {
                var val = aspect.GetValue(dp.Name);
                // handle nonscalar dps
                if (dp.IsComplexProperty)
                {
                    jn.AddJNode(dp.NameOnServer, DataToJNode(((IComplexObject)val).ComplexAspect));
                }
                else
                {
                    jn.AddPrimitive(dp.NameOnServer, val, TypeFns.GetDefaultValue(dp.DataType.ClrType));
                }
            });
            return(jn);
        }
Example #2
0
        private void SetPropertyToDefaultValue(Object entity, String propertyName)
        {
            var propInfo = entity.GetType().GetProperty(propertyName,
                                                        BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

            // exit if unmapped property.
            if (propInfo == null)
            {
                return;
            }
            if (propInfo.CanWrite)
            {
                var val = TypeFns.GetDefaultValue(propInfo.PropertyType);
                propInfo.SetValue(entity, val, null);
            }
            else
            {
                throw new Exception(String.Format("Unable to write to property '{0}' on type: '{1}'", propertyName,
                                                  entity.GetType()));
            }
        }