Inheritance: PropertyInfo, ISerializable
Esempio n. 1
0
        private static PropertyInfo?GetBasePropertyDefinition(RuntimePropertyInfo property)
        {
            MethodInfo?method = property.GetGetMethod(true);

            if (method == null || !method.IsVirtual)
            {
                method = property.GetSetMethod(true);
            }
            if (method == null || !method.IsVirtual)
            {
                return(null);
            }

            MethodInfo baseMethod = ((RuntimeMethodInfo)method).GetBaseMethod();

            if (baseMethod != null && baseMethod != method)
            {
                ParameterInfo[] parameters = property.GetIndexParameters();
                if (parameters != null && parameters.Length > 0)
                {
                    Type[] paramTypes = new Type[parameters.Length];
                    for (int i = 0; i < paramTypes.Length; i++)
                    {
                        paramTypes[i] = parameters[i].ParameterType;
                    }
                    return(baseMethod.DeclaringType !.GetProperty(property.Name, property.PropertyType,
                                                                  paramTypes));
                }
                else
                {
                    return(baseMethod.DeclaringType !.GetProperty(property.Name, property.PropertyType));
                }
            }
            return(null);
        }
Esempio n. 2
0
        internal bool EqualsSig(RuntimePropertyInfo target)
        {
            //@Asymmetry - Legacy policy is to remove duplicate properties, including hidden properties.
            //             The comparison is done by name and by sig. The EqualsSig comparison is expensive
            //             but forutnetly it is only called when an inherited property is hidden by name or
            //             when an interfaces declare properies with the same signature.
            //             Note that we intentionally don't resolve generic arguments so that we don't treat
            //             signatures that only match in certain instantiations as duplicates. This has the
            //             down side of treating overriding and overriden properties as different properties
            //             in some cases. But PopulateProperties in rttype.cs should have taken care of that
            //             by comparing VTable slots.
            //
            //             Class C1(Of T, Y)
            //                 Property Prop1(ByVal t1 As T) As Integer
            //                     Get
            //                         ... ...
            //                     End Get
            //                 End Property
            //                 Property Prop1(ByVal y1 As Y) As Integer
            //                     Get
            //                         ... ...
            //                     End Get
            //                 End Property
            //             End Class
            //

            Contract.Requires(Name.Equals(target.Name));
            Contract.Requires(this != target);
            Contract.Requires(this.ReflectedType == target.ReflectedType);

            return(Signature.CompareSig(this.Signature, target.Signature));
        }
Esempio n. 3
0
 internal static bool IsDefined(RuntimePropertyInfo property, RuntimeType caType)
 {
     if (PseudoCustomAttribute.IsDefined(property, caType))
     {
         return(true);
     }
     return(CustomAttribute.IsCustomAttributeDefined(property.GetRuntimeModule(), property.MetadataToken, caType));
 }
        internal Object GetObject()
        {
            int      propNum  = 0;
            Assembly assembly = null;
            Object   ca       = CreateCAObject(ref propNum, ref assembly);

            if (propNum > 0)
            {
                Type caType = ca.GetType();
                do
                {
                    // deal with named properties
                    bool   isProperty      = false;
                    Object value           = null;
                    Type   type            = null;
                    string propOrFieldName = GetDataForPropertyOrField(ref isProperty, out value, out type, propNum == 1);
                    if (isProperty)
                    {
                        try {
                            // a type only comes back when a enum or an object is specified in all other cases the value
                            // already holds the info of what type that is
                            if (type == null && value != null)
                            {
                                type = (value is System.Type) ? s_TypeType : value.GetType();
                            }
                            RuntimePropertyInfo p = null;
                            if (type == null)
                            {
                                p = caType.GetProperty(propOrFieldName) as RuntimePropertyInfo;
                            }
                            else
                            {
                                p = caType.GetProperty(propOrFieldName, type) as RuntimePropertyInfo;
                            }
                            p.SetValueInternal(ca, value, assembly);
                        }
                        catch (Exception e) {
                            throw new CustomAttributeFormatException(String.Format(Environment.GetResourceString("RFLCT.InvalidPropFail"),
                                                                                   propOrFieldName),
                                                                     e);
                        }
                    }
                    else
                    {
                        try {
                            FieldInfo f = caType.GetField(propOrFieldName);
                            f.SetValue(ca, value);
                        }
                        catch (Exception e) {
                            throw new CustomAttributeFormatException(String.Format(Environment.GetResourceString("RFLCT.InvalidFieldFail"),
                                                                                   propOrFieldName),
                                                                     e);
                        }
                    }
                } while (--propNum > 0);
            }
            return(ca);
        }
Esempio n. 5
0
        internal override bool CacheEquals(object o)
        {
            RuntimePropertyInfo info = o as RuntimePropertyInfo;

            if (info == null)
            {
                return(false);
            }
            return((info.m_token == this.m_token) && this.m_declaringType.GetTypeHandleInternal().GetModuleHandle().Equals(info.m_declaringType.GetTypeHandleInternal().GetModuleHandle()));
        }
