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


C# FieldInfo.SetValue方法代码示例

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


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

示例1: ApplyToFieldInfo

 public override void ApplyToFieldInfo(FieldInfo Info, ISerializablePacket Packet, Type Field)
 {
     if (Field.Equals(typeof(bool)))
         Info.SetValue(Packet, val);
     else
         Info.SetValue(Packet, Convert.ChangeType((bool)val, Info.FieldType));
 }
开发者ID:TheGhostGroup,项目名称:RiftEMU,代码行数:7,代码来源:BoolBit.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: ApplyToFieldInfo

        public override void ApplyToFieldInfo(FieldInfo Info, ISerializablePacket Packet, Type Field)
        {
            if (Field.Equals(typeof(List<uint>)))
            {
                List<uint> Luint = new List<uint>();
                foreach (ISerializableField Value in (List<ISerializableField>)val)
                    Luint.Add(Value.GetUint());
                Info.SetValue(Packet, Luint);
            }
            else if(Field.Equals(typeof(List<ISerializablePacket>)))
            {
                List<ISerializablePacket> Packets = new List<ISerializablePacket>();
                foreach (ISerializableField Value in (List<ISerializableField>)val)
                    Packets.Add(Value.GetPacket());
                Info.SetValue(Packet, Packets);
            }
            else if (Field.Equals(typeof(List<bool>)))
            {
                List<bool> Bools = new List<bool>();
                foreach (ISerializableField Value in (List<ISerializableField>)val)
                    Bools.Add((bool)Value.val);
                Info.SetValue(Packet, Bools);
            }
            else if (Field.Equals(typeof(List<float>)))
            {
                List<float> floats = new List<float>();
                foreach (ISerializableField Value in (List<ISerializableField>)val)
                    floats.Add(Value.GetFloat());

                Info.SetValue(Packet, floats);
            }
        }
开发者ID:Easun,项目名称:ChameleonProject,代码行数:32,代码来源:ListBit.cs

示例4: ApplyToFieldInfo

 public override void ApplyToFieldInfo(FieldInfo Info, ISerializablePacket Packet, Type Field)
 {
     if (Field.Equals(typeof(byte[])))
         Info.SetValue(Packet, val);
     else if(Field.Equals(typeof(string)))
         Info.SetValue(Packet,Marshal.ConvertToString((byte[])val));
 }
开发者ID:Easun,项目名称:RiftEMU,代码行数:7,代码来源:ArrayBit.cs

示例5: ApplyToFieldInfo

 public override void ApplyToFieldInfo(FieldInfo Info, ISerializablePacket Packet, Type Field)
 {
     if (Field.Equals(typeof(byte[])))
         Info.SetValue(Packet, (byte[])val);
     else if (Field.Equals(typeof(long)))
     {
         //Array.Reverse((val as byte[]));
         Info.SetValue(Packet, BitConverter.ToInt64((byte[])val, 0));
     }
 }
开发者ID:Easun,项目名称:RiftEMU,代码行数:10,代码来源:Raw8Bit.cs

示例6: ___SetFieldValue

 private void ___SetFieldValue(FieldInfo field, ConnectionStringSettings connectionStringSettings, string mapFromKey)
 {
     if (field.FieldType == typeof (ConnectionStringSettings))
     {
         field.SetValue(this,connectionStringSettings);
     }
     else if (field.FieldType == typeof (string))
     {
         field.SetValue(this,connectionStringSettings.ConnectionString);
     }
     else 
     {
         throw new ConfigMappingException(string.Format("Connection string mappings must be either of type System.String or System.Configuration.ConnectionStringSettings. The type provided was {0}", field.FieldType.Name), mapFromKey);
     }
 }
开发者ID:martinburrows,项目名称:ConfigMapper,代码行数:15,代码来源:ConnectionStrings.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: 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

示例9: Visit

        public void Visit(string settingsNamespace, string fieldPath, FieldInfo rawSettingsField, object rawSettings)
        {
            var defaultAttr = rawSettingsField.GetCustomAttribute<DefaultAttribute>();
            if (defaultAttr != null)
            {
                if (!CanAssign(rawSettingsField, defaultAttr.Value))
                    throw new ConfigurationException("Invalid default field value for {0}.{1}: '{2}'.", rawSettingsField.DeclaringType.Name, rawSettingsField.Name, defaultAttr.Value);

                object targetValue = rawSettingsField.GetValue(rawSettings);
                if (targetValue == null)
                {
                    if (rawSettingsField.FieldType == typeof(string)) rawSettingsField.SetValue(rawSettings, defaultAttr.Value.ToString());
                    else rawSettingsField.SetValue(rawSettings, defaultAttr.Value);
                }
            }
        }
开发者ID:lukyad,项目名称:Eco,代码行数:16,代码来源:DefaultValueSetter.cs

示例10: Fill

 public override void Fill(Object obj, FieldInfo field)
 {
     if (CheckFillType(field))
     {
       field.SetValue(obj, this);
     }
 }
开发者ID:unhammer,项目名称:gimp-sharp,代码行数:7,代码来源:TypeParameter.cs

示例11: SetValue

 public static void SetValue(FieldInfo fi, object obj, object val)
 {
     Type fieldType = fi.FieldType;
     if (typeof(INullable).IsAssignableFrom(fieldType))
         val = Wrap(fieldType, val);
     fi.SetValue(obj, val);
 }
开发者ID:valery-shinkevich,项目名称:sooda,代码行数:7,代码来源:SqlTypesUtil.cs

示例12: CreateSetter

		public static UserDefinedTypeImporter.SetterDelegate CreateSetter(Type type, FieldInfo field)
		{
			return (Importer importer, object value) =>
			{
				var fieldValue = importer.Read(field.FieldType);
				field.SetValue(value, fieldValue);
			};
		}
开发者ID:WBasti,项目名称:CoherentUIMobileOpenSource,代码行数:8,代码来源:DynamicCode_Mobile.cs

示例13: Fill

 public override void Fill(Object obj, FieldInfo field)
 {
     if (field.FieldType is AliasParameter) {
     field.SetValue(obj, Data);
       } else {
     Console.WriteLine("AliasParameter.Fill: " + field.FieldType);
       }
 }
开发者ID:unhammer,项目名称:gimp-sharp,代码行数:8,代码来源:AliasParameter.cs

示例14: AssignElement

        private void AssignElement(FieldInfo field, WatControl control)
        {
            var auto = field.GetValue(control) as AutoWatElement;
            if (auto == null)
                return; // This field is not marked with Auto

            var element = CreateElement(field.Name, auto, control);
            field.SetValue(control, element);
        }
开发者ID:behaug,项目名称:Venturous,代码行数:9,代码来源:AutoFieldInitializer.cs

示例15: ConfigInjection

            private readonly FieldInfo fieldInfo; //internal configuration field.

            /// <summary>
            /// Creates ConfigInjection instance.
            /// </summary>
            /// <param name="updateManager">UpdateManager instance to which configuration is to be injected.</param>
            /// <param name="configuration">The configuration for injection.</param>
            public ConfigInjection(DynUpdateManager updateManager, UpdateManagerConfiguration configuration)
            {
                this.updateManager = updateManager;
                fieldInfo = updateManager.GetType()
                    .GetField("configuration", BindingFlags.NonPublic | BindingFlags.Instance);
                Assert.IsNotNull(fieldInfo);

                this.configuration = fieldInfo.GetValue(updateManager);
                fieldInfo.SetValue(updateManager, configuration);
            }
开发者ID:whztt07,项目名称:Dynamo,代码行数:17,代码来源:UpdateManagerTests.cs


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