本文整理汇总了C#中System.Reflection.MemberInfo.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# MemberInfo.GetType方法的具体用法?C# MemberInfo.GetType怎么用?C# MemberInfo.GetType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.MemberInfo
的用法示例。
在下文中一共展示了MemberInfo.GetType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetMemberValue
/// <summary> Vrátí hodnotu fieldu nebo propertry objektu. </summary>
/// <param name="member"> Popis fieldu nebo property. </param>
/// <param name="obj"> Objekt. </param>
/// <returns> Hodnota fieldu nebo property. </returns>
public static object GetMemberValue ( MemberInfo member, object obj )
{
if ( member is FieldInfo )
return ((FieldInfo)member).GetValue( obj );
else if ( member is PropertyInfo )
return ((PropertyInfo)member).GetValue( obj, null );
else
throw new Exception( string.Format( "OtherCode.GetMemberValue: unsupported member type '{0}', class '{1}'", member.GetType(), obj.GetType() ) );
}
示例2: GetMemberType
/// <summary> Vrátí typ fieldu nebo property objektu. </summary>
/// <param name="member"> Popis fieldu nebo property. </param>
/// <returns> Typ fieldu nebo property. </returns>
public static Type GetMemberType ( MemberInfo member )
{
if ( member is FieldInfo )
return ((FieldInfo)member).FieldType;
else if ( member is PropertyInfo )
return ((PropertyInfo)member).PropertyType;
else
throw new Exception( string.Format( "OtherCode.GetMemberType: unsupported member type '{0}'", member.GetType() ) );
}
示例3: SetMemberValue
/// <summary> Nastaví hodnotu fieldu nebo propertry objektu. </summary>
/// <param name="member"> Popis fieldu nebo property. </param>
/// <param name="obj"> Objekt. </param>
/// <param name="value"> Nastavovaná hodnota. </param>
public static void SetMemberValue ( MemberInfo member, object obj, object value )
{
if ( member is FieldInfo )
((FieldInfo)member).SetValue( obj, value );
else if ( member is PropertyInfo )
((PropertyInfo)member).SetValue( obj, value, null );
else
throw new Exception( string.Format( "OtherCode.SetMemberValue: unsupported member type '{0}', class '{1}', value '{2}'", member.GetType(), obj.GetType(), value.GetType() ) );
}
示例4: IsMemberEqual
// Compares two members. The .Equals method on the member
// does not work since the ReflectedType for the members might
// be different and we don't care about that.
internal static bool IsMemberEqual(MemberInfo m1,
MemberInfo m2)
{
if (!m1.GetType().Equals(m1.GetType()))
return false;
if (!m1.DeclaringType.Equals(m2.DeclaringType))
return false;
if (!m1.Name.Equals(m2.Name))
return false;
// All but constructors and methods are equal at this point
if (!(m1 is MethodBase))
return true;
// The method handles check that the methods are actually
// the same
if (((MethodBase)m1).MethodHandle.
Equals(((MethodBase)m2).MethodHandle))
return true;
return false;
}
示例5: GetMemberType
internal Type GetMemberType(MemberInfo objMember)
{
if (objMember is FieldInfo)
{
return ((FieldInfo) objMember).FieldType;
}
if (!(objMember is PropertyInfo))
{
throw new SerializationException(Environment.GetResourceString("Serialization_SerMemberInfo", new object[] { objMember.GetType() }));
}
return ((PropertyInfo) objMember).PropertyType;
}
示例6: GetMemberType
internal Type GetMemberType(MemberInfo objMember)
{
if (objMember is FieldInfo)
{
return ((FieldInfo) objMember).FieldType;
}
if (!(objMember is PropertyInfo))
{
throw new SerializationException(string.Format(CultureInfo.CurrentCulture, SoapUtil.GetResourceString("Serialization_SerMemberInfo"), new object[] { objMember.GetType() }));
}
return ((PropertyInfo) objMember).PropertyType;
}
示例7: Create
public static MemberAccessor Create(MemberInfo memberInfo, bool requiresSetter)
{
FieldInfo fieldInfo;
PropertyInfo propertyInfo;
if ((fieldInfo = memberInfo as FieldInfo) != null)
{
return new FieldMemberAccessor(fieldInfo);
}
else if ((propertyInfo = memberInfo as PropertyInfo) != null)
{
return new PropertyMemberAccessor(propertyInfo, requiresSetter);
}
throw new NotSupportedException(memberInfo.GetType().ToString());
}
示例8: MemberMapInfo
internal MemberMapInfo(MemberInfo member, string columnName, SqlType columnType, bool nullable, ConstraintMapInfo[] constraints)
{
Member = member;
ColumnName = columnName;
ColumnType = columnType;
IsNullable = nullable;
Constraints = constraints;
if (member is PropertyInfo) {
MemberType = ((PropertyInfo) member).PropertyType;
} else if (member is FieldInfo) {
MemberType = ((FieldInfo) member).FieldType;
} else {
throw new ArgumentException(String.Format("Member of type '{0}' is not permitted.", member.GetType()));
}
}
示例9: Create
public static IReflectionAccessor Create(MemberInfo memberInfo)
{
var propInfo = memberInfo as PropertyInfo;
if (propInfo != null)
{
return new PropertyInfoAccessor(propInfo);
}
var fieldInfo = memberInfo as FieldInfo;
if (fieldInfo != null)
{
return new FieldInfoAccessor(fieldInfo);
}
throw new ArgumentException("invalid member info:" + memberInfo.GetType());
}
示例10: GetMemberType
protected static Type GetMemberType(MemberInfo memberInfo)
{
var propertyInfo = memberInfo as PropertyInfo;
var fieldInfo = memberInfo as FieldInfo;
if (propertyInfo != null)
{
return propertyInfo.PropertyType;
}
if (fieldInfo != null)
{
return fieldInfo.FieldType;
}
throw new NotSupportedException(string.Format("{0} not supported", memberInfo.GetType().Name));
}
示例11: GetObjectMemberValue
/// <summary>
/// Gets the object member value.
/// </summary>
/// <param name="data">The data.</param>
/// <param name="member">The member.</param>
/// <returns>The value of object member.</returns>
/// <exception cref="ArgumentException">If <paramref name="member"/> is of unknown type.</exception>
public object GetObjectMemberValue(object data, MemberInfo member)
{
object ret;
if (member is PropertyInfo)
{
PropertyInfo propInfo = (PropertyInfo)member;
ret = propInfo.GetValue(data, null);
}
else if (member is FieldInfo)
{
FieldInfo fieldInfo = (FieldInfo)member;
ret = fieldInfo.GetValue(data);
}
else
{
// Unknown member type - throw it away
string message = "Unknown type of member: " + (null == member ? "(null)" : member.GetType().FullName);
Log.Error(message);
throw new ArgumentException(message, "member");
}
return ret;
}
示例12: GetGetterFast
// ashmind: this method is a bit too hardcoded, on the other hand it does not make
// sense to ask IPropertyAccessor to find accessor by name when we already have MemberInfo
private IGetter GetGetterFast(Type type, MemberInfo member)
{
if (member is PropertyInfo)
return new BasicPropertyAccessor.BasicGetter(type, (PropertyInfo)member, member.Name);
if (member is FieldInfo)
return new FieldAccessor.FieldGetter((FieldInfo)member, type, member.Name);
throw new ArgumentException("Can not get getter for " + member.GetType() + ".", "member");
}
示例13: ToSignature
internal static string ToSignature(MemberInfo mi)
{
if (mi is PropertyInfo)
return ToSignature ((PropertyInfo)mi);
if (mi is FieldInfo)
return ToSignature ((FieldInfo)mi);
if (mi is ConstructorInfo)
return ToSignature ((ConstructorInfo)mi);
if (mi is MethodInfo)
return ToSignature ((MethodInfo)mi);
return "[unknown: " + mi.GetType ().FullName + "]";
}
示例14: IsDynamic
/// <summary>Checks if the given member is from a class being compiled at the moment.</summary>
/// <param name="member">The member to check.</param>
/// <returns>True if the member is from a dynamic type (one being compiled); false otherwise.</returns>
public static bool IsDynamic(MemberInfo member){
Type t=member.GetType();
return (t==typeof(MethodBuilder)||t==typeof(FieldBuilder)||t==typeof(ConstructorBuilder)||t==typeof(TypeBuilder)||t==typeof(LocalBuilder)||t==typeof(PropertyBuilder)||t==typeof(ParameterBuilder));
}
示例15: IsDefined
internal static bool IsDefined(MemberInfo target, Type caType, bool inherit) {
// JScript implements subclasses of MemberInfo which throw an exception when Module is
// accessed. We know that none of these are from a ReflectionOnly assembly.
Type t = target.GetType();
if (t.Assembly == typeof(CustomAttribute).Assembly || !target.Module.Assembly.ReflectionOnly)
return target.IsDefined(caType, inherit);
return CustomAttribute.CheckForCustomAttribute(CustomAttributeData.GetCustomAttributes(target), caType);
}