本文整理汇总了C#中System.Reflection.MemberInfo类的典型用法代码示例。如果您正苦于以下问题:C# MemberInfo类的具体用法?C# MemberInfo怎么用?C# MemberInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MemberInfo类属于System.Reflection命名空间,在下文中一共展示了MemberInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetObjectData
public static object [] GetObjectData (object obj, MemberInfo [] members)
{
if (obj == null)
throw new ArgumentNullException ("obj");
if (members == null)
throw new ArgumentNullException ("members");
int n = members.Length;
object [] result = new object [n];
for (int i = 0; i < n; i++) {
MemberInfo member = members [i];
if (member == null)
throw new ArgumentNullException (String.Format ("members[{0}]", i));
if (member.MemberType != MemberTypes.Field)
throw new SerializationException (
String.Format ("members [{0}] is not a field.", i));
FieldInfo fi = member as FieldInfo; // members must be fields
result [i] = fi.GetValue (obj);
}
return result;
}
示例2: GetMemberModifiers
public string GetMemberModifiers(MemberInfo memberInfo)
{
ArgumentUtility.CheckNotNull ("memberInfo", memberInfo);
switch (memberInfo.MemberType)
{
case MemberTypes.Method:
case MemberTypes.Constructor:
return GetMethodModifiers (memberInfo, memberInfo);
case MemberTypes.Field:
return GetFieldModifiers ((FieldInfo)memberInfo);
case MemberTypes.Property:
var propertyInfo = (PropertyInfo) memberInfo;
return GetMethodModifiers (propertyInfo.GetGetMethod (true) ?? propertyInfo.GetSetMethod (true), memberInfo);
case MemberTypes.Event:
var eventInfo = (EventInfo) memberInfo;
return GetMethodModifiers (eventInfo.GetAddMethod (true), memberInfo);
case MemberTypes.NestedType:
return _typeModifierUtility.GetTypeModifiers ((Type) memberInfo);
case MemberTypes.Custom:
case MemberTypes.TypeInfo:
return "TODO special MemberTypes";
default:
throw new Exception ("unknown member type");
}
}
示例3: IsSerializableMember
public static bool IsSerializableMember(MemberInfo member)
{
if (member.MemberType == MemberTypes.Method)
return false;
var field = member as FieldInfo;
if (field != null)
{
if (IsSerializableFieldPredicate != null)
return IsSerializableFieldPredicate(field);
return DefaultIsSerializableField(field);
}
var property = member as PropertyInfo;
if (property != null)
{
if (IsSerializablePropertyPredicate != null)
return IsSerializablePropertyPredicate(property);
return DefaultIsSerializableProperty(property);
}
return false;
}
示例4: MemberMetadata
public MemberMetadata(MemberInfo memberInfo)
{
_type = MemberType.None;
_memberType = null;
_mi = null;
_fp = null;
memberInfo.ThrowIfNull("memberInfo", "Parameter cannot be null.");
switch (memberInfo.MemberType)
{
case MemberTypes.Field:
_type = MemberType.Field;
_mi = memberInfo;
_memberType = (memberInfo as FieldInfo).FieldType;
break;
case MemberTypes.Property:
_type = MemberType.Property;
_memberType = (memberInfo as PropertyInfo).PropertyType;
_fp = new FastReflection.FastProperty((memberInfo as PropertyInfo), true);
_mi = memberInfo;
break;
default:
break;
}
}
示例5: UpdateDefaultValue
private static void UpdateDefaultValue(MemberInfo memberInfo, MetaProperty info)
{
var defaultAttribute = memberInfo.GetCustomAttribute<DefaultValueAttribute>();
if (defaultAttribute == null) return;
info.DefaultValue = defaultAttribute.Value;
}
示例6: MemberListBinding
internal MemberListBinding(MemberInfo member, ReadOnlyCollection<ElementInit> initializers)
#pragma warning disable 618
: base(MemberBindingType.ListBinding, member)
{
#pragma warning restore 618
Initializers = initializers;
}
示例7: GetProviderObjectFromMember
private object GetProviderObjectFromMember(MemberInfo member)
{
object providerObject = null;
object instance = null;
switch (member.MemberType)
{
case MemberTypes.Property:
PropertyInfo providerProperty = member as PropertyInfo;
MethodInfo getMethod = providerProperty.GetGetMethod(true);
if (!getMethod.IsStatic)
//instance = ProviderCache.GetInstanceOf(providerType);
instance = Reflect.Construct(providerType, providerArgs);
providerObject = providerProperty.GetValue(instance, null);
break;
case MemberTypes.Method:
MethodInfo providerMethod = member as MethodInfo;
if (!providerMethod.IsStatic)
//instance = ProviderCache.GetInstanceOf(providerType);
instance = Reflect.Construct(providerType, providerArgs);
providerObject = providerMethod.Invoke(instance, null);
break;
case MemberTypes.Field:
FieldInfo providerField = member as FieldInfo;
if (!providerField.IsStatic)
//instance = ProviderCache.GetInstanceOf(providerType);
instance = Reflect.Construct(providerType, providerArgs);
providerObject = providerField.GetValue(instance);
break;
}
return providerObject;
}
示例8: SourceInfo
public SourceInfo(string source, string arg, MemberInfo memberInfo, Type type, CodeGenerator ilg) {
this.Source = source;
this.Arg = arg ?? source;
this.MemberInfo = memberInfo;
this.Type = type;
this.ILG = ilg;
}
示例9: CanBeRouteParameter
protected virtual bool CanBeRouteParameter(MemberInfo info)
{
return (info.MemberType == MemberTypes.Field || info.MemberType == MemberTypes.Property)
&& !info.HasCustomAttribute<ExcludeFromRouteAttribute>()
&& IsValidForRoute(info.GetMemberType());
}
示例10: PersistAggregationInfo
public PersistAggregationInfo(object aggregatedObject,string[] keyMapping,MemberInfo mi)
{
p_aggregatedObject=aggregatedObject;
p_mi=mi;
foreach(string mapping in keyMapping)
p_alKeyMapping.Add(new KeyMappingInfo(mapping));
}
示例11: ComputedIndex
public ComputedIndex(DocumentMapping mapping, MemberInfo[] members)
{
_members = members;
var field = mapping.FieldFor(members);
_locator = field.SqlLocator.Replace("d.", "");
_table = mapping.Table;
}
示例12: ConvertArgs
protected ISqlExpression[] ConvertArgs(MemberInfo member, ISqlExpression[] args)
{
if (member is MethodInfo)
{
var method = (MethodInfo)member;
if (method.DeclaringType.IsGenericType)
args = args.Concat(method.DeclaringType.GetGenericArguments().Select(t => (ISqlExpression)SqlDataType.GetDataType(t))).ToArray();
if (method.IsGenericMethod)
args = args.Concat(method.GetGenericArguments().Select(t => (ISqlExpression)SqlDataType.GetDataType(t))).ToArray();
}
if (ArgIndices != null)
{
var idxs = new ISqlExpression[ArgIndices.Length];
for (var i = 0; i < ArgIndices.Length; i++)
idxs[i] = args[ArgIndices[i]];
return idxs;
}
return args;
}
示例13: GetPropertyMap
public static PropertyMap GetPropertyMap(this IMappingEngine mappingEngine, MemberInfo sourceMemberInfo, Type destinationMemberType)
{
var typeMap = mappingEngine.ConfigurationProvider.FindTypeMapFor(sourceMemberInfo.DeclaringType, destinationMemberType);
if (typeMap == null)
{
const string MessageFormat = "Missing map from {0} to {1}. " +
"Create using Mapper.CreateMap<{0}, {1}>.";
var message = string.Format(MessageFormat, sourceMemberInfo.DeclaringType.Name, destinationMemberType.Name);
throw new InvalidOperationException(message);
}
var propertyMap = typeMap.GetPropertyMaps()
.FirstOrDefault(pm => pm.CanResolveValue() &&
pm.SourceMember != null && pm.SourceMember.Name == sourceMemberInfo.Name);
if (propertyMap == null)
{
const string MessageFormat = "Missing property map from {0} to {1} for {2} property. " +
"Create using Mapper.CreateMap<{0}, {1}>.";
var message = string.Format(MessageFormat, sourceMemberInfo.DeclaringType.Name, destinationMemberType.Name,
sourceMemberInfo.Name);
throw new InvalidOperationException(message);
}
return propertyMap;
}
示例14: BindingExpression
/// <summary>
/// Initializes a new instance of the <see cref="MonoMobile.Views.BindingExpression"/> class.
/// </summary>
/// <param name='binding'>
/// Binding.
/// </param>
/// <param name='targetProperty'>
/// ViewModel.<targetProperty>.
/// </param>
/// <param name='target'>
/// ViewModel to hock into.
/// </param>
/// <exception cref='ArgumentNullException'>
/// Is thrown when an argument passed to a method is invalid because it is <see langword="null" /> .
/// </exception>
public BindingExpression(Binding binding, MemberInfo targetProperty, object target)
{
if (binding == null)
throw new ArgumentNullException("binding");
if (targetProperty == null)
throw new ArgumentNullException("targetProperty");
if (target == null)
throw new ArgumentNullException("target");
Binding = binding;
Binding.Target = target;
TargetProperty = targetProperty;
if(string.IsNullOrEmpty(binding.TargetPath))
{
binding.TargetPath = targetProperty.Name;
}
object viewSource = Binding.Source;
_ViewProperty = viewSource.GetType().GetNestedMember(ref viewSource, Binding.SourcePath, true);
Binding.ViewSource = viewSource;
SourceProperty = _ViewProperty;
var dataContext = viewSource as IDataContext;
if (dataContext != null && dataContext.DataContext != null)
{
var source = dataContext.DataContext;
SourceProperty = source.GetType().GetNestedMember(ref source, Binding.SourcePath, true);
Binding.Source = source;
}
}
示例15: IsEncryptedMember
bool IsEncryptedMember(MemberInfo arg)
{
var propertyInfo = arg as PropertyInfo;
if (propertyInfo != null)
{
if (propertyInfo.GetIndexParameters().Length > 0)
{
if (conventions.IsEncryptedProperty(propertyInfo))
{
throw new Exception("Cannot encrypt or decrypt indexed properties that return a WireEncryptedString.");
}
return false;
}
return conventions.IsEncryptedProperty(propertyInfo);
}
var fieldInfo = arg as FieldInfo;
if (fieldInfo != null)
{
return fieldInfo.FieldType == typeof(WireEncryptedString);
}
return false;
}