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


C# FieldInfo.GetValue方法代码示例

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


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

示例1: ConstructField

 private void ConstructField(FieldInfo fieldInfo)
 {
     string valueStr = null;
     if (fieldInfo.FieldType.IsArray)
     {
         var arrayBuilder = new StringBuilder();
         arrayBuilder.Append("[");
         var arr = fieldInfo.GetValue(Obj) as Array;
         foreach (var element in arr)
         {
             arrayBuilder.Append(string.Format("{0}, ", ConstructValue(element)));
         }
         arrayBuilder.Remove(arrayBuilder.Length - 2, 2);
         arrayBuilder.Append("]");
         valueStr = arrayBuilder.ToString();
     }
     else
     {
         valueStr = ConstructValue(fieldInfo.GetValue(Obj));
     }
     if (valueStr == null)
     {
         throw new Exception("Unsupported data type");
     }
     builder.Append(string.Format("\"{0}\": {1},\n", fieldInfo.Name, valueStr));
 }
开发者ID:JmanJ,项目名称:nsudotnet,代码行数:26,代码来源:Serializator.cs

示例2: Visit

        public void Visit(string settingsNamesapce, string fieldPath, FieldInfo rawSettingsField, object rawSettings)
        {
            // Skip 'sealed' fields.
            if (rawSettingsField.IsDefined<SealedAttribute>()) return;

            if (rawSettingsField.FieldType == typeof(string))
            {
                var originalString = (string)rawSettingsField.GetValue(rawSettings);
                if (originalString != null)
                {
                    var expandedString = ExpandVariables(originalString, _variables);
                    rawSettingsField.SetValue(rawSettings, expandedString);
                }
            }
            else if (rawSettingsField.FieldType == typeof(string[]))
            {
                string[] arr = (string[])rawSettingsField.GetValue(rawSettings);
                for (int i = 0; i < arr.Length; i++)
                {
                    string originalString = arr[i];
                    if (originalString != null)
                    {
                        var expandedString = ExpandVariables(originalString, _variables);
                        arr[i] = expandedString;
                    }
                }
            }
        }
开发者ID:lukyad,项目名称:Eco,代码行数:28,代码来源:ConfigurationVariableExpander.cs

示例3: push_primitive

 static void push_primitive(object obj, FieldInfo field, BuffBuilder bb)
 {
     if (field.FieldType == typeof(uint))
     {
         bb.PushUint((uint)field.GetValue(obj));
     }
     else if (field.FieldType == typeof(int))
     {
         bb.PushInt((int)field.GetValue(obj));
     }
     else if (field.FieldType == typeof(ushort))
     {
         bb.PushUshort((ushort)field.GetValue(obj));
     }
     else if (field.FieldType == typeof(short))
     {
         bb.PushShort((short)field.GetValue(obj));
     }
     else if (field.FieldType == typeof(ulong))
     {
         bb.PushUlong((ulong)field.GetValue(obj));
     }
     else if (field.FieldType == typeof(long))
     {
         bb.PushLong((long)field.GetValue(obj));
     }
     else if (field.FieldType == typeof(byte))
     {
         bb.PushByte((byte)field.GetValue(obj));
     }
     else if (field.FieldType == typeof(float))
     {
         bb.PushFloat((float)field.GetValue(obj));
     }
 }
开发者ID:jwk000,项目名称:reflectparser,代码行数:35,代码来源:GenericBuilder.cs

示例4: Visit

        public void Visit(string settingsNamesapce, string fieldPath, FieldInfo refinedSettingsField, object refinedSettings, FieldInfo rawSettingsField, object rawSettings)
        {
            if (refinedSettingsField.IsDefined<RefAttribute>()) return;

            object rawValue = null;
            object refinedValue = refinedSettingsField.GetValue(refinedSettings);
            if (refinedValue != null)
            {
                Type refinedValueType = refinedValue.GetType();
                if (refinedValueType.IsSettingsType())
                {
                    rawValue = SettingsConstruction.CreateSettingsObject(refinedValue, rawSettingsField, _typeMappings);
                }
                else if (refinedValueType.IsSettingsOrObjectArrayType())
                {
                    rawValue = SettingsConstruction.CreateSettingsArray((Array)refinedValue, rawSettingsField, _typeMappings);
                }
                else if (refinedValueType != typeof(string) && rawSettingsField.FieldType == typeof(string))
                {
                    rawValue = ToString(refinedSettingsField, refinedSettings);
                }
                else
                {
                    rawValue = refinedSettingsField.GetValue(refinedSettings);
                }
                rawSettingsField.SetValue(rawSettings, rawValue);
            }
        }