Esempio n. 6
0
        internal override bool CacheEquals(object o)
        {
            RuntimePropertyInfo runtimePropertyInfo = o as RuntimePropertyInfo;

            if (runtimePropertyInfo == null || runtimePropertyInfo.m_token != this.m_token)
            {
                return(false);
            }
            return(RuntimeTypeHandle.GetModule(this.m_declaringType).Equals((object)RuntimeTypeHandle.GetModule(runtimePropertyInfo.m_declaringType)));
        }
        public void HasPublicSetter_ReturnsTrueIfSetterExistsAndIsPublic(string propertyName)
        {
            // Arrange
            var property = GetPropertyInfo(propertyName);
            var runtimePropertyInfo = new RuntimePropertyInfo(property);

            // Act
            var result = runtimePropertyInfo.HasPublicSetter;

            // Assert
            Assert.True(result);
        }
Esempio n. 8
0
        internal static object[] GetCustomAttributes(RuntimePropertyInfo property, RuntimeType caType)
        {
            int count = 0;

            Attribute[] sourceArray      = PseudoCustomAttribute.GetCustomAttributes(property, caType, out count);
            object[]    destinationArray = GetCustomAttributes(property.Module, property.MetadataToken, count, caType);
            if (count > 0)
            {
                Array.Copy(sourceArray, 0, destinationArray, destinationArray.Length - count, count);
            }
            return(destinationArray);
        }
        public void HasPublicGetter_ReturnsFalseIfGetterDoesNotExistOrIsNonPublic(string propertyName)
        {
            // Arrange
            var property = GetPropertyInfo(propertyName);
            var runtimePropertyInfo = new RuntimePropertyInfo(property);

            // Act
            var result = runtimePropertyInfo.HasPublicGetter;

            // Assert
            Assert.False(result);
        }
Esempio n. 10
0
        internal override bool CacheEquals(object o)
        {
            RuntimePropertyInfo m = o as RuntimePropertyInfo;

            if ((object)m == null)
            {
                return(false);
            }

            return(m.m_token == m_token &&
                   RuntimeTypeHandle.GetModule(m_declaringType).Equals(
                       RuntimeTypeHandle.GetModule(m.m_declaringType)));
        }
Esempio n. 11
0
        public void PropertyInfo_ReturnsMetadataOfAdaptingProperty()
        {
            // Arrange
            var property = GetPropertyInfo(nameof(TestType.Property));
            var runtimePropertyInfo = new RuntimePropertyInfo(property);

            // Act
            var actual = runtimePropertyInfo.Property;

            // Assert
            Assert.Same(property, actual);
            var runtimeTypeInfo = Assert.IsType<RuntimeTypeInfo>(runtimePropertyInfo.PropertyType);
            Assert.Same(property.PropertyType, runtimeTypeInfo.TypeInfo);
        }
        internal static object[] GetCustomAttributes(RuntimePropertyInfo property, RuntimeType caType)
        {
            int count = 0;

            Attribute[] sourceArray = PseudoCustomAttribute.GetCustomAttributes(property, caType, out count);
            bool        isDecoratedTargetSecurityTransparent = property.GetRuntimeModule().GetRuntimeAssembly().IsAllSecurityTransparent();

            object[] destinationArray = GetCustomAttributes(property.GetRuntimeModule(), property.MetadataToken, count, caType, isDecoratedTargetSecurityTransparent);
            if (count > 0)
            {
                Array.Copy(sourceArray, 0, destinationArray, destinationArray.Length - count, count);
            }
            return(destinationArray);
        }
Esempio n. 13
0
        internal static object[] GetCustomAttributes(RuntimePropertyInfo property, RuntimeType caType)
        {
            int count = 0;

            Attribute[] customAttributes1 = PseudoCustomAttribute.GetCustomAttributes(property, caType, out count);
            bool        isDecoratedTargetSecurityTransparent = property.GetRuntimeModule().GetRuntimeAssembly().IsAllSecurityTransparent();

            object[] customAttributes2 = CustomAttribute.GetCustomAttributes(property.GetRuntimeModule(), property.MetadataToken, count, caType, isDecoratedTargetSecurityTransparent);
            if (count > 0)
            {
                Array.Copy((Array)customAttributes1, 0, (Array)customAttributes2, customAttributes2.Length - count, count);
            }
            return(customAttributes2);
        }
