當前位置: 首頁>>代碼示例>>C#>>正文


C# BindingFlags.HasFlag方法代碼示例

本文整理匯總了C#中BindingFlags.HasFlag方法的典型用法代碼示例。如果您正苦於以下問題:C# BindingFlags.HasFlag方法的具體用法?C# BindingFlags.HasFlag怎麽用?C# BindingFlags.HasFlag使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在BindingFlags的用法示例。


在下文中一共展示了BindingFlags.HasFlag方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: TestAccessibility

        private static bool TestAccessibility(MethodBase member, BindingFlags bindingFlags) {
            bool visibility = (member.IsPublic && bindingFlags.HasFlag(BindingFlags.Public)) ||
                              (!member.IsPublic && bindingFlags.HasFlag(BindingFlags.NonPublic));

            bool instance = (member.IsStatic && bindingFlags.HasFlag(BindingFlags.Static)) ||
                            (!member.IsStatic && bindingFlags.HasFlag(BindingFlags.Instance));

            return visibility && instance;
        }
開發者ID:InlineAsm,項目名稱:Exceptionless.Net,代碼行數:9,代碼來源:TypeExtensions.cs

示例2: AreBindingFlagsMatching

        private static bool AreBindingFlagsMatching(FieldInfo fieldInfo, BindingFlags bindingAttr)
        {
            var publicFlag = bindingAttr.HasFlag(BindingFlags.Public);
            var nonPublicFlag = bindingAttr.HasFlag(BindingFlags.NonPublic);

            var staticFlag = bindingAttr.HasFlag(BindingFlags.Static);
            var instanceFlag = bindingAttr.HasFlag(BindingFlags.Instance);

            return ((fieldInfo.IsPublic && publicFlag) || (!fieldInfo.IsPublic && nonPublicFlag)) &&
                   ((fieldInfo.IsStatic && staticFlag) || (!fieldInfo.IsStatic && instanceFlag));
        }
開發者ID:hungdluit,項目名稱:aforge,代碼行數:11,代碼來源:TypeExtensions.cs

示例3: GetMembers

        public static MemberInfo[] GetMembers(this Type t, BindingFlags flags)
        {
            #if NETFX_CORE
            if (!flags.HasFlag(BindingFlags.Instance) && !flags.HasFlag(BindingFlags.Static)) return null;

            var ti = t.GetTypeInfo();
            var result = new List<MemberInfo>();
            result.AddRange(ti.DeclaredMembers);
            return result.ToArray();
            #else
            throw new NotImplementedException();
            #endif
        }
開發者ID:hmcaio,項目名稱:UnityPorting,代碼行數:13,代碼來源:ReflectionExtensions.cs

示例4: GetProperties

        public static IEnumerable<PropertyInfo> GetProperties(this Type type, BindingFlags bindingFlags) {
            IList<PropertyInfo> properties = (bindingFlags.HasFlag(BindingFlags.DeclaredOnly))
                ? type.GetTypeInfo().DeclaredProperties.ToList()
                : type.GetTypeInfo().GetPropertiesRecursive();

            return properties.Where(p => TestAccessibility(p, bindingFlags));
        }
開發者ID:InlineAsm,項目名稱:Exceptionless.Net,代碼行數:7,代碼來源:TypeExtensions.cs

示例5: GetMethod

        public static MethodInfo GetMethod(this Type This, string name, BindingFlags flags = default(BindingFlags))
        {
            var ti = This.GetTypeInfo();
            var ret = ti.GetDeclaredMethod(name);
            if (ret != null || !flags.HasFlag(BindingFlags.FlattenHierarchy) || ti.BaseType == null) return ret;

            return ti.BaseType.GetMethod(name, flags);
        }
開發者ID:ChrisWay,項目名稱:RxTest,代碼行數:8,代碼來源:ReflectionStubs.cs

示例6: GetMethod

        public static MethodInfo GetMethod(this Type This, string methodName, Type[] paramTypes, BindingFlags flags = default(BindingFlags))
        {
            var ti = This.GetTypeInfo();
            var ret = ti.GetDeclaredMethods(methodName)
                .FirstOrDefault(x => {
                    return paramTypes.Zip(x.GetParameters().Select(y => y.ParameterType), (l, r) => l == r).All(y => y != false);
                });

            if (ret != null || !flags.HasFlag(BindingFlags.FlattenHierarchy) || ti.BaseType == null) return ret;
            return ti.BaseType.GetMethod(methodName, paramTypes, flags);
        }
