本文整理汇总了C#中MemberSerialization类的典型用法代码示例。如果您正苦于以下问题:C# MemberSerialization类的具体用法?C# MemberSerialization怎么用?C# MemberSerialization使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MemberSerialization类属于命名空间,在下文中一共展示了MemberSerialization类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateProperties
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
{
var properties = base.CreateProperties(type, memberSerialization);
var updateableProperties = new List<JsonProperty>();
foreach (var property in properties)
{
foreach (var o in type
.GetRuntimeProperty(property.PropertyName)
.GetCustomAttributes(typeof(UpdateableAttribute), false))
{
var a = (UpdateableAttribute)o;
if (a.Updateable)
{
updateableProperties.Add(property);
}
}
}
var additionalUpdateableProperties = properties
.Where(p => !type.GetRuntimeProperty(p.PropertyName).GetCustomAttributes(typeof(UpdateableAttribute), false).Any())
.ToList();
updateableProperties.AddRange(additionalUpdateableProperties);
return updateableProperties;
}
示例2: CreateProperty
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
{
JsonProperty res = base.CreateProperty(member, memberSerialization);
res.Required = Required.AllowNull;
return res;
}
示例3: CreateProperties
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
{
var inheritedProperties = new List<JsonProperty>();
if (type.BaseType != null)
{
// recursively add properties from base types
inheritedProperties.AddRange(CreateProperties(type.BaseType, memberSerialization));
}
var jsonPropertiesFromFields = type
.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
.Select(f =>
{
var jsonProperty = CreateProperty(f, memberSerialization);
jsonProperty.Writable = jsonProperty.Readable = true;
return jsonProperty;
})
.ToArray();
var jsonPropertiesToKeep = jsonPropertiesFromFields
.Concat(inheritedProperties)
.GroupBy(p => p.UnderlyingName)
.Select(g => g.First()) //< only keep first occurrency for each underlying name - weeds out dupes
.Where(g => !(g.DeclaringType == typeof(AggregateRoot) && g.PropertyType == typeof(IUnitOfWork))) //< skip unit of work property
.ToList();
return jsonPropertiesToKeep;
}
示例4: CreateProperties
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
{
return
base.CreateProperties(type, memberSerialization)
.Where(p => !_excludedProperties.Contains(p.PropertyName))
.ToList();
}
示例5: CreateProperties
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
{
IList<JsonProperty> properties = base.CreateProperties(type, memberSerialization);
IList<JsonProperty> convertedProperties = new List<JsonProperty>();
foreach (var p in properties)
{
IDocumentPropertySetting documentProperty = null;
db.SharedSetting.Collection.ChangeDocumentPropertyForType(type, p.UnderlyingName, x => documentProperty = x);
if (documentProperty != null)
{
if (documentProperty.IgnoreProperty)
continue;
}
p.PropertyName = db.SharedSetting.Collection.ResolvePropertyName(type, p.UnderlyingName);
if (p.PropertyName == "_key" || p.PropertyName == "_id" || p.PropertyName == "_rev")
p.NullValueHandling = NullValueHandling.Ignore;
convertedProperties.Add(p);
}
return convertedProperties;
}
示例6: CreateProperty
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
{
var property = base.CreateProperty(member, memberSerialization);
if (!member.DeclaringType.IsGenericType)
return property;
var declaringType = member.DeclaringType.GetGenericTypeDefinition();
if (declaringType == typeof(ListResponse<>))
{
var type = member.ReflectedType.GenericTypeArguments[0];
var attr = type.GetCustomAttribute<RootPropertyNameAttribute>(true);
property.PropertyName = attr.PluralName;
}
if (declaringType == typeof(ItemResponse<>))
{
var type = member.ReflectedType.GenericTypeArguments[0];
var attr = type.GetCustomAttribute<RootPropertyNameAttribute>(true);
property.PropertyName = attr.SingularName;
}
return property;
}
示例7: CreateProperties
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
{
var properties = base.CreateProperties(type, memberSerialization);
var photosProperty = properties.Single(x => x.UnderlyingName == "DrawingSession");
properties.Remove(photosProperty);
return properties;
}
示例8: CreateProperty
protected override JsonProperty CreateProperty(
MemberInfo member, MemberSerialization memberSerialization) {
JsonProperty property = base.CreateProperty(member, memberSerialization);
Predicate<object> shouldSerialize = property.ShouldSerialize;
property.ShouldSerialize = obj => _includeProperty(property) && (shouldSerialize == null || shouldSerialize(obj));
return property;
}
示例9: CreateProperty
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
{
var property = base.CreateProperty(member, memberSerialization);
if (IsIgnored(property.DeclaringType, property.PropertyName))
property.ShouldSerialize = instance => false;
return property;
}
示例10: CreateProperty
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) {
JsonProperty property = base.CreateProperty(member, memberSerialization);
Predicate<object> shouldSerialize = property.ShouldSerialize;
property.ShouldSerialize = obj => (shouldSerialize == null || shouldSerialize(obj)) && !property.IsValueEmptyCollection(obj);
return property;
}
示例11: CreateProperty
/// <summary>
/// Creates a
/// <see cref="T:Newtonsoft.Json.Serialization.JsonProperty" /> for the given
/// <see cref="T:System.Reflection.MemberInfo" />.
/// </summary>
/// <param name="member">The member to create a <see cref="T:Newtonsoft.Json.Serialization.JsonProperty" /> for.</param>
/// <param name="memberSerialization">The member's parent <see cref="T:Newtonsoft.Json.MemberSerialization" />.</param>
/// <returns>
/// A created <see cref="T:Newtonsoft.Json.Serialization.JsonProperty" /> for the given <see cref="T:System.Reflection.MemberInfo" />.
/// </returns>
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
{
try
{
var property = base.CreateProperty(member, memberSerialization);
if (!property.Writable)
{
var prop = member as PropertyInfo;
if (prop != null)
{
var hasPrivateSetter = prop.GetSetMethod(true) != null;
property.Writable = hasPrivateSetter;
}
}
return property;
}
catch(Exception ex)
{
Log.Fatal(string.Format("SerializationContracts failed to create a required property for '{0}'!",member.Name));
Log.Fatal(string.Format("SerializationContracts failed with the following message: {0}", ex.Message));
Log.Fatal(string.Format("SerializationContract failures could be caused by corrupt save files."));
}
return null;
}
示例12: CreateProperty
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
{
JsonProperty property = base.CreateProperty(member, memberSerialization);
switch (_requestType)
{
case RequestType.Get:
{
if (property.AttributeProvider.GetAttributes(false).Any(w => ReferenceEquals(w.TypeId, typeof(GetColumnAttribute))))
{
return property;
}
break;
}
case RequestType.Post:
{
if (property.AttributeProvider.GetAttributes(false).Any(w => ReferenceEquals(w.TypeId, typeof(PostColumnAttribute))))
{
return property;
}
break;
}
case RequestType.Put:
{
if (property.AttributeProvider.GetAttributes(false).Any(w => ReferenceEquals(w.TypeId, typeof(PostColumnAttribute))))
{
return property;
}
break;
}
}
return null;
}
示例13: CreateProperties
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
{
return base.CreateProperties(type, memberSerialization).Where((prop) => {
return prop.PropertyName != "__interceptors" &&
prop.PropertyName != "__target";
}).ToList();
}
示例14: CreateProperty
protected override JsonProperty CreateProperty(MemberInfo member,
MemberSerialization memberSerialization)
{
JsonProperty property = base.CreateProperty(member, memberSerialization);
//Console.WriteLine("dont worry, im right here");
if (property.DeclaringType == typeof(System.Int32) &&
property.PropertyName == "ExitCode")
{
property.ShouldSerialize = instanceOfProblematic => false;
}/*
property.ShouldSerialize = instance =>
{
try
{
PropertyInfo prop = (PropertyInfo)member;
if (prop.CanRead)
{
prop.GetValue(instance, null);
return true;
}
}
catch
{
}
return false;
};*/
return property;
}
示例15: CreateProperty
/// <summary>
/// Creates a <see cref="T:Newtonsoft.Json.Serialization.JsonProperty"/> for the given <see cref="T:System.Reflection.MemberInfo"/>.
/// </summary>
/// <param name="memberSerialization">The member's parent <see cref="T:Newtonsoft.Json.MemberSerialization"/>.</param><param name="member">The member to create a <see cref="T:Newtonsoft.Json.Serialization.JsonProperty"/> for.</param>
/// <returns>
/// A created <see cref="T:Newtonsoft.Json.Serialization.JsonProperty"/> for the given <see cref="T:System.Reflection.MemberInfo"/>.
/// </returns>
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
{
var jsonProp = base.CreateProperty(member, memberSerialization);
var sfAttrs = member.GetCustomAttributes(typeof(SalesForceAttribute), true);
// if there are no attr then no need to process any further
if (!sfAttrs.Any()) return jsonProp;
var sfAttr = sfAttrs.FirstOrDefault() as SalesForceAttribute;
// if there are no attr then no need to process any further
if (sfAttr == null)
{
return jsonProp;
}
// if ignore then we should skip it and return null
if (sfAttr.Ignore || (updateResolver && sfAttr.IgnoreUpdate))
{
return null;
}
// if no fieldname then we use the default
if (string.IsNullOrEmpty(sfAttr.FieldName))
{
return jsonProp;
}
jsonProp.PropertyName = sfAttr.FieldName;
return jsonProp;
}