Esempio n. 14
0
        // BEGIN helper methods for Dev11 466969 quirk
        internal bool HasMatchingAccessibility(RuntimePropertyInfo target)
        {
            Contract.Assert(CompatibilitySwitches.IsAppEarlierThanWindowsPhone8);
            bool match = true;

            if (!IsMatchingAccessibility(this.GetGetMethod(true), target.GetGetMethod(true)))
            {
                match = false;
            }
            else if (!IsMatchingAccessibility(this.GetSetMethod(true), target.GetSetMethod(true)))
            {
                match = false;
            }

            return(match);
        }
        // Token: 0x0600471F RID: 18207 RVA: 0x00102024 File Offset: 0x00100224
        internal RuntimeModule GetRuntimeModule()
        {
            RuntimeMethodInfo      runtimeMethodInfo      = this.Member as RuntimeMethodInfo;
            RuntimeConstructorInfo runtimeConstructorInfo = this.Member as RuntimeConstructorInfo;
            RuntimePropertyInfo    runtimePropertyInfo    = this.Member as RuntimePropertyInfo;

            if (runtimeMethodInfo != null)
            {
                return(runtimeMethodInfo.GetRuntimeModule());
            }
            if (runtimeConstructorInfo != null)
            {
                return(runtimeConstructorInfo.GetRuntimeModule());
            }
            if (runtimePropertyInfo != null)
            {
                return(runtimePropertyInfo.GetRuntimeModule());
            }
            return(null);
        }
Esempio n. 16
0
        internal RuntimeModule GetRuntimeModule()
        {
            RuntimeMethodInfo      member = this.Member as RuntimeMethodInfo;
            RuntimeConstructorInfo info2  = this.Member as RuntimeConstructorInfo;
            RuntimePropertyInfo    info3  = this.Member as RuntimePropertyInfo;

            if (member != null)
            {
                return(member.GetRuntimeModule());
            }
            if (info2 != null)
            {
                return(info2.GetRuntimeModule());
            }
            if (info3 != null)
            {
                return(info3.GetRuntimeModule());
            }
            return(null);
        }
Esempio n. 17
0
        internal RuntimeModule GetRuntimeModule()
        {
            RuntimeMethodInfo      method      = Member as RuntimeMethodInfo;
            RuntimeConstructorInfo constructor = Member as RuntimeConstructorInfo;
            RuntimePropertyInfo    property    = Member as RuntimePropertyInfo;

            if (method != null)
            {
                return(method.GetRuntimeModule());
            }
            else if (constructor != null)
            {
                return(constructor.GetRuntimeModule());
            }
            else if (property != null)
            {
                return(property.GetRuntimeModule());
            }
            else
            {
                return(null);
            }
        }
 internal RemotingCachedData(RuntimePropertyInfo ri)
 {
     this.RI = ri;
 }
Esempio n. 19
0
 internal static bool IsDefined(RuntimePropertyInfo property, RuntimeType caType)
 {
     return (PseudoCustomAttribute.IsDefined(property, caType) || IsCustomAttributeDefined(property.Module, property.MetadataToken, caType));
 }
Esempio n. 20
0
 internal static object[] GetCustomAttributes(RuntimePropertyInfo property, RuntimeType caType)
 {
     int count = 0;
     Attribute[] sourceArray = PseudoCustomAttribute.GetCustomAttributes(property, caType, out count);
     object[] destinationArray = GetCustomAttributes(property.Module, property.MetadataToken, count, caType);
     if (count > 0)
     {
         Array.Copy(sourceArray, 0, destinationArray, destinationArray.Length - count, count);
     }
     return destinationArray;
 }
Esempio n. 21
0
        public void GetAttributes_ReturnsCustomAttributesOfSpecifiedType()
        {
            // Arrange
            var property = GetPropertyInfo(nameof(TestType.PropertyWithAttributes));
            var runtimeProperty = new RuntimePropertyInfo(property);

            // Act
            var attributes = property.GetCustomAttributes<HtmlAttributeNameAttribute>();

            // Assert
            var htmlAttributeName = Assert.Single(attributes);
            Assert.Equal("somename", htmlAttributeName.Name);
        }
Esempio n. 22
0
 internal bool EqualsSig(RuntimePropertyInfo target)
 {
     return(Signature.CompareSig(this.Signature, target.Signature));
 }
Esempio n. 23
0
 internal static IList <CustomAttributeData> GetCustomAttributesInternal(RuntimePropertyInfo target)
 {
     return(CustomAttributeData.GetCustomAttributes(target.GetRuntimeModule(), target.MetadataToken));
 }
Esempio n. 24
0
        internal bool EqualsSig(RuntimePropertyInfo target)
        {
            //@Asymmetry - Legacy policy is to remove duplicate properties, including hidden properties. 
            //             The comparison is done by name and by sig. The EqualsSig comparison is expensive 
            //             but forutnetly it is only called when an inherited property is hidden by name or
            //             when an interfaces declare properies with the same signature. 
            //             Note that we intentionally don't resolve generic arguments so that we don't treat
            //             signatures that only match in certain instantiations as duplicates. This has the
            //             down side of treating overriding and overriden properties as different properties
            //             in some cases. But PopulateProperties in rttype.cs should have taken care of that
            //             by comparing VTable slots.
            //
            //             Class C1(Of T, Y)
            //                 Property Prop1(ByVal t1 As T) As Integer
            //                     Get
            //                         ... ...
            //                     End Get
            //                 End Property
            //                 Property Prop1(ByVal y1 As Y) As Integer
            //                     Get
            //                         ... ...
            //                     End Get
            //                 End Property
            //             End Class
            //

            Contract.Requires(Name.Equals(target.Name));
            Contract.Requires(this != target);
            Contract.Requires(this.ReflectedType == target.ReflectedType);


#if FEATURE_LEGACYNETCF
            if (CompatibilitySwitches.IsAppEarlierThanWindowsPhone8)
                return Signature.CompareSigForAppCompat(this.Signature, this.m_declaringType,
                                                        target.Signature, target.m_declaringType);
#endif
            return Signature.CompareSig(this.Signature, target.Signature);
        }
