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


C# MemberSerialization类代码示例

本文整理汇总了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;
        }
开发者ID:mcoke,项目名称:Force.com-Toolkit-for-NET,代码行数:27,代码来源:UpdateableContractResolver.cs

示例2: CreateProperty

        protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
        {
            JsonProperty res = base.CreateProperty(member, memberSerialization);
            res.Required = Required.AllowNull;

            return res;
        }
开发者ID:Rigby93,项目名称:TMDbLib,代码行数:7,代码来源:FailingContractResolver.cs

示例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;
            }
开发者ID:RichieYang,项目名称:Cirqus,代码行数:29,代码来源:Sturdylizer.cs

示例4: CreateProperties

 protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
 {
     return
         base.CreateProperties(type, memberSerialization)
             .Where(p => !_excludedProperties.Contains(p.PropertyName))
             .ToList();
 }
开发者ID:ParkitectNexus,项目名称:AssetTools,代码行数:7,代码来源:DumpDataResolver.cs

示例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;
        }
开发者ID:GOArango,项目名称:arangoclient.net,代码行数:25,代码来源:DocumentContractResolver.cs

示例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;
        }
开发者ID:ElijahGlover,项目名称:GeckoApi,代码行数:26,代码来源:ResponseContractResolver.cs

示例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;
 }
开发者ID:Costo,项目名称:sketch,代码行数:7,代码来源:DrawingSessionContractResolver.cs

示例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;
 }
开发者ID:khoussem,项目名称:Exceptionless,代码行数:7,代码来源:ConditionalContractResolver.cs

示例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;
		}
开发者ID:andyliyuze,项目名称:POPForums,代码行数:7,代码来源:IgnorePropertyContractResolver.cs

示例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;
        }
开发者ID:aamarber,项目名称:Exceptionless,代码行数:7,代码来源:LowerCaseUnderscorePropertyNamesContractResolver.cs

示例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;
        }
开发者ID:ramseur,项目名称:MudDesigner,代码行数:38,代码来源:SerializationContracts.cs

示例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;
        }
开发者ID:danpadua,项目名称:runrunit4net,代码行数:34,代码来源:RunrunitSerializeEntityResolver.cs

示例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();
 }
开发者ID:kevinswiber,项目名称:zetta-dot-net,代码行数:7,代码来源:ZettaInteropContractResolver.cs

示例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;
        }
开发者ID:coder-guy22296,项目名称:groupVolumeControl,代码行数:29,代码来源:SerializableContractResolver+.cs

示例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;
        }
开发者ID:RomeoQNgo,项目名称:SalesforceSharp,代码行数:39,代码来源:SalesForceContractResolver.cs


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