本文整理汇总了C#中System.Reflection.MemberInfo.SetValue方法的典型用法代码示例。如果您正苦于以下问题:C# MemberInfo.SetValue方法的具体用法?C# MemberInfo.SetValue怎么用?C# MemberInfo.SetValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.MemberInfo
的用法示例。
在下文中一共展示了MemberInfo.SetValue方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InjectIntroducedField
/// <summary>
/// Injects the introduced field.
/// </summary>
/// <param name="advice">The advice.</param>
/// <param name="adviceMemberInfo">The member information.</param>
/// <param name="advisedType">Type of the advised.</param>
/// <exception cref="System.InvalidOperationException">Internal error, can not find matching introduced field</exception>
private static void InjectIntroducedField(IAdvice advice, MemberInfo adviceMemberInfo, Type advisedType)
{
adviceMemberInfo.SetValue(advice, Activator.CreateInstance(adviceMemberInfo.GetMemberType(), advice, adviceMemberInfo));
}
示例2: Set
public void Set(MemberInfo member, Object instance, Byte[] buffer, ref Int32 currentPosition)
{
var length = buffer.ReadInt32(currentPosition);
currentPosition += sizeof (Int32);
member.SetValue(instance, _encoding.GetString(buffer, currentPosition, length - 1));
currentPosition += length;
}
示例3: DecryptMember
void DecryptMember(object target, MemberInfo property)
{
var encryptedValue = property.GetValue(target);
if (encryptedValue == null)
{
return;
}
var wireEncryptedString = encryptedValue as WireEncryptedString;
if (wireEncryptedString != null)
{
Decrypt(wireEncryptedString);
}
else
{
property.SetValue(target, DecryptUserSpecifiedProperty(encryptedValue));
}
Log.Debug(property.Name + " decrypted successfully");
}
示例4: EncryptMember
void EncryptMember(object target, MemberInfo member)
{
var valueToEncrypt = member.GetValue(target);
if (valueToEncrypt == null)
{
return;
}
var wireEncryptedString = valueToEncrypt as WireEncryptedString;
if (wireEncryptedString != null)
{
var encryptedString = wireEncryptedString;
EncryptWireEncryptedString(encryptedString);
//we clear the properties to avoid having the extra data serialized
encryptedString.EncryptedBase64Value = null;
encryptedString.Base64Iv = null;
}
else
{
member.SetValue(target, EncryptUserSpecifiedProperty(valueToEncrypt));
}
Log.Debug(member.Name + " encrypted successfully");
}
示例5: EncryptMember
void EncryptMember(object target, MemberInfo member)
{
var valueToEncrypt = member.GetValue(target);
if (valueToEncrypt == null)
return;
if (EncryptionService == null)
throw new InvalidOperationException(
String.Format("Cannot encrypt field {0} because no encryption service was configured.",
member.Name));
if (valueToEncrypt is WireEncryptedString)
{
var encryptedString = (WireEncryptedString)valueToEncrypt;
EncryptWireEncryptedString(encryptedString);
if (!ConfigureEncryption.EnsureCompatibilityWithNSB2)
{
//we clear the properties to avoid having the extra data serialized
encryptedString.EncryptedBase64Value = null;
encryptedString.Base64Iv = null;
}
}
else
{
member.SetValue(target, EncryptUserSpecifiedProperty(valueToEncrypt));
}
Log.Debug(member.Name + " encrypted successfully");
}
示例6: DecryptMember
void DecryptMember(object target, MemberInfo property)
{
var encryptedValue = property.GetValue(target);
if (encryptedValue == null)
return;
if (EncryptionService == null)
throw new InvalidOperationException(
String.Format("Cannot decrypt field {0} because no encryption service was configured.", property.Name));
if (encryptedValue is WireEncryptedString)
{
Decrypt((WireEncryptedString)encryptedValue);
}
else
{
property.SetValue(target, DecryptUserSpecifiedProperty(encryptedValue));
}
Log.Debug(property.Name + " decrypted successfully");
}
示例7: EncryptMember
void EncryptMember(object target, MemberInfo member)
{
var valueToEncrypt = member.GetValue(target);
if (valueToEncrypt == null)
{
return;
}
if (EncryptionService == null)
{
throw new Exception(String.Format("Cannot encrypt field {0} because no encryption service was configured.",member.Name));
}
var wireEncryptedString = valueToEncrypt as WireEncryptedString;
if (wireEncryptedString != null)
{
var encryptedString = wireEncryptedString;
EncryptWireEncryptedString(encryptedString);
//we clear the properties to avoid having the extra data serialized
encryptedString.EncryptedBase64Value = null;
encryptedString.Base64Iv = null;
}
else
{
member.SetValue(target, EncryptUserSpecifiedProperty(valueToEncrypt));
}
Log.Debug(member.Name + " encrypted successfully");
}
示例8: CreateEnumCollectionSection
private ISection CreateEnumCollectionSection(MemberInfo member, string caption, object view, List<Binding> bindings)
{
Type memberType = GetTypeForMember(member);
object context = view;
var dataContext = view as IDataContext;
if (dataContext != null)
{
context = dataContext.DataContext;
}
SetDefaultConverter(view, member, "DataContext", new EnumCollectionConverter(), null, bindings);
member = GetMemberFromDataContext(member, ref context);
var csection = new Section() { IsMultiselect = true, Opaque = false };
var collection = member.GetValue(view);
if (collection == null)
{
var collectionType = typeof(EnumCollection<>);
var enumType = memberType.GetGenericArguments().FirstOrDefault();
Type[] generic = { enumType };
collection = Activator.CreateInstance(collectionType.MakeGenericType(generic));
member.SetValue(view, collection);
}
var index = 0;
var items = (EnumCollection)collection;
foreach (var item in items.Items)
{
var checkboxElement = new CheckboxElement(item.Description)
{
Item = item,
Index = index,
DataContext = item.IsChecked,
Group = item.GroupName
};
csection.Add(checkboxElement);
index++;
}
csection.DataContext = memberType;
csection.ViewBinding.DataContextCode = DataContextCode.EnumCollection;
return csection;
}