本文整理汇总了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));
}
示例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;
}
}
}
}
示例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);
}
}
示例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));
}
示例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));
}
}
示例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);
}
}
示例7: StepArgument
public StepArgument(FieldInfo member, object declaringObject)
{
Name = member.Name;
_get = () => member.GetValue(declaringObject);
_set = o => member.SetValue(declaringObject, o);
ArgumentType = member.FieldType;
}
示例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);
}
}
示例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);
}
}
}
示例10: Fill
public override void Fill(Object obj, FieldInfo field)
{
if (CheckFillType(field))
{
field.SetValue(obj, this);
}
}
示例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);
}
示例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);
};
}
示例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);
}
}
示例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);
}
示例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);
}