Пример #1
0
        /// <summary>
        /// For an indexed property, the type of the property. Null if not indexed.
        /// </summary>
        /// <returns></returns>
        public MrType GetItemType(bool publicishOnly)
        {
            // This could be a getter or a setter method
            MrMethod etterMethod;

            var getterHandle = Definition.GetAccessors().Getter;

            etterMethod = MrMethod.TryGetMethod(getterHandle, this.DeclaringType, publicishOnly);
            if (etterMethod == null)
            {
                var setterHandle = Definition.GetAccessors().Getter;
                etterMethod = MrMethod.TryGetMethod(setterHandle, this.DeclaringType, publicishOnly);
                if (etterMethod == null)
                {
                    // Not an indexed property
                    return(null);
                }
            }

            var parameters = etterMethod.GetParameters();

            if (parameters.Length == 0)
            {
                // Not an indexed property
                return(null);
            }

            return(parameters[0].GetParameterType());
        }
Пример #2
0
        public void GetAccessors(out MrMethod adder, out MrMethod remover, bool publicishOnly = true)
        {
            var eventAccessors = Definition.GetAccessors();

            adder   = MrMethod.TryGetMethod(eventAccessors.Adder, DeclaringType, publicishOnly);
            remover = MrMethod.TryGetMethod(eventAccessors.Remover, DeclaringType, publicishOnly);
        }
Пример #3
0
        public MrParameter(MrMethod method, ParameterHandle parameterHandle, int parameterIndex)
        {
            _parameterHandle = parameterHandle;
            Method           = method;
            _parameterIndex  = parameterIndex;

            _parameter = Method.DeclaringType.Assembly.Reader.GetParameter(_parameterHandle);
        }
        /// <summary>
        /// The methods and constructors for this type. This is one method rather than two to be more efficient
        /// (fewer allocations).
        /// </summary>
        /// <param name="publicishOnly">If true, only return public or protected methods (for an unsealed type)</param>
        public void GetMethodsAndConstructors(
            out ImmutableArray <MrMethod> methods,
            out ImmutableArray <MrMethod> constructors,
            bool publicishOnly = true)
        {
            if (IsFakeType || IsTypeCode)
            {
                methods = constructors = ImmutableArray <MrMethod> .Empty;
                return;
            }

            var             methodDefinitionHandles = TypeDefinition.GetMethods();
            List <MrMethod> mrMethods      = null;
            List <MrMethod> mrConstructors = null;

            foreach (var methodDefinitionHandle in methodDefinitionHandles)
            {
                var methodDefinition = Assembly.Reader.GetMethodDefinition(methodDefinitionHandle);

                var mrMethod = MrMethod.TryGetMethod(methodDefinitionHandle, this, publicishOnly);
                if (mrMethod == null)
                {
                    continue;
                }

                var isConstructor = mrMethod.GetIsConstructor();

                // Ignore things like the get_/set_ methods for properties.
                // Don't ignore constructors though; SpecialName is set for the static constructor
                if (mrMethod.MethodDefinition.Attributes.HasFlag(MethodAttributes.SpecialName) && !isConstructor)
                {
                    continue;
                }

                if (isConstructor)
                {
                    if (mrConstructors == null)
                    {
                        mrConstructors = new List <MrMethod>(methodDefinitionHandles.Count);
                    }
                    mrConstructors.Add(mrMethod);
                }
                else
                {
                    if (mrMethods == null)
                    {
                        mrMethods = new List <MrMethod>(methodDefinitionHandles.Count);
                    }
                    mrMethods.Add(mrMethod);
                }
            }

            methods      = mrMethods == null ? ImmutableArray <MrMethod> .Empty : mrMethods.ToImmutableArray();
            constructors = mrConstructors == null ? ImmutableArray <MrMethod> .Empty : mrConstructors.ToImmutableArray();
        }
Пример #5
0
        internal static bool AreAttributesPublicish(MethodAttributes attributes, MrType declaringType)
        {
            if (MrMethod.IsPublicMethodAttributes(attributes) ||
                MrMethod.IsProtectedMethodAttributes(attributes) &&
                !declaringType.IsSealed)
            {
                return(true);
            }

            return(false);
        }
