Пример #1
0
        public static bool CheckBindings(this MemberInfo member, BindingFlags flags, bool inParent)
        {
            if ((member.IsStatic() & (flags & BindingFlags.Static) == BindingFlags.Static) ||
                (!(member.IsStatic()) & (flags & BindingFlags.Instance) == BindingFlags.Instance))
            {
                // if we're static and we're in parent, and we haven't specified flatten hierarchy, we can't match...
                if (inParent && (int)(flags & BindingFlags.FlattenHierarchy) == 0 && member.IsStatic())
                {
                    return(false);
                }

                if ((member.IsPublic() & (flags & BindingFlags.Public) == BindingFlags.Public) ||
                    (!(member.IsPublic()) & (flags & BindingFlags.NonPublic) == BindingFlags.NonPublic))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Пример #2
0
 /// <summary>
 /// Finds the introduced field.
 /// </summary>
 /// <param name="advice">The advice.</param>
 /// <param name="adviceMemberInfo">The advice member information.</param>
 /// <param name="advisedType">Type of the advised.</param>
 /// <returns></returns>
 /// <exception cref="System.InvalidOperationException">Internal error, can not find matching introduced field</exception>
 internal static FieldInfo FindIntroducedField(IAdvice advice, MemberInfo adviceMemberInfo, Type advisedType)
 {
     var introducedFieldType = GetIntroducedType(adviceMemberInfo);
     var adviceType = advice.GetType();
     var introducedFieldName = IntroductionRules.GetName(adviceType.Namespace, adviceType.Name, adviceMemberInfo.Name);
     var linkID = string.Format("{0}:{1}", adviceType.AssemblyQualifiedName, adviceMemberInfo.Name);
     const BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static;
     var introducedField = FindIntroducedFieldByName(advisedType, introducedFieldName, linkID, bindingFlags)
              ?? FindIntroducedFieldByTypeAndAvailability(advisedType, introducedFieldType, adviceMemberInfo.IsStatic(), null, bindingFlags)
              ?? FindIntroducedFieldByTypeAndAvailability(advisedType, introducedFieldType, adviceMemberInfo.IsStatic(), linkID, bindingFlags);
     if (introducedField == null)
         throw new InvalidOperationException("Internal error, can not find matching introduced field");
     var introducedFieldAttribute = introducedField.GetCustomAttribute<IntroducedFieldAttribute>();
     introducedFieldAttribute.LinkID = linkID;
     return introducedField;
 }
Пример #3
0
 /// <summary>
 /// Creates the invocation context.
 /// </summary>
 /// <returns>The invokation context or null, if can't be handled by Dynamitey.</returns>
 /// <param name="device">Target device.</param>
 /// <param name="info">Field, property or method info.</param>
 private static InvokeContext CreateInvocationContext(object device, MemberInfo info)
 {
     if(info.IsStatic())
     {
         if(info is FieldInfo || info is PropertyInfo)
         {
             //FieldInfo not supported in Dynamitey
             return null;
         }
         return InvokeContext.CreateStatic(device.GetType());
     }
     var propertyInfo = info as PropertyInfo;
     if(propertyInfo != null)
     {
         //private properties not supported in Dynamitey
         if((propertyInfo.CanRead && propertyInfo.GetGetMethod(true).IsPrivate)
            || (propertyInfo.CanWrite && propertyInfo.GetSetMethod(true).IsPrivate))
         {
             return null;
         }
     }
     return InvokeContext.CreateContext(device, info.ReflectedType);
 }
Пример #4
0
 /// <summary>
 /// Determines whether the given <paramref name="member"/> is an instance member.
 /// </summary>
 /// <returns>True for instance fields, properties and methods and false for static fields,
 /// properties and methods. Throws an exception for all other <see href="MemberTypes" />.</returns>
 public static bool IsInstance(this MemberInfo member)
 {
     return(!member.IsStatic());
 }