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


C# IReflect.GetField方法代码示例

本文整理汇总了C#中IReflect.GetField方法的典型用法代码示例。如果您正苦于以下问题:C# IReflect.GetField方法的具体用法?C# IReflect.GetField怎么用?C# IReflect.GetField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IReflect的用法示例。


在下文中一共展示了IReflect.GetField方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetFieldByPropertyName

		private static FieldInfo GetFieldByPropertyName(IReflect viewModelType, string propertyName)
		{
			var charList = new List<char> { char.ToLower(propertyName[0]) };
			charList.AddRange(propertyName.Substring(1));
			var fieldName = new string(charList.ToArray());

			var field = viewModelType.GetField(fieldName, BindingFlags.Instance | BindingFlags.NonPublic);
			return field;
		}
开发者ID:matteomigliore,项目名称:HSDK,代码行数:9,代码来源:ReflectionCache.cs

示例2: GetMember

        private static MemberInfo GetMember(IReflect entityType, string[] memberNames)
        {
            var publicProperties =
                from name in memberNames
                select entityType.GetProperty(name, BindingFlags.Instance | BindingFlags.Public) into propertyInfo
                where propertyInfo != null && IsPropertyOk(propertyInfo)
                select propertyInfo;

            var privateProperties =
                from name in memberNames
                select entityType.GetProperty(name, BindingFlags.Instance | BindingFlags.NonPublic) into propertyInfo
                where propertyInfo != null && IsPropertyOk(propertyInfo)
                select propertyInfo;

            var publicFields =
                from name in memberNames
                select entityType.GetField(name, BindingFlags.Instance | BindingFlags.Public) into fieldInfo
                where fieldInfo != null && IsFildOk(fieldInfo)
                select fieldInfo;

            return publicProperties.OfType<MemberInfo>().Concat(privateProperties).Concat(publicFields).FirstOrDefault();
        }
开发者ID:artikh,项目名称:CouchDude,代码行数:22,代码来源:ParticularyNamedPropertyOrPubilcFieldSpecialMember.cs

示例3: SetField

        /// <summary>
        /// Sets the field.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="strMethod">The STR method.</param>
        /// <param name="objInstance">The obj instance.</param>
        /// <param name="eFlags">The e flags.</param>
        /// <param name="setValue">The set value.</param>
        /// <returns></returns>
        private static object SetField(IReflect type, string strMethod, object objInstance, BindingFlags eFlags, object setValue)
        {
            FieldInfo field;
            try
            {
                if ((eFlags == InstanceBindingFlags) && (objInstance == null))
                {
                    throw new ArgumentException("The reflection non-static object argument was invalid");
                }
                if ((eFlags == StaticBindingFlags) && (objInstance != null))
                {
                    throw new ArgumentException("The reflection static object argument was invalid");
                }
                if ((objInstance != null) && (objInstance.GetType() != (Type)type) && (objInstance.GetType().BaseType != (Type)type))
                {
                    throw new ArgumentException("The object instance was of type '" + objInstance.GetType() + "' for type '" + type + "'.");
                }
                if (string.IsNullOrEmpty(strMethod))
                {
                    throw new ArgumentException("The reflection method argument was invalid");
                }

                field = type.GetField(strMethod, eFlags);
                if (field == null)
                {
                    throw new ArgumentException("There is no field '" + strMethod + "' for type '" + type + "'.");
                }

                if (setValue.GetType() != field.FieldType)
                {
                    throw new ArgumentException("The value instance was of type '" + setValue.GetType() + "' for field type '" + field.FieldType + "'.");
                }

                field.SetValue(objInstance, setValue);
                var objRet = field.GetValue(objInstance);
                return objRet;
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.Message);
                throw;
            }
        }
开发者ID:Guzikowski,项目名称:TestMania,代码行数:52,代码来源:ReflectionTestHelper.cs

示例4: GetInstanceField

 private static object GetInstanceField(IReflect type, object instance, string fieldName)
 {
     const BindingFlags bindFlags = BindingFlags.Instance | BindingFlags.NonPublic;
     var field = type.GetField(fieldName, bindFlags);
     return field.GetValue(instance);
 }
开发者ID:TwilioDevEd,项目名称:airtng-csharp,代码行数:6,代码来源:TwiMLResultExtensions.cs

示例5: GetField

 private static FieldInfo GetField(IReflect type, string fieldName) {
     return type.GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
 }
开发者ID:kavand,项目名称:Kavand.Windows.Controls,代码行数:3,代码来源:PersianDateTimeFormatInfo.cs


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