Esempio n. 25
0
 // Token: 0x06004490 RID: 17552 RVA: 0x000FC7EE File Offset: 0x000FA9EE
 internal static bool IsDefined(RuntimePropertyInfo property, RuntimeType caType)
 {
     return(false);
 }
Esempio n. 26
0
 internal static bool IsDefined(RuntimePropertyInfo property, RuntimeType caType)
 {
     return false;
 }
Esempio n. 27
0
        [System.Security.SecuritySafeCritical]  // auto-generated
        internal static Object[] GetCustomAttributes(RuntimePropertyInfo property, RuntimeType caType)
        {
            Contract.Requires(property != null);
            Contract.Requires(caType != null);

            int pcaCount = 0;
            Attribute[] pca = PseudoCustomAttribute.GetCustomAttributes(property, caType, out pcaCount);
            // Since properties and events have no transparency state, logically we should check the declaring types.
            // But then if someone wanted to apply critical attributes on a property/event he would need to make the type critical,
            // which would also implicitly made all the members critical.
            // So we check the containing assembly instead. If the assembly can contain critical code we allow critical attributes on properties/events.
            bool disallowCriticalCustomAttributes = property.GetRuntimeModule().GetRuntimeAssembly().IsAllSecurityTransparent();

            object[] attributes = GetCustomAttributes(property.GetRuntimeModule(), property.MetadataToken, pcaCount, caType, disallowCriticalCustomAttributes);
            if (pcaCount > 0) Array.Copy(pca, 0, attributes, attributes.Length - pcaCount, pcaCount);
            return attributes;
        }
 // Token: 0x06004714 RID: 18196 RVA: 0x00101BBB File Offset: 0x000FFDBB
 internal RuntimeParameterInfo(RuntimeParameterInfo accessor, RuntimePropertyInfo property) : this(accessor, property)
 {
     this.m_signature = property.Signature;
 }
 internal static Object[] GetCustomAttributes(RuntimePropertyInfo property, RuntimeType caType)
 {
     int pcaCount = 0;
     Attribute[] pca = PseudoCustomAttribute.GetCustomAttributes(property, caType, out pcaCount);
     object[] attributes = GetCustomAttributes(property.Module, property.MetadataToken, pcaCount, caType);
     if (pcaCount > 0) Array.Copy(pca, 0, attributes, attributes.Length - pcaCount, pcaCount);
     return attributes;
 }
        internal static bool IsDefined(RuntimePropertyInfo property, RuntimeType caType)
        {
            ASSERT.PRECONDITION(property != null);

            if (PseudoCustomAttribute.IsDefined(property, caType))
                return true;

            return IsCustomAttributeDefined(property.Module, property.MetadataToken, caType);
        }
Esempio n. 31
0
 private void LoadPropertyInfo()
 {
     if (_properties != null)
     {
         return;
     }
     LoadMethodInfo();
     _properties = new RuntimePropertyInfo[_class.Properties.Length];
     for (int i = 0; i < _class.Properties.Length; i++)
     {
         Property property = _class.Properties[i];
         RuntimeMethodInfo getMethodInfo;
         if (property.GetMethod != null)
         {
             getMethodInfo = _methodToRuntimeMethodInfoMap[property.GetMethod];
         }
         else
         {
             getMethodInfo = null;
         }
         RuntimeMethodInfo setMethodInfo;
         if (property.SetMethod != null)
         {
             setMethodInfo = _methodToRuntimeMethodInfoMap[property.SetMethod];
         }
         else
         {
             setMethodInfo = null;
         }
         _properties[i] = new RuntimePropertyInfo(property, this, getMethodInfo, setMethodInfo);
     }
 }
Esempio n. 32
0
 internal bool EqualsSig(RuntimePropertyInfo target)
 {
     return(System.Signature.DiffSigs(this.Signature, this.DeclaringType.GetTypeHandleInternal(), target.Signature, target.DeclaringType.GetTypeHandleInternal()));
 }
Esempio n. 33
0
 // Token: 0x0600448F RID: 17551 RVA: 0x000FC7E8 File Offset: 0x000FA9E8
 internal static Attribute[] GetCustomAttributes(RuntimePropertyInfo property, RuntimeType caType, out int count)
 {
     count = 0;
     return(null);
 }
Esempio n. 34
0
        // BEGIN helper methods for Dev11 466969 quirk
        internal bool HasMatchingAccessibility(RuntimePropertyInfo target)
        {
            Contract.Assert(CompatibilitySwitches.IsAppEarlierThanWindowsPhone8);
            bool match = true;
            
            if (!IsMatchingAccessibility(this.GetGetMethod(true), target.GetGetMethod(true)))
            {
                match = false;
            }
            else if (!IsMatchingAccessibility(this.GetSetMethod(true), target.GetSetMethod(true)))
            {
                match = false;
            }

            return match;
        }