開發者ID:hjlfmy,項目名稱:ReactiveUI,代碼行數:11,代碼來源:ReflectionStubs.cs

示例7: InvokeInternal

        protected virtual object InvokeInternal(string name, BindingFlags invokeAttr, Binder binder, object target, object[] args, System.Globalization.CultureInfo culture)
        {
            if (invokeAttr.HasFlag(BindingFlags.GetProperty))
            {
                var prop = GetProperty(name, invokeAttr);
                if (prop == null)
                {
                    throw new MissingFieldException("ScriptDrivenObject", name);
                }

                return prop.GetValue(target, null);

            }
            else if (invokeAttr.HasFlag(BindingFlags.SetProperty))
            {
                var prop = GetProperty(name, invokeAttr);
                if (prop == null)
                {
                    throw new MissingFieldException("ScriptDrivenObject", name);
                }

                prop.SetValue(target, args[0], invokeAttr, binder, null, culture);

                return null;
            }
            else if (invokeAttr.HasFlag(BindingFlags.InvokeMethod))
            {
                var method = GetMethod(name, invokeAttr);
                if (method == null)
                {
                    throw new MissingMethodException("ScriptDrivenObject", name);
                }

                return method.Invoke(target, invokeAttr, binder, args, culture);
            }
            else
            {
                throw new ArgumentException("No flags for property access or method call");
            }
        }
開發者ID:Shemetov,項目名稱:OneScript,代碼行數:40,代碼來源:ReflectableSDO.cs

示例8: InnerInvokeMember

        protected override object InnerInvokeMember(string name, BindingFlags invokeAttr, Binder binder, object target,
			object[] args, ParameterModifier[] modifiers, CultureInfo culture, string[] namedParameters)
        {
            object[] processedArgs = TypeMappingHelpers.MapToHostType(args);
            object result;

            if (name == SpecialMemberName.Default && invokeAttr.HasFlag(BindingFlags.CreateInstance))
            {
                if (_engineMode != JsEngineMode.Classic && processedArgs.Length > 0)
                {
                    processedArgs = processedArgs.Skip(1).ToArray();
                }

                result = Activator.CreateInstance(_type, processedArgs);
            }
            else
            {
                result = InvokeStandardMember(name, invokeAttr, binder, target,
                    processedArgs, modifiers, culture, namedParameters);
            }

            return TypeMappingHelpers.MapToScriptType(result, _engineMode);
        }
開發者ID:Taritsyn,項目名稱:MsieJavaScriptEngine,代碼行數:23,代碼來源:HostType.cs

示例9: GetFields

        public static FieldInfo[] GetFields(this Type t, BindingFlags flags)
        {
            #if NETFX_CORE
            if (!flags.HasFlag(BindingFlags.Instance) && !flags.HasFlag(BindingFlags.Static)) return null;

            var ti = t.GetTypeInfo();
            var origFields = ti.DeclaredFields;
            var results = new List<FieldInfo>();
            foreach (var field in origFields)
            {
                var isValid = (flags.HasFlag(BindingFlags.Public) && field.IsPublic)
                    || (flags.HasFlag(BindingFlags.NonPublic) && !field.IsPublic);
                isValid &= (flags.HasFlag(BindingFlags.Static) && field.IsStatic) || (flags.HasFlag(BindingFlags.Instance) && !field.IsStatic);
                if (flags.HasFlag(BindingFlags.DeclaredOnly))
                    isValid &= field.DeclaringType == t;

                results.Add(field);
            }
            return results.ToArray();
            #else
            throw new NotImplementedException();
            #endif
        }
開發者ID:hmcaio,項目名稱:UnityPorting,代碼行數:23,代碼來源:ReflectionExtensions.cs

示例10: GetConstructors

            public override ConstructorInfo[] GetConstructors(BindingFlags bindingAttr)
            {
                // Do not expose non-public constructors for composition, since 
                // this is the behavior of all other frameworks (including Microsoft.Composition!)
                if (bindingAttr.HasFlag(BindingFlags.NonPublic))
                    bindingAttr &= ~BindingFlags.NonPublic;

                var ctor = base.GetConstructors(bindingAttr).OrderByDescending(c => c.GetParameters().Length).FirstOrDefault();
                if (ctor != null)
                    return new ConstructorInfo[] { new ImportingConstructorInfo(ctor) };

                return new ConstructorInfo[0];
            }
開發者ID:MobileEssentials,項目名稱:clide,代碼行數:13,代碼來源:ComponentCatalog.cs

