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


C# TypeInfo.GetDeclaredField方法代码示例

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


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

示例1: TryGetFieldInHierarchy

 public static FieldInfo TryGetFieldInHierarchy(TypeInfo ti, string name)
 {
     while (true)
     {
         var fi = ti.GetDeclaredField(name);
         if (fi != null)
         {
             return fi;
         }
         var baseType = ti.BaseType;
         if (baseType == null)
         {
             return null;
         }
         ti = baseType.GetTypeInfo();
     }
 }
开发者ID:knat,项目名称:SData,代码行数:17,代码来源:ReflectionExtensions.cs

示例2: GetField

 public static FieldInfo GetField(TypeInfo ti, string name)
 {
     var r = ti.GetDeclaredField(name);
     if (r != null) return r;
     throw new ArgumentException("Cannot get field: " + name);
 }
开发者ID:knat,项目名称:SData,代码行数:6,代码来源:ReflectionExtensions.cs

示例3: GetAuthorization

 private static IAuthorize GetAuthorization(TypeInfo typeInfo)
 {
     return (IAuthorize)typeInfo.GetDeclaredField("Instance").GetValue(null);
 }
开发者ID:xuchong7,项目名称:UWP_ZhiHuRiBao,代码行数:4,代码来源:AuthorizationHelper.cs

示例4: actuallyGetField

        FieldInfo actuallyGetField(TypeInfo typeInfo, string propertyName)
        {
            var current = typeInfo;
            while (current != null) {
                var ret = typeInfo.GetDeclaredField(propertyName);
                if (ret != null && ret.IsStatic) return ret;

                current = current.BaseType.GetTypeInfo();
            }

            return null;
        }
开发者ID:Wagnerp,项目名称:ReactiveUI,代码行数:12,代码来源:DependencyObjectObservableForProperty.cs

示例5: SetupPart

		void SetupPart(TypeInfo sourceType, BindingExpressionPart part)
		{
			part.Arguments = null;
			part.LastGetter = null;
			part.LastSetter = null;

			PropertyInfo property = null;
			if (part.IsIndexer)
			{
				if (sourceType.IsArray)
				{
					int index;
					if (!int.TryParse(part.Content, out index))
						Log.Warning("Binding", "{0} could not be parsed as an index for a {1}", part.Content, sourceType);
					else
						part.Arguments = new object[] { index };

					part.LastGetter = sourceType.GetDeclaredMethod("Get");
					part.LastSetter = sourceType.GetDeclaredMethod("Set");
					part.SetterType = sourceType.GetElementType();
				}

				DefaultMemberAttribute defaultMember = sourceType.GetCustomAttributes(typeof(DefaultMemberAttribute), true).OfType<DefaultMemberAttribute>().FirstOrDefault();
				string indexerName = defaultMember != null ? defaultMember.MemberName : "Item";

				part.IndexerName = indexerName;

				property = sourceType.GetDeclaredProperty(indexerName);
				if (property == null)
					property = sourceType.BaseType.GetProperty(indexerName);

				if (property != null)
				{
					ParameterInfo parameter = property.GetIndexParameters().FirstOrDefault();
					if (parameter != null)
					{
						try
						{
							object arg = Convert.ChangeType(part.Content, parameter.ParameterType, CultureInfo.InvariantCulture);
							part.Arguments = new[] { arg };
						}
						catch (FormatException)
						{
						}
						catch (InvalidCastException)
						{
						}
						catch (OverflowException)
						{
						}
					}
				}
			}
			else
			{
				property = sourceType.GetDeclaredProperty(part.Content);
				if (property == null)
					property = sourceType.BaseType.GetProperty(part.Content);
			}

			if (property != null)
			{
				if (property.CanRead && property.GetMethod.IsPublic && !property.GetMethod.IsStatic)
					part.LastGetter = property.GetMethod;
				if (property.CanWrite && property.SetMethod.IsPublic && !property.SetMethod.IsStatic)
				{
					part.LastSetter = property.SetMethod;
					part.SetterType = part.LastSetter.GetParameters().Last().ParameterType;

					if (Binding.AllowChaining)
					{
						FieldInfo bindablePropertyField = sourceType.GetDeclaredField(part.Content + "Property");
						if (bindablePropertyField != null && bindablePropertyField.FieldType == typeof(BindableProperty) && sourceType.ImplementedInterfaces.Contains(typeof(IElementController)))
						{
							MethodInfo setValueMethod = null;
							foreach (MethodInfo m in sourceType.AsType().GetRuntimeMethods())
							{
								if (m.Name.EndsWith("IElementController.SetValueFromRenderer"))
								{
									ParameterInfo[] parameters = m.GetParameters();
									if (parameters.Length == 2 && parameters[0].ParameterType == typeof(BindableProperty))
									{
										setValueMethod = m;
										break;
									}
								}
							}
							if (setValueMethod != null)
							{
								part.LastSetter = setValueMethod;
								part.IsBindablePropertySetter = true;
								part.BindablePropertyField = bindablePropertyField.GetValue(null);
							}
						}
					}
				}
			}
		}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:98,代码来源:BindingExpression.cs


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