public TypeDescription(TypeInfo objectType)
            : base(null, objectType)
        {
            if (objectType == null)
            {
                throw new ArgumentNullException("objectType");
            }

            this.objectType     = objectType;
            this.IsDataContract = this.Attributes.Any(attribute => attribute.GetType().Name == DATA_CONTRACT_ATTRIBUTE_NAME);
#if NETSTANDARD
            this.IsSerializable = this.objectType.GetCustomAttributes(typeof(SerializableAttribute), true).Any();
#else
            this.IsSerializable = objectType.IsSerializable;
#endif
            this.IsEnumerable    = this.objectType.IsInstantiationOf(typeof(Enumerable)) && this.objectType != typeof(string);
            this.IsDictionary    = typeof(IDictionary).GetTypeInfo().IsAssignableFrom(this.objectType);
            this.IsAnonymousType = this.objectType.IsSealed && this.objectType.IsNotPublic && this.objectType.GetCustomAttributes(typeof(CompilerGeneratedAttribute), true).Any();

            var allMembers = this.FindMembers(this.objectType);

            this.members       = allMembers.AsReadOnly();
            this.membersByName = allMembers.ToDictionary(m => m.Name, StringComparer.Ordinal);

            MetadataReflection.TryGetConstructor(this.objectType, out this.constructorFn, out this.defaultConstructor);
        }
Exemple #2
0
        public FieldDescription(TypeDescription typeDescription, FieldInfo fieldInfo)
            : base(typeDescription, fieldInfo)
        {
            if (fieldInfo == null)
            {
                throw new ArgumentNullException("fieldInfo");
            }

            this.fieldInfo = fieldInfo;

            MetadataReflection.TryGetMemberAccessFunc(fieldInfo, out this.getFn, out this.setFn);
        }
        public PropertyDescription(TypeDescription typeDescription, PropertyInfo propertyInfo)
            : base(typeDescription, propertyInfo)
        {
            if (propertyInfo == null)
            {
                throw new ArgumentNullException("propertyInfo");
            }

            this.propertyInfo = propertyInfo;

            this.getMethod = propertyInfo.GetGetMethod(nonPublic: true);
            this.setMethod = propertyInfo.GetSetMethod(nonPublic: true);

            MetadataReflection.TryGetMemberAccessFunc(this.getMethod, this.setMethod, out this.getFn, out this.setFn);
        }