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


C# Type.GetMember方法代码示例

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


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

示例1: ItemMetadata

        /// <summary>
        /// Creates a new ItemMetadta
        /// </summary>
        /// <param name="t"></param>
        /// <param name="tableName"></param>
        /// <param name="primaryName"></param>
        /// <param name="secondaryName"></param>
        public ItemMetadata(Type t, string tableName, string primaryName, string secondaryName)
        {
            Table = tableName;
            Primary = primaryName;
            Secondary = secondaryName;
            HasSecondary = !string.IsNullOrEmpty(secondaryName);
            ObjecType = t;

            //

            var p = ObjecType.GetMember(Primary).FirstOrDefault();
            if (p == null)
                throw new Exception("Invalid PrimaryKey");

            if (p is FieldInfo)
            {
                PrimaryIsField = true;
                PrimaryType = ((FieldInfo)p).FieldType;
            }
            else if (p is PropertyInfo)
            {
                PrimaryIsField = false;
                PrimaryType = ((PropertyInfo)p).PropertyType;

            }
            else
                throw new Exception("Invalid PrimaryKey");

            if (!IsValidKeyType(PrimaryType))
                throw new Exception("Invalid Key. Secondary key must be a string or a number.");
            //

            if (HasSecondary)
            {
                var s = ObjecType.GetMember(Secondary).FirstOrDefault();
                if (s == null)
                    throw new Exception("Invalid SecondaryKey");

                if (s is FieldInfo)
                {
                    SecondaryIsField = true;
                    SecondaryType = ((FieldInfo)s).FieldType;
                }
                else if (s is PropertyInfo)
                {
                    SecondaryIsField = false;
                    SecondaryType = ((PropertyInfo)s).PropertyType;
                }
                else
                    throw new Exception("Invalid SecondaryKey");

                if (!IsValidKeyType(PrimaryType))
                    throw new Exception("Invalid Key. Secondary key must be a string or a number.");
            }
        }
开发者ID:realtime-framework,项目名称:unity3d-plugin,代码行数:62,代码来源:ItemMetadata.cs

示例2: AccessorPropertyMapper

 public AccessorPropertyMapper(Type declaringType, string propertyName, Action<string> accesorValueSetter)
 {
     PropertyName = propertyName;
     if (declaringType == null)
     {
         throw new ArgumentNullException("declaringType");
     }
     MemberInfo member = null;
     if (propertyName != null)
     {
         member = declaringType.GetMember(propertyName, FieldBindingFlag).FirstOrDefault();
     }
     if (member == null)
     {
         accesorValueSetter("none");
         canChangeAccessor = false;
     }
     else if ((member as FieldInfo) != null)
     {
         accesorValueSetter("field");
         canChangeAccessor = false;
     }
     this.declaringType = declaringType;
     this.propertyName = propertyName;
     setAccessor = accesorValueSetter;
 }
开发者ID:alvarezdaniel,项目名称:conformando-nhibernate,代码行数:26,代码来源:AccessorPropertyMapper.cs

示例3: GetFastMethodInvoker

        public Func<object, object[], object> GetFastMethodInvoker(Type declaringType, string memberName, Type[] typeParameters, Type[] argumentTypes, BindingFlags bindingFlags)
        {
            ArgumentUtility.CheckNotNull ("declaringType", declaringType);
              ArgumentUtility.CheckNotNull ("memberName", memberName);
              ArgumentUtility.CheckNotNull ("typeParameters", typeParameters);
              ArgumentUtility.CheckNotNull ("argumentTypes", argumentTypes);

              var overloads = (MethodBase[]) declaringType.GetMember (memberName, MemberTypes.Method, bindingFlags);

              if (overloads.Length == 0)
            throw new MissingMethodException (string.Format ("Method '{0}' not found on type '{1}'.", memberName, declaringType));

              MethodInfo method;
              if (typeParameters.Length > 0)
              {
            var methods = overloads.Where (m => m.GetGenericArguments ().Length == typeParameters.Length)
                               .Select (m => ((MethodInfo) m).MakeGenericMethod (typeParameters));

            method = methods.SingleOrDefault (m => m.GetParameters ().Select (p => p.ParameterType).SequenceEqual (argumentTypes));
            if (method == null)
              throw new MissingMethodException (string.Format ("Generic overload of method '{0}`{1}' not found on type '{2}'.", memberName, typeParameters.Length, declaringType));
              }
              else
              {
            method = (MethodInfo) Type.DefaultBinder.SelectMethod (bindingFlags, overloads, argumentTypes, null);
            if (method == null)
              throw new MissingMethodException (string.Format ("Overload of method '{0}' not found on type '{1}'.", memberName, declaringType));
              }

              return CreateDelegateForMethod (method);
        }