示例11: TryInvokeObject

        public static bool TryInvokeObject(object target, BindingFlags invokeFlags, object[] args, object[] bindArgs, bool tryDynamic, out object result)
        {
            var hostTarget = target as HostTarget;
            if (hostTarget != null)
            {
                if (hostTarget.TryInvoke(invokeFlags, args, bindArgs, out result))
                {
                    return true;
                }

                if (hostTarget is HostType)
                {
                    return false;
                }

                target = hostTarget.InvokeTarget;
                tryDynamic = tryDynamic && typeof(IDynamicMetaObjectProvider).IsAssignableFrom(hostTarget.Type);
            }

            if ((target != null) && invokeFlags.HasFlag(BindingFlags.InvokeMethod))
            {
                if (target is ScriptItem)
                {
                    target = DelegateFactory.CreateFunc<object>(null, target, args.Length);
                }

                var del = target as Delegate;
                if (del != null)
                {
                    result = InvokeDelegate(del, args);
                    return true;
                }

                if (tryDynamic)
                {
                    var dynamicMetaObjectProvider = target as IDynamicMetaObjectProvider;
                    if (dynamicMetaObjectProvider != null)
                    {
                        if (dynamicMetaObjectProvider.GetMetaObject(Expression.Constant(target)).TryInvoke(args, out result))
                        {
                            return true;
                        }
                    }
                }
            }

            result = null;
            return false;
        }
開發者ID:sergueik,項目名稱:swd-recorder-appium,代碼行數:49,代碼來源:InvokeHelpers.cs

示例12: IsConformWithBindingFlags

        private static bool IsConformWithBindingFlags(FieldInfo method, BindingFlags bindingFlags)
        {
            if (method.IsPublic && !bindingFlags.HasFlag(BindingFlags.Public))
                return false;
            if (method.IsPrivate && !bindingFlags.HasFlag(BindingFlags.NonPublic))
                return false;
            if (method.IsStatic && !bindingFlags.HasFlag(BindingFlags.Static))
                return false;
            if (!method.IsStatic && !bindingFlags.HasFlag(BindingFlags.Instance))
                return false;

            return true;
        }
開發者ID:alecor191,項目名稱:RefactoringEssentials,代碼行數:13,代碼來源:ReflectionCompatibilityExtensions.cs

示例13: GetProperties

        public static PropertyInfo[] GetProperties(this Type type, BindingFlags flags)
        {
            var props = type.GetRuntimeProperties ();

            return props.Where (p =>
              ((flags.HasFlag (BindingFlags.Static) == (p.GetMethod != null && p.GetMethod.IsStatic)) ||
                (flags.HasFlag (BindingFlags.Instance) == (p.GetMethod != null && !p.GetMethod.IsStatic))
              ) &&
              (flags.HasFlag (BindingFlags.Public) == (p.GetMethod != null && p.GetMethod.IsPublic)
              )).ToArray ();
        }
開發者ID:GSharpDevs,項目名稱:RunG,代碼行數:11,代碼來源:GeneralExtensions.cs

示例14: TryInvokeAuxMember

        public override bool TryInvokeAuxMember(string memberName, BindingFlags invokeFlags, object[] args, object[] bindArgs, out object result)
        {
            if (invokeFlags.HasFlag(BindingFlags.InvokeMethod))
            {
                if (memberName == "get")
                {
                    result = target.InvokeMember(name, BindingFlags.GetProperty, args, bindArgs, null);
                    return true;
                }

                if (memberName == "set")
                {
                    result = target.InvokeMember(name, BindingFlags.SetProperty, args, bindArgs, null);
                    return true;
                }
            }

            result = null;
            return false;
        }
開發者ID:julianhaslinger,項目名稱:swd-recorder,代碼行數:20,代碼來源:HostIndexedProperty.cs

示例15: GetFields

        public static IEnumerable<FieldInfo> GetFields(this Type type, BindingFlags bindingFlags)
        {
            IList<FieldInfo> fields = (bindingFlags.HasFlag(BindingFlags.DeclaredOnly))
                ? type.GetTypeInfo().DeclaredFields.ToList()
                : type.GetTypeInfo().GetFieldsRecursive();

            return fields.Where(f => TestAccessibility(f, bindingFlags)).ToList();
        }
開發者ID:cilliemalan,項目名稱:Cargo,代碼行數:8,代碼來源:TypeExtensions.cs


注:本文中的BindingFlags.HasFlag方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。