当前位置: 首页>>代码示例>>C#>>正文


C# JsonPropertyCollection.OrderBy方法代码示例

本文整理汇总了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();
 }
开发者ID:binki,项目名称:Alba.Framework,代码行数:12,代码来源:JsonLinkedContractResolver.cs

示例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();
        }
开发者ID:PowerDMS,项目名称:Owin.Scim,代码行数:86,代码来源:ScimContractResolver.cs


注:本文中的JsonPropertyCollection.OrderBy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。