开发者ID:re-motion,项目名称:Mixins-XRef,代码行数:31,代码来源:FastMemberInvokerGenerator.cs

示例4: GetAddMethod

 private static MethodInfo GetAddMethod(Type type, int paramCount, out bool hasMoreThanOne)
 {
     MethodInfo info = null;
     MemberInfo[] infoArray = type.GetMember("Add", MemberTypes.Method, GetBindingFlags(type));
     if (infoArray != null)
     {
         foreach (MemberInfo info2 in infoArray)
         {
             MethodInfo method = (MethodInfo) info2;
             if (TypeReflector.IsPublicOrInternal(method))
             {
                 ParameterInfo[] parameters = method.GetParameters();
                 if ((parameters != null) && (parameters.Length == paramCount))
                 {
                     if (info != null)
                     {
                         hasMoreThanOne = true;
                         return null;
                     }
                     info = method;
                 }
             }
         }
     }
     hasMoreThanOne = false;
     return info;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:27,代码来源:CollectionReflector.cs

示例5: AnalyzeInvokeAttribute

 private void AnalyzeInvokeAttribute(RuleAnalysis analysis, Type contextType, Stack<MemberInfo> methodStack, CodeExpression targetExpression, RulePathQualifier targetQualifier, CodeExpressionCollection argumentExpressions, ParameterInfo[] parameters, List<CodeExpression> attributedExpressions)
 {
     foreach (MemberInfo info in contextType.GetMember(this.methodInvoked, MemberTypes.Property | MemberTypes.Method, BindingFlags.FlattenHierarchy | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance))
     {
         if (!methodStack.Contains(info))
         {
             methodStack.Push(info);
             object[] customAttributes = info.GetCustomAttributes(typeof(RuleAttribute), true);
             if ((customAttributes != null) && (customAttributes.Length != 0))
             {
                 foreach (RuleAttribute attribute in (RuleAttribute[]) customAttributes)
                 {
                     RuleReadWriteAttribute attribute2 = attribute as RuleReadWriteAttribute;
                     if (attribute2 != null)
                     {
                         attribute2.Analyze(analysis, info, targetExpression, targetQualifier, argumentExpressions, parameters, attributedExpressions);
                     }
                     else
                     {
                         ((RuleInvokeAttribute) attribute).AnalyzeInvokeAttribute(analysis, contextType, methodStack, targetExpression, targetQualifier, argumentExpressions, parameters, attributedExpressions);
                     }
                 }
             }
             methodStack.Pop();
         }
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:27,代码来源:RuleInvokeAttribute.cs

示例6: ShitFunc

        // [JUNK]

        void ShitFunc(Type T, string mtdName)
        {
            //  T.InvokeMember(mtdName, BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.Public, null, null, null);
            RuntimeMethodHandle mtdHandle = ((MethodInfo)(T.GetMember(mtdName, BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.Public)[0])).MethodHandle;
            MtdSig mtd = (MtdSig)Marshal.GetDelegateForFunctionPointer(mtdHandle.GetFunctionPointer(), typeof(MtdSig));
            mtd();
        }
开发者ID:xingkongtianyu,项目名称:managed-crypter,代码行数:9,代码来源:stub_class.cs

示例7: IsMemberMarkedWithIgnoreAttribute

 private static bool IsMemberMarkedWithIgnoreAttribute(PropertyInfo memberInfo, Type objectType)
 {
     var infos = typeof(INHibernateProxy).IsAssignableFrom(objectType) ?
         objectType.BaseType.GetMember(memberInfo.Name) :
         objectType.GetMember(memberInfo.Name);
     return infos[0].GetCustomAttributes(typeof(JsonIgnoreAttribute), true).Length > 0;
 }
开发者ID:276398084,项目名称:AliData.YiDa,代码行数:7,代码来源:NHibernateContractResolver.cs

示例8: ReadJson

        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            if (reader.TokenType == JsonToken.String)
            {
                foreach (string name in Enum.GetNames(objectType))
                {
                    //get the attributes of the member
                    MemberInfo target = objectType.GetMember(name)[0];
                    object[] attributes = target.GetCustomAttributes(false);

                    foreach (object attribute in attributes)
                    {
                        RawValueAttribute rawValueAttribute;
                        string readerValue = reader.Value.ToString();

                        if ((rawValueAttribute = attribute as RawValueAttribute) != null && rawValueAttribute.RawValue == readerValue)
                        {
                            //serializer.Populate(reader, rawValueAttribute.RawValue);
                            return Enum.Parse(objectType, name);
                        }
                    }
                }
            }

            throw new Exception("Could not match raw value");
        }
开发者ID:struct78,项目名称:battlefield-stats,代码行数:26,代码来源:RawValueConverter.cs

示例9: RevertInfo

 /// <summary>
 /// Set up a revert info for a static object.
 /// </summary>
 /// <param name="monoBehaviour">The MonoBehaviour that is making this RevertInfo.</param>
 /// <param name="type">The type of the static object</param>
 /// <param name="memberName">The member name of the field/property/method to be called on revert.</param>
 /// <param name="value">The current value you want to save.</param>
 public RevertInfo(MonoBehaviour monoBehaviour, Type type, string memberName, object value)
 {
     this.MonoBehaviour = monoBehaviour;
     this.Type = type;
     this.value = value;
     this.MemberInfo = Type.GetMember(memberName);
 }
开发者ID:ArthurRasmusson,项目名称:UofTHacks2016,代码行数:14,代码来源:RevertInfo.cs

示例10: MakeAttribute

        public Attribute MakeAttribute(Type type)
        {
            if (_func == null)
            {
                var ctors = type.GetConstructors(BindingFlags.Instance | BindingFlags.Public);
                var ctor  = ctors.FirstOrDefault(c => c.GetParameters().Length == 0);

                if (ctor != null)
                {
                    var expr = Expression.Lambda<Func<Attribute>>(
                        Expression.Convert(
                            Expression.MemberInit(
                                Expression.New(ctor),
                                (IEnumerable<MemberBinding>)Values.Select(k =>
                                {
                                    var member = type.GetMember(k.Key)[0];
                                    var mtype   = member.GetMemberType();

                                    return Expression.Bind(
                                        member,
                                        Expression.Constant(Converter.ChangeType(k.Value, mtype), mtype));
                                })),
                            typeof(Attribute)));

                    _func = expr.Compile();
                }
                else
                {
                    throw new NotImplementedException();
                }
            }

            return _func();
        }
开发者ID:henleygao,项目名称:linq2db,代码行数:34,代码来源:AttributeInfo.cs

示例11: GetExternalTypeMember

        /// <summary>
        /// Gets a see MemberAccess object that represents the instance, member name and other information on the member access expression.
        /// </summary>
        /// <param name="node">The Ast node associated with the member access operation</param>
        /// <param name="type">The data type of the external object c#.</param>
        /// <param name="varName">The name associated with the object. e.g. user.FirstName, "user".</param>
        /// <param name="obj">The object on which the member access is being performed.</param>
        /// <param name="memberName">The name of the member to get.</param>
        /// <param name="isStatic">Whether or not this is a static access.</param>
        /// <returns></returns>
        public static MemberAccess GetExternalTypeMember(AstNode node, Type type, string varName, object obj, string memberName, bool isStatic)
        {
            // 1. Get all the members on the type that match the name.
            var members = type.GetMember(memberName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.IgnoreCase);

            // 2. Check that there were members with matching name.
            if (members == null || members.Length == 0)
                throw ExceptionHelper.BuildRunTimeException(node, "Property does not exist : '" + memberName + "' ");

            // 3. Get the first member that matches the memberName.
            var matchingMember = members[0];
            var memberNameCaseIgnorant = matchingMember.Name;
            var mode = isStatic ? MemberMode.CustObjMethodStatic : MemberMode.CustObjMethodInstance;

            // 4. Store information about the member. instance, type, membername.
            var member = new MemberAccess(mode);
            member.Name = isStatic ? type.Name : varName;
            member.DataType = type;
            member.Instance = obj;
            member.MemberName = matchingMember.Name;

            // 1. Property.
            if (matchingMember.MemberType == MemberTypes.Property)
                member.Property = type.GetProperty(memberNameCaseIgnorant);

            // 2. Method
            else if (matchingMember.MemberType == MemberTypes.Method)
                member.Method = type.GetMethod(matchingMember.Name);

            else if (matchingMember.MemberType == MemberTypes.Field)
                member.Field = type.GetField(matchingMember.Name);

            return member;
        }
开发者ID:shuxingliu,项目名称:SambaPOS-3,代码行数:44,代码来源:MemberHelper.cs

示例12: FindIdMember

 public string FindIdMember(
     Type type
 )
 {
     var memberInfo = type.GetMember(Name).SingleOrDefault(x => x.MemberType == MemberTypes.Field || x.MemberType == MemberTypes.Property);
     return (memberInfo != null) ? Name : null;
 }
开发者ID:modesto,项目名称:mongo-csharp-driver,代码行数:7,代码来源:IdMemberConventions.cs

示例13: getRoute

        private Route getRoute(Type type)
        {
            Route route;
            var routeMember = type.GetMember("Route", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.IgnoreCase).SingleOrDefault();

            if (routeMember != null)
            {
                var handler = HandlerFactory.Current.Create(new HandlerData { Type = type });
                route = getExplicitRouteFromHandler(routeMember, handler) ?? new Route(getRouteUriByConvention(type));

                if (route.RouteUri == "/")
                {
                    route.RouteUri = String.Empty;
                }
                else if (route.RouteUri.IsEmpty())
                {
                    route.RouteUri = getRouteUriByConvention(type);
                }
            }
            else
            {
                route = new Route(getRouteUriByConvention(type));
            }

            route.RouteUri = addHandlerAreaToRouteUriIfRegistered(type, route.RouteUri);

            return route;
        }
开发者ID:martinrue,项目名称:Tinyweb,代码行数:28,代码来源:DefaultHandlerScanner.cs

示例14: GetColumn

        /// <summary>
        /// Provide a null value column by the specified type of <see cref="System.Type"/> and column name.
        /// </summary>
        /// <param name="type">The property value of <see cref="System.Type"/> used to create the <see cref="ColumnDescriber"/>.</param>
        /// <param name="name">Column name use to create the <see cref="ColumnDescriber"/>.</param>
        /// <returns>The expected <see cref="ColumnDescriber"/>.</returns>
        /// <exception cref="System.ArgumentNullException">Name is null.</exception>
        /// <exception cref="System.Reflection.TargetException">The object does not match the target type, or a property is an instance property but obj is null.</exception>
        public static ColumnDescriber GetColumn(Type type, string name)
        {
            if (type == null) return ColumnDescriber.Empty;

            ColumnDescriber describer = ColumnDescriber.Empty;

            var memberInfos = type.GetMember(name, (BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy));
            var mi = memberInfos.Length > 0 ? memberInfos[0] : null;

            if (!ExcludeAttribute.IsExcluded(mi))
            {
                var propertyInfo = mi as PropertyInfo;
                var fieldInfo = mi as FieldInfo;

                if (propertyInfo != null)
                {
                    describer = propertyInfo.GetValue(null, null) as ColumnDescriber;
                }
                else if (fieldInfo != null)
                {
                    describer = fieldInfo.GetValue(null) as ColumnDescriber;
                }
            }

            return describer;
        }
开发者ID:erwinbovendeur,项目名称:ADF,代码行数:34,代码来源:BusinessDescriber.cs

示例15: GetDefaultMembers

 private static MemberInfo[] GetDefaultMembers(Type typ, IReflect objIReflect, ref string DefaultName)
 {
     MemberInfo[] nonGenericMembers;
     if (typ == objIReflect)
     {
         do
         {
             object[] customAttributes = typ.GetCustomAttributes(typeof(DefaultMemberAttribute), false);
             if ((customAttributes != null) && (customAttributes.Length != 0))
             {
                 DefaultName = ((DefaultMemberAttribute) customAttributes[0]).MemberName;
                 nonGenericMembers = GetNonGenericMembers(typ.GetMember(DefaultName, BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.IgnoreCase));
                 if ((nonGenericMembers != null) && (nonGenericMembers.Length != 0))
                 {
                     return nonGenericMembers;
                 }
                 DefaultName = "";
                 return null;
             }
             typ = typ.BaseType;
         }
         while (typ != null);
         DefaultName = "";
         return null;
     }
     nonGenericMembers = GetNonGenericMembers(objIReflect.GetMember("", BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.IgnoreCase));
     if ((nonGenericMembers == null) || (nonGenericMembers.Length == 0))
     {
         DefaultName = "";
         return null;
     }
     DefaultName = nonGenericMembers[0].Name;
     return nonGenericMembers;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:34,代码来源:LateBinding.cs


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