开发者ID:lukyad,项目名称:Eco,代码行数:28,代码来源:RawSettingsBuilder.cs

示例5: EvaluateMemberAccessField

        private static object EvaluateMemberAccessField(ConstantExpression node, FieldInfo fieldAccessor)
        {
            object value;

            if (fieldAccessor.IsStatic)
                value = fieldAccessor.GetValue(null);
            else
                value = node == null ? null : fieldAccessor.GetValue(node.Value);

            return ConvertMemberAccessValue(value);
        }
开发者ID:darrencauthon,项目名称:SisoDb-Provider,代码行数:11,代码来源:ExpressionEvaluator.cs

示例6: GetFieldValues

        public static string[] GetFieldValues(object ruleInfo, FieldInfo fieldInfo, Action<string> emitError)
        {
            var type = fieldInfo.FieldType;
            if (type == typeof(string))
                return new[] { (string)fieldInfo.GetValue(ruleInfo) };
            if (type == typeof(string[]))
                return (string[])fieldInfo.GetValue(ruleInfo);

            emitError("Bad type for reference on {0}.{1}. Supported types: string, string[]"
                .F(ruleInfo.GetType().Name, fieldInfo.Name));

            return new string[] { };
        }
开发者ID:rhamilton1415,项目名称:OpenRA,代码行数:13,代码来源:LintExts.cs

示例7: StepArgument

 public StepArgument(FieldInfo member, object declaringObject)
 {
     Name = member.Name;
     _get = () => member.GetValue(declaringObject);
     _set = o => member.SetValue(declaringObject, o);
     ArgumentType = member.FieldType;
 }
开发者ID:jason-roberts,项目名称:TestStack.BDDfy,代码行数:7,代码来源:StepArgument.cs

示例8: GetInstancePage

 private static IBaseElement GetInstancePage(object parent, FieldInfo field, Type type, Type parentType)
 {
     var instance = (IBaseElement) field.GetValue(parent) ?? (IBaseElement) Activator.CreateInstance(type);
     var pageAttribute = field.GetAttribute<PageAttribute>();
     pageAttribute?.FillPage((WebPage) instance, parentType);
     return instance;
 }
开发者ID:yuliapetrova,项目名称:JDITraining,代码行数:7,代码来源:WebCascadeInit.cs

示例9: TsEnumValue

        /// <summary>
        /// Initializes a new instance of the TsEnumValue class with the specific name and value.
        /// </summary>
        /// <param name="name">The name of the enum value.</param>
        /// <param name="value">The value of the enum value.</param>
        public TsEnumValue(FieldInfo field)
        {
            this.Field = field;
            this.Name = field.Name;

            var value = field.GetValue(null);

            var valueType = Enum.GetUnderlyingType(value.GetType());
            if (valueType == typeof(byte)) {
                this.Value = ((byte)value).ToString();
            }
            if (valueType == typeof(sbyte)) {
                this.Value = ((sbyte)value).ToString();
            }
            if (valueType == typeof(short)) {
                this.Value = ((short)value).ToString();
            }
            if (valueType == typeof(ushort)) {
                this.Value = ((ushort)value).ToString();
            }
            if (valueType == typeof(int)) {
                this.Value = ((int)value).ToString();
            }
            if (valueType == typeof(uint)) {
                this.Value = ((uint)value).ToString();
            }
            if (valueType == typeof(long)) {
                this.Value = ((long)value).ToString();
            }
            if (valueType == typeof(ulong)) {
                this.Value = ((ulong)value).ToString();
            }
        }
开发者ID:spelltwister,项目名称:KnockoutTypeLITE,代码行数:38,代码来源:TsEnumValue.cs

示例10: ObjectMeta

 public ObjectMeta(FieldInfo field, object obj)
 {
     Type = field.FieldType;
     Value = field.GetValue(obj);
     Name = field.Name;
     DisplayName = GetDisplayName();
 }