Пример #6
0
        /// <summary>
        /// The property's getter and setter, either of which could be null
        /// </summary>
        static void GetGetterAndSetter(
            PropertyDefinition propertyDefinition,
            MrType declaringType,
            bool publicishOnly,
            out MrMethod getter, out MrMethod setter)
        {
            var propertyAccessors = propertyDefinition.GetAccessors();

            getter = MrMethod.TryGetMethod(propertyAccessors.Getter, declaringType, publicishOnly);
            setter = MrMethod.TryGetMethod(propertyAccessors.Setter, declaringType, publicishOnly);
        }
Пример #7
0
 private static MrMethod TryGetEtter(
     MrType declaringType,
     MethodDefinitionHandle methodDefinitionHandle,
     bool publicishOnly)
 {
     if (!methodDefinitionHandle.IsNil)
     {
         var methodDefinition = declaringType.Assembly.Reader.GetMethodDefinition(methodDefinitionHandle);
         var attributes       = methodDefinition.Attributes;
         if (!publicishOnly || MrMethod.AreAttributesPublicish(attributes, declaringType))
         {
             return(new MrMethod(methodDefinitionHandle, declaringType, methodDefinition));
         }
     }
     return(null);
 }
Пример #8
0
        public ParsedMethodAttributes GetParsedMethodAttributes()
        {
            var attributes = this.MethodDefinition.Attributes;

            var modifiers = new ParsedMethodAttributes();

            modifiers.IsPublic    = MrMethod.IsPublicMethodAttributes(attributes);
            modifiers.IsPrivate   = MrMethod.IsPrivateMethodAttributes(attributes);
            modifiers.IsInternal  = MrMethod.IsInternalMethodAttributes(attributes);
            modifiers.IsProtected = MrMethod.IsProtectedMethodAttributes(attributes);
            modifiers.IsVirtual   = MrMethod.IsVirtualMethodAttributes(attributes);
            modifiers.IsOverride  = MrMethod.IsOverrideMethodAttributes(attributes);
            modifiers.IsSealed    = MrMethod.IsSealedMethodAttributes(attributes);
            modifiers.IsStatic    = MrMethod.IsStaticMethodAttributes(attributes);
            modifiers.IsAbstract  = MrMethod.IsAbstractMethodAttributes(attributes);

            return(modifiers);
        }
Пример #9
0
        static internal MrEvent TryGetEvent(
            EventDefinitionHandle eventDefinitionHandle,
            MrType declaringType,
            bool publicishOnly)
        {
            var eventDefinition = declaringType.Assembly.Reader.GetEventDefinition(eventDefinitionHandle);

            if (publicishOnly)
            {
                var eventAccessors  = eventDefinition.GetAccessors();
                var adderDefinition = declaringType.Assembly.Reader.GetMethodDefinition(eventAccessors.Adder);
                if (!MrMethod.AreAttributesPublicish(adderDefinition.Attributes, declaringType))
                {
                    return(null);
                }
            }

            return(new MrEvent(eventDefinitionHandle, eventDefinition, declaringType));
        }
Пример #10
0
        /// <summary>
        /// Get a method named "Invoke". This is intended to be called on delegate types.
        /// </summary>
        /// <returns></returns>
        public MrMethod GetInvokeMethod()
        {
            if (IsFakeType)
            {
                return(null);
            }

            // Don't use this.GetMethods, because it filters out SpecialType methods like Delegate.Invoke
            foreach (var methodDefinitionHandle in this.TypeDefinition.GetMethods())
            {
                var methodDefinition = this.Assembly.Reader.GetMethodDefinition(methodDefinitionHandle);
                var name             = methodDefinition.Name.AsString(this.Assembly);
                if (name == "Invoke")
                {
                    return(MrMethod.TryGetMethod(methodDefinitionHandle, this, publicishOnly: false));
                }
            }

            return(null);
        }