本文整理汇总了C#中JsonPropertyCollection.OrderBy方法的典型用法代码示例。如果您正苦于以下问题:C# JsonPropertyCollection.OrderBy方法的具体用法?C# JsonPropertyCollection.OrderBy怎么用?C# JsonPropertyCollection.OrderBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonPropertyCollection
的用法示例。
在下文中一共展示了JsonPropertyCollection.OrderBy方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateProperties
protected override IList<JsonProperty> CreateProperties (Type type, MemberSerialization serialization)
{
var properties = new JsonPropertyCollection(type);
foreach (JsonProperty property in GetSerializableMembers(type).Select(m => CreateProperty(m, serialization)).WhereNotNull())
properties.AddProperty(property);
return properties
.OrderBy(p => p.Order ?? -1)
.ThenBy(IsPropertyCollection)
.ThenBy(GetPropertyTypeDepth)
.ThenBy(p => p.PropertyName)
.ToList();
}
示例2: CreateProperties
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
{
var serializableMembers = GetSerializableMembers(type).Cast<PropertyInfo>();
if (serializableMembers == null)
throw new JsonSerializationException("Null collection of seralizable members returned.");
var typeDefinition = _ServerConfiguration.GetScimTypeDefinition(type);
var propertyCollection = new JsonPropertyCollection(type);
foreach (var member in serializableMembers)
{
var property = CreateProperty(member, memberSerialization);
if (property != null)
{
var state = _InstanceState;
var propertyNameTable = state.NameTable;
bool lockTaken = false;
try
{
Monitor.Enter(propertyNameTable, ref lockTaken);
property.PropertyName = state.NameTable.Add(property.PropertyName);
IScimTypeAttributeDefinition attributeDefinition;
if (typeDefinition != null && typeDefinition.AttributeDefinitions.TryGetValue(member, out attributeDefinition))
{
// Internal json.net deserialization logic will hit the ShouldDeserialize delegate before checking property.Writable
// Still, we'll set Writable to accurately reflect this
property.Writable = attributeDefinition.Mutability != Mutability.ReadOnly; // deserializable?
// setting property.Readable will shortcut the ShouldSerialize delegate
// INTERNAL JSON.NET LOGIC
// if (!property.Ignored && property.Readable && ShouldSerialize(writer, property, value) && IsSpecified(writer, property, value))
property.Readable = attributeDefinition.Mutability != Mutability.WriteOnly; // serializable?
// Only attach a conditional deserialization delegate if the attribute is not ReadWrite.
if (attributeDefinition.Mutability != Mutability.ReadWrite)
{
property.ShouldDeserialize = o =>
{
if (attributeDefinition.Mutability == Mutability.ReadOnly)
return false;
return true;
};
}
// Only attach a conditional serialization delegate if the attribute is not Always returned.
if (attributeDefinition.Returned != Returned.Always)
{
var existingShouldSerializeFunc = property.ShouldSerialize;
property.ShouldSerialize = o =>
{
if (attributeDefinition.Mutability == Mutability.WriteOnly || attributeDefinition.Returned == Returned.Never)
return false;
var httpMethod = AmbientRequestService.HttpMethod;
if (attributeDefinition.Returned == Returned.Default ||
(attributeDefinition.Returned == Returned.Request && (httpMethod == HttpMethod.Post || httpMethod == _Patch || httpMethod == HttpMethod.Put)))
{
var queryOptions = AmbientRequestService.QueryOptions;
if (queryOptions.Attributes.Any() && !queryOptions.Attributes.Contains(property.PropertyName))
return false;
if (queryOptions.ExcludedAttributes.Any() && queryOptions.ExcludedAttributes.Contains(property.PropertyName))
return false;
}
if (existingShouldSerializeFunc != null)
return existingShouldSerializeFunc(o);
return true;
};
}
}
}
finally
{
if (lockTaken)
Monitor.Exit(propertyNameTable);
}
propertyCollection.AddProperty(property);
}
}
return propertyCollection.OrderBy(p => p.Order ?? -1).ToList();
}