开发者ID:pedershk,项目名称:dotnetprograms,代码行数:7,代码来源:ObjectMeta.cs

示例11: LocalizeField

 private static void LocalizeField(Control control, ResourceManager resourceManager, FieldInfo fi, string propertyName)
 {
     MemberInfo[] mia = fi.FieldType.GetMember(propertyName);
     if (mia.GetLength(0) > 0)
     {
         try
         {
             string resourceName = control.GetType().Namespace.Replace(".", "_") + "_" + control.GetType().Name + "_" + fi.Name + "_" + propertyName;
             string localizedText = resourceManager.GetString(resourceName);
             if (localizedText == null)
             {
             }
             else if (!string.IsNullOrEmpty(localizedText))
             {
                 Object o = fi.GetValue(control);
                 if (o != null)
                 {
                     PropertyInfo pi = o.GetType().GetProperty(propertyName);
                     if (pi != null)
                     {
                         pi.SetValue(o, localizedText, null);
                     }
                 }
             }
         }
         catch (System.Resources.MissingManifestResourceException)
         {
             //just ignore
         }
         catch (Exception ex)
         {
             System.Diagnostics.Debug.WriteLine("Error when localizing: " + fi.Name + ":\r\n" + ex.ToString());
         }
     }
 }
开发者ID:deb761,项目名称:BikeMap,代码行数:35,代码来源:Localizer.cs

示例12: IsObjectField

        /// <summary>
        /// Checks to see if a field's type is an object.
        /// </summary>
        /// <param name="field"></param>
        /// <param name="obj"></param>
        /// <returns></returns>
        internal static bool IsObjectField(FieldInfo field, object obj)
        {
            var fieldValue = field.GetValue(obj);

            return fieldValue != null
                && !fieldValue.IsPrimitive();
        }
开发者ID:etkirsch,项目名称:NetDiff,代码行数:13,代码来源:ObjectExtensions.cs

示例13: WriteClassNameIfNeedBe

 private void WriteClassNameIfNeedBe(object value, FieldInfo field) {
     object fieldValue = field.GetValue(value);
     if (fieldValue == null) return;
     Type actualType = fieldValue.GetType();
     if (!field.FieldType.Equals(actualType))
         writer.WriteAttribute(Attributes.classType, actualType.AssemblyQualifiedName);
 }
开发者ID:srushti,项目名称:xstream.net,代码行数:7,代码来源:Marshaller.cs

示例14: FieldMemberDescriptor

        /// <summary>
        ///     Initializes a new instance of the <see cref="PropertyMemberDescriptor" /> class.
        /// </summary>
        /// <param name="fi">The FieldInfo.</param>
        /// <param name="accessMode">The <see cref="InteropAccessMode" /> </param>
        public FieldMemberDescriptor(FieldInfo fi, InteropAccessMode accessMode)
        {
            if (Script.GlobalOptions.Platform.IsRunningOnAOT())
                accessMode = InteropAccessMode.Reflection;

            FieldInfo = fi;
            AccessMode = accessMode;
            Name = fi.Name;
            IsStatic = FieldInfo.IsStatic;

            if (FieldInfo.IsLiteral)
            {
                IsConst = true;
                m_ConstValue = FieldInfo.GetValue(null);
            }
            else
            {
                IsReadonly = FieldInfo.IsInitOnly;
            }

            if (AccessMode == InteropAccessMode.Preoptimized)
            {
                OptimizeGetter();
            }
        }
开发者ID:eddy5641,项目名称:moonsharp,代码行数:30,代码来源:FieldMemberDescriptor.cs

示例15: CreateSpecificationFromBehavior

    public Specification CreateSpecificationFromBehavior(Behavior behavior, FieldInfo specificationField)
    {
      bool isIgnored = behavior.IsIgnored || specificationField.HasAttribute(new IgnoreAttributeFullName());
      var it = (Delegate) specificationField.GetValue(behavior.Instance);
      string name = specificationField.Name.ToFormat();

      return new BehaviorSpecification(name, specificationField.FieldType, it, isIgnored, specificationField, behavior.Context, behavior);
    }
开发者ID:hennys,项目名称:machine.specifications,代码行数:8,代码来源:SpecificationFactory.cs


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