Esempio n. 35
0
		RuntimePropertyInfo[] GetPropertiesByName (string name, BindingFlags bindingAttr, bool icase, RuntimeType reflectedType)
		{
			var refh = new RuntimeTypeHandle (reflectedType);
			using (var h = new Mono.SafeGPtrArrayHandle (GetPropertiesByName_native (name, bindingAttr, icase))) {
				var n = h.Length;
				var a = new RuntimePropertyInfo [n];
				for (int i = 0; i < n; i++) {
					var ph = new Mono.RuntimePropertyHandle (h[i]);
					a[i] = (RuntimePropertyInfo) PropertyInfo.GetPropertyFromHandle (ph, refh);
				}
				return a;
			}
		}
        private static unsafe object[] GetCustomAttributes(RuntimeModule decoratedModule, int decoratedMetadataToken, int pcaCount, RuntimeType attributeFilterType, bool mustBeInheritable, IList derivedAttributes, bool isDecoratedTargetSecurityTransparent)
        {
            if (decoratedModule.Assembly.ReflectionOnly)
            {
                throw new InvalidOperationException(Environment.GetResourceString("Arg_ReflectionOnlyCA"));
            }
            MetadataImport metadataImport = decoratedModule.MetadataImport;

            CustomAttributeRecord[] customAttributeRecords = CustomAttributeData.GetCustomAttributeRecords(decoratedModule, decoratedMetadataToken);
            Type elementType = (((attributeFilterType == null) || attributeFilterType.IsValueType) || attributeFilterType.ContainsGenericParameters) ? typeof(object) : attributeFilterType;

            if ((attributeFilterType == null) && (customAttributeRecords.Length == 0))
            {
                return(CreateAttributeArrayHelper(elementType, 0));
            }
            object[]             attributes = CreateAttributeArrayHelper(elementType, customAttributeRecords.Length);
            int                  length     = 0;
            SecurityContextFrame frame      = new SecurityContextFrame();

            frame.Push(decoratedModule.GetRuntimeAssembly());
            Assembly lastAptcaOkAssembly = null;

            for (int i = 0; i < customAttributeRecords.Length; i++)
            {
                bool   flag2;
                bool   flag3;
                object obj2 = null;
                CustomAttributeRecord caRecord      = customAttributeRecords[i];
                IRuntimeMethodInfo    ctor          = null;
                RuntimeType           attributeType = null;
                int    namedArgs = 0;
                IntPtr signature = caRecord.blob.Signature;
                IntPtr blobEnd   = (IntPtr)(((void *)signature) + caRecord.blob.Length);
                int    num4      = (int)((long)((((void *)blobEnd) - ((void *)signature)) / 1));
                if (FilterCustomAttributeRecord(caRecord, metadataImport, ref lastAptcaOkAssembly, decoratedModule, decoratedMetadataToken, attributeFilterType, mustBeInheritable, attributes, derivedAttributes, out attributeType, out ctor, out flag2, out flag3))
                {
                    if (ctor != null)
                    {
                        RuntimeMethodHandle.CheckLinktimeDemands(ctor, decoratedModule, isDecoratedTargetSecurityTransparent);
                    }
                    RuntimeConstructorInfo.CheckCanCreateInstance(attributeType, flag3);
                    if (flag2)
                    {
                        obj2 = CreateCaObject(decoratedModule, ctor, ref signature, blobEnd, out namedArgs);
                    }
                    else
                    {
                        obj2 = RuntimeTypeHandle.CreateCaInstance(attributeType, ctor);
                        if (num4 == 0)
                        {
                            namedArgs = 0;
                        }
                        else
                        {
                            if (Marshal.ReadInt16(signature) != 1)
                            {
                                throw new CustomAttributeFormatException();
                            }
                            signature = (IntPtr)(((void *)signature) + 2);
                            namedArgs = Marshal.ReadInt16(signature);
                            signature = (IntPtr)(((void *)signature) + 2);
                        }
                    }
                    for (int j = 0; j < namedArgs; j++)
                    {
                        string      str;
                        bool        flag4;
                        RuntimeType type;
                        object      obj3;
                        IntPtr      ptr1 = caRecord.blob.Signature;
                        GetPropertyOrFieldData(decoratedModule, ref signature, blobEnd, out str, out flag4, out type, out obj3);
                        try
                        {
                            if (flag4)
                            {
                                if ((type == null) && (obj3 != null))
                                {
                                    type = (RuntimeType)obj3.GetType();
                                    if (type == Type_RuntimeType)
                                    {
                                        type = Type_Type;
                                    }
                                }
                                RuntimePropertyInfo property = null;
                                if (type == null)
                                {
                                    property = attributeType.GetProperty(str) as RuntimePropertyInfo;
                                }
                                else
                                {
                                    property = attributeType.GetProperty(str, type, Type.EmptyTypes) as RuntimePropertyInfo;
                                }
                                if (property == null)
                                {
                                    throw new CustomAttributeFormatException(string.Format(CultureInfo.CurrentUICulture, Environment.GetResourceString(flag4 ? "RFLCT.InvalidPropFail" : "RFLCT.InvalidFieldFail"), new object[] { str }));
                                }
                                RuntimeMethodInfo setMethod = property.GetSetMethod(true) as RuntimeMethodInfo;
                                if (setMethod.IsPublic)
                                {
                                    RuntimeMethodHandle.CheckLinktimeDemands(setMethod, decoratedModule, isDecoratedTargetSecurityTransparent);
                                    setMethod.Invoke(obj2, BindingFlags.Default, null, new object[] { obj3 }, null, true);
                                }
                            }
                            else
                            {
                                RtFieldInfo field = attributeType.GetField(str) as RtFieldInfo;
                                if (isDecoratedTargetSecurityTransparent)
                                {
                                    RuntimeFieldHandle.CheckAttributeAccess(field.FieldHandle, decoratedModule.GetNativeHandle());
                                }
                                field.InternalSetValue(obj2, obj3, BindingFlags.Default, Type.DefaultBinder, null, false);
                            }
                        }
                        catch (Exception exception)
                        {
                            throw new CustomAttributeFormatException(string.Format(CultureInfo.CurrentUICulture, Environment.GetResourceString(flag4 ? "RFLCT.InvalidPropFail" : "RFLCT.InvalidFieldFail"), new object[] { str }), exception);
                        }
                    }
                    if (!signature.Equals(blobEnd))
                    {
                        throw new CustomAttributeFormatException();
                    }
                    attributes[length++] = obj2;
                }
            }
            frame.Pop();
            if ((length == customAttributeRecords.Length) && (pcaCount == 0))
            {
                return(attributes);
            }
            object[] destinationArray = CreateAttributeArrayHelper(elementType, length + pcaCount);
            Array.Copy(attributes, 0, destinationArray, 0, length);
            return(destinationArray);
        }
Esempio n. 37
0
 internal bool EqualsSig(RuntimePropertyInfo target)
 {
     return System.Signature.DiffSigs(this.Signature, this.DeclaringType.GetTypeHandleInternal(), target.Signature, target.DeclaringType.GetTypeHandleInternal());
 }
Esempio n. 38
0
        [System.Security.SecurityCritical]  // auto-generated
        internal static bool IsDefined(RuntimePropertyInfo property, RuntimeType caType)
        {
            Contract.Requires(property != null);
            Contract.Requires(caType != null);

            if (PseudoCustomAttribute.IsDefined(property, caType))
                return true;

            return IsCustomAttributeDefined(property.GetRuntimeModule(), property.MetadataToken, caType);
        }
Esempio n. 39
0
        public void GetAttributes_DoesNotInheritAttributes()
        {
            // Arrange
            var property = GetPropertyInfo(nameof(TestType.PropertyWithAttributes));
            var runtimeProperty = new RuntimePropertyInfo(property);

            // Act
            var attributes = property.GetCustomAttributes<HtmlAttributeNotBoundAttribute>();

            // Assert
            Assert.Empty(attributes);
        }
Esempio n. 40
0
 internal static Attribute[] GetCustomAttributes(RuntimePropertyInfo property, RuntimeType caType, out int count)
 {
     count = 0;
     return null;
 }
 internal bool EqualsSig(RuntimePropertyInfo target)
 {
     return(System.Signature.DiffSigs(this.Signature, target.Signature));
 }
 internal static IList<CustomAttributeData> GetCustomAttributesInternal(RuntimePropertyInfo target)
 {
     return GetCustomAttributes(target.GetRuntimeModule(), target.MetadataToken);
 }
Esempio n. 43
0
        private static unsafe object[] GetCustomAttributes(RuntimeModule decoratedModule, int decoratedMetadataToken, int pcaCount, RuntimeType attributeFilterType, bool mustBeInheritable, IList derivedAttributes, bool isDecoratedTargetSecurityTransparent)
        {
            if (decoratedModule.Assembly.ReflectionOnly)
            {
                throw new InvalidOperationException(Environment.GetResourceString("Arg_ReflectionOnlyCA"));
            }
            MetadataImport metadataImport = decoratedModule.MetadataImport;

            CustomAttributeRecord[] attributeRecords = CustomAttributeData.GetCustomAttributeRecords(decoratedModule, decoratedMetadataToken);
            Type elementType = (attributeFilterType == (RuntimeType)null || attributeFilterType.IsValueType ? 1 : (attributeFilterType.ContainsGenericParameters ? 1 : 0)) != 0 ? typeof(object) : (Type)attributeFilterType;

            if (attributeFilterType == (RuntimeType)null && attributeRecords.Length == 0)
            {
                return(CustomAttribute.CreateAttributeArrayHelper(elementType, 0));
            }
            object[]             attributeArrayHelper1 = CustomAttribute.CreateAttributeArrayHelper(elementType, attributeRecords.Length);
            int                  length = 0;
            SecurityContextFrame securityContextFrame = new SecurityContextFrame();

            securityContextFrame.Push(decoratedModule.GetRuntimeAssembly());
            Assembly lastAptcaOkAssembly = (Assembly)null;

            for (int index1 = 0; index1 < attributeRecords.Length; ++index1)
            {
                CustomAttributeRecord caRecord      = attributeRecords[index1];
                IRuntimeMethodInfo    ctor          = (IRuntimeMethodInfo)null;
                RuntimeType           attributeType = (RuntimeType)null;
                int    namedArgs = 0;
                IntPtr ptr1      = caRecord.blob.Signature;
                IntPtr blobEnd   = (IntPtr)((void *)((IntPtr)(void *)ptr1 + caRecord.blob.Length));
                int    num       = (int)((sbyte *)(void *)blobEnd - (sbyte *)(void *)ptr1);
                bool   ctorHasParameters;
                bool   isVarArg;
                if (CustomAttribute.FilterCustomAttributeRecord(caRecord, metadataImport, ref lastAptcaOkAssembly, decoratedModule, (MetadataToken)decoratedMetadataToken, attributeFilterType, mustBeInheritable, attributeArrayHelper1, derivedAttributes, out attributeType, out ctor, out ctorHasParameters, out isVarArg))
                {
                    if (ctor != null)
                    {
                        RuntimeMethodHandle.CheckLinktimeDemands(ctor, decoratedModule, isDecoratedTargetSecurityTransparent);
                    }
                    RuntimeConstructorInfo.CheckCanCreateInstance((Type)attributeType, isVarArg);
                    object target;
                    if (ctorHasParameters)
                    {
                        target = CustomAttribute.CreateCaObject(decoratedModule, ctor, ref ptr1, blobEnd, out namedArgs);
                    }
                    else
                    {
                        target = RuntimeTypeHandle.CreateCaInstance(attributeType, ctor);
                        if (num == 0)
                        {
                            namedArgs = 0;
                        }
                        else
                        {
                            if ((int)Marshal.ReadInt16(ptr1) != 1)
                            {
                                throw new CustomAttributeFormatException();
                            }
                            IntPtr ptr2 = (IntPtr)((void *)((IntPtr)(void *)ptr1 + 2));
                            namedArgs = (int)Marshal.ReadInt16(ptr2);
                            ptr1      = (IntPtr)((void *)((IntPtr)(void *)ptr2 + 2));
                        }
                    }
                    for (int index2 = 0; index2 < namedArgs; ++index2)
                    {
                        IntPtr      signature = caRecord.blob.Signature;
                        string      name;
                        bool        isProperty;
                        RuntimeType type;
                        object      obj;
                        CustomAttribute.GetPropertyOrFieldData(decoratedModule, ref ptr1, blobEnd, out name, out isProperty, out type, out obj);
                        try
                        {
                            if (isProperty)
                            {
                                if (type == (RuntimeType)null && obj != null)
                                {
                                    type = (RuntimeType)obj.GetType();
                                    if (type == CustomAttribute.Type_RuntimeType)
                                    {
                                        type = CustomAttribute.Type_Type;
                                    }
                                }
                                RuntimePropertyInfo runtimePropertyInfo = !(type == (RuntimeType)null) ? attributeType.GetProperty(name, (Type)type, Type.EmptyTypes) as RuntimePropertyInfo : attributeType.GetProperty(name) as RuntimePropertyInfo;
                                if ((PropertyInfo)runtimePropertyInfo == (PropertyInfo)null)
                                {
                                    throw new CustomAttributeFormatException(string.Format((IFormatProvider)CultureInfo.CurrentUICulture, Environment.GetResourceString(isProperty ? "RFLCT.InvalidPropFail" : "RFLCT.InvalidFieldFail"), (object)name));
                                }
                                RuntimeMethodInfo runtimeMethodInfo = runtimePropertyInfo.GetSetMethod(true) as RuntimeMethodInfo;
                                if (runtimeMethodInfo.IsPublic)
                                {
                                    RuntimeMethodHandle.CheckLinktimeDemands((IRuntimeMethodInfo)runtimeMethodInfo, decoratedModule, isDecoratedTargetSecurityTransparent);
                                    runtimeMethodInfo.UnsafeInvoke(target, BindingFlags.Default, (Binder)null, new object[1] {
                                        obj
                                    }, (CultureInfo)null);
                                }
                            }
                            else
                            {
                                RtFieldInfo rtFieldInfo = attributeType.GetField(name) as RtFieldInfo;
                                if (isDecoratedTargetSecurityTransparent)
                                {
                                    RuntimeFieldHandle.CheckAttributeAccess(rtFieldInfo.FieldHandle, decoratedModule.GetNativeHandle());
                                }
                                rtFieldInfo.CheckConsistency(target);
                                rtFieldInfo.UnsafeSetValue(target, obj, BindingFlags.Default, Type.DefaultBinder, (CultureInfo)null);
                            }
                        }
                        catch (Exception ex)
                        {
                            throw new CustomAttributeFormatException(string.Format((IFormatProvider)CultureInfo.CurrentUICulture, Environment.GetResourceString(isProperty ? "RFLCT.InvalidPropFail" : "RFLCT.InvalidFieldFail"), (object)name), ex);
                        }
                    }
                    if (!ptr1.Equals((object)blobEnd))
                    {
                        throw new CustomAttributeFormatException();
                    }
                    attributeArrayHelper1[length++] = target;
                }
            }
            securityContextFrame.Pop();
            if (length == attributeRecords.Length && pcaCount == 0)
            {
                return(attributeArrayHelper1);
            }
            object[] attributeArrayHelper2 = CustomAttribute.CreateAttributeArrayHelper(elementType, length + pcaCount);
            Array.Copy((Array)attributeArrayHelper1, 0, (Array)attributeArrayHelper2, 0, length);
            return(attributeArrayHelper2);
        }
Esempio n. 44
0
 // used by RuntimePropertyInfo
 internal RuntimeParameterInfo(RuntimeParameterInfo accessor, RuntimePropertyInfo property)
     : this(accessor, (MemberInfo)property)
 {
     m_signature = property.Signature;
 }
Esempio n. 45
0
 internal ParameterInfo(ParameterInfo accessor, RuntimePropertyInfo property) : this(accessor, (MemberInfo)property)
 {
     this.m_signature = property.Signature;
 }
Esempio n. 46
0
        internal bool EqualsSig(RuntimePropertyInfo target)
        {
            //@Asymmetry - Legacy policy is to remove duplicate properties, including hidden properties. 
            //             The comparison is done by name and by sig. The EqualsSig comparison is expensive 
            //             but forutnetly it is only called when an inherited property is hidden by name or
            //             when an interfaces declare properies with the same signature. 

            ASSERT.PRECONDITION(Name.Equals(target.Name));
            ASSERT.PRECONDITION(this != target);
            ASSERT.PRECONDITION(this.ReflectedType == target.ReflectedType);

            return Signature.DiffSigs(target.Signature);
        }
Esempio n. 47
0
 internal static extern Type[] GetTypeModifiers(RuntimePropertyInfo prop, bool optional);
Esempio n. 48
0
 internal static extern int get_metadata_token(RuntimePropertyInfo monoProperty);
        internal override bool CacheEquals(object o)
        {
            RuntimePropertyInfo runtimePropertyInfo = o as RuntimePropertyInfo;

            return(runtimePropertyInfo != null && runtimePropertyInfo.m_token == this.m_token && RuntimeTypeHandle.GetModule(this.m_declaringType).Equals(RuntimeTypeHandle.GetModule(runtimePropertyInfo.m_declaringType)));
        }
 internal bool EqualsSig(RuntimePropertyInfo target)
 {
     return System.Signature.DiffSigs(this.Signature, target.Signature);
 }
Esempio n. 51
0
 internal static bool IsDefined(RuntimePropertyInfo property, RuntimeType caType)
 {
     return(PseudoCustomAttribute.IsDefined(property, caType) || IsCustomAttributeDefined(property.Module, property.MetadataToken, caType));
 }
Esempio n. 52
0
 internal static extern void get_property_info(RuntimePropertyInfo prop, ref MonoPropertyInfo info,
                                               PInfo req_info);
        [System.Security.SecurityCritical]  // auto-generated
        internal static bool IsDefined(RuntimePropertyInfo property, RuntimeType caType)
        {
            Contract.Requires(property != null);
            Contract.Requires(caType != null);

#if !FEATURE_CORECLR
            if (FrameworkEventSource.IsInitialized && FrameworkEventSource.Log.IsEnabled(EventLevel.Informational, FrameworkEventSource.Keywords.DynamicTypeUsage) && caType != null)
            {
                FrameworkEventSource.Log.QueryAttributeIsDefined(caType.GetFullNameForEtw());
            }
#endif

            if (PseudoCustomAttribute.IsDefined(property, caType))
                return true;

            return IsCustomAttributeDefined(property.GetRuntimeModule(), property.MetadataToken, caType);
        }
Esempio n. 54
0
 internal static extern object get_default_value(RuntimePropertyInfo prop);
 internal static object[] GetCustomAttributes(RuntimePropertyInfo property, RuntimeType caType)
 {
     int count = 0;
     Attribute[] sourceArray = PseudoCustomAttribute.GetCustomAttributes(property, caType, out count);
     bool isDecoratedTargetSecurityTransparent = property.GetRuntimeModule().GetRuntimeAssembly().IsAllSecurityTransparent();
     object[] destinationArray = GetCustomAttributes(property.GetRuntimeModule(), property.MetadataToken, count, caType, isDecoratedTargetSecurityTransparent);
     if (count > 0)
     {
         Array.Copy(sourceArray, 0, destinationArray, destinationArray.Length - count, count);
     }
     return destinationArray;
 }