示例#1
0
 object IDataContractSurrogate.GetObjectToSerialize(object obj, Type targetType)
 {
     if (prevSurrogate != null)
     {
         return(prevSurrogate.GetObjectToSerialize(obj, targetType));
     }
     return(obj);
 }
 internal static object GetObjectToSerialize(IDataContractSurrogate surrogate, object obj, Type objType, Type membertype)
 {
     if (obj == null)
         return null;
     if (DataContract.GetBuiltInDataContract(objType) != null)
         return obj;
     return surrogate.GetObjectToSerialize(obj, membertype);
 }
 public object GetObjectToSerialize(object obj, Type targetType)
 {
     if (obj is IDetector)
     {
         IDetector detector = obj as IDetector;
         return(new DetectorSurrogate(detector));
     }
     return(_dataContractSurrogate.GetObjectToSerialize(obj, targetType));
 }
 internal static object GetObjectToSerialize(IDataContractSurrogate surrogate, object obj, Type objType, Type membertype)
 {
     if (obj == null)
     {
         return(null);
     }
     if (DataContract.GetBuiltInDataContract(objType) != null)
     {
         return(obj);
     }
     return(surrogate.GetObjectToSerialize(obj, membertype));
 }
示例#5
0
        public object GetObjectToSerialize(object obj, Type targetType)
        {
            if (obj == null)
            {
                return(null);
            }

            var type = obj.GetType();

            type.GetProperties().ToList()
            .ForEach(prop =>
            {
                try
                {
                    var attr = prop.GetCustomAttributes(typeof(ConditionalDataMemberAttribute), false);
                    if (attr.Any())
                    {
                        bool isVisible = true;
                        if (((ConditionalDataMemberAttribute)attr[0]).IsClientServiceVisible != null)
                        {
                            isVisible = ((ConditionalDataMemberAttribute)attr[0]).IsClientServiceVisible;
                        }
                        //Is the user authorized
                        if (isVisible == true)
                        {
                            var proptype = prop.PropertyType;
                            prop.GetSetMethod().Invoke(obj,
                                                       new[] { proptype.IsValueType?Activator.CreateInstance(proptype) : null });
                        }
                        else
                        {
                            prop = null;
                        }
                    }
                }
                catch { }
            });

            return(_baseSerializer != null?_baseSerializer.GetObjectToSerialize(obj, targetType) : obj);
        }