/// <summary>
        /// Creates instance of property.
        /// </summary>
        public Property(PropertyInfo propertyInfo)
        {
            // Create instances.
            Relations = new Dictionary <string, string>();

            // Assign properties.
            PropertyInfo           = propertyInfo;
            PropertyName           = propertyInfo.Name;
            PropertyNameWithMonkey = "@" + PropertyName;
            DeclaringType          = propertyInfo.DeclaringType;
            PropertyType           = propertyInfo.PropertyType;

            // Assign flags.
            Type entityType = typeof(Entity);

            IsEntityChild = DeclaringType.GetTypeInfo().BaseType == entityType;
            IsForeignKey  = PropertyType.GetTypeInfo().BaseType == entityType;

            // If property belongs to entity and is it plain field.
            if (!IsForeignKey)
            {
                CacheGet();
                CacheSet();
            }
        }
Beispiel #2
0
        private static bool IsAccessible(TypeInfo queryTypeInfo)
        {
            // One of Public, NotPublic, NestedAssembly
            TypeAttributes?result = null;

            for (TypeInfo?typeInfo = queryTypeInfo; result == null && typeInfo != null; typeInfo = typeInfo !.DeclaringType?.GetTypeInfo())
            {
                var attributes = typeInfo.Attributes & TypeAttributes.VisibilityMask;
                switch (attributes)
                {
                case TypeAttributes.NestedPublic:
                    break;

                case TypeAttributes.Public:
                    result = TypeAttributes.Public;
                    break;

                case TypeAttributes.NestedPrivate:
                case TypeAttributes.NestedFamily:
                case TypeAttributes.NestedFamANDAssem:
                    result = TypeAttributes.NotPublic;
                    break;

                case TypeAttributes.NestedAssembly:
                case TypeAttributes.NestedFamORAssem:
                default:     // Internal
                    result = TypeAttributes.NestedAssembly;
                    break;
                }
            }

            if (result == null)
            {
                // Not sure how we got here. Try and generate an implementation for it, which may fail (in which case we'll
                // produce another error message)
                Debug.Assert(false);
                result = TypeAttributes.Public;
            }
            else if (result == TypeAttributes.NestedAssembly)
            {
                if (queryTypeInfo.Assembly.GetCustomAttributes <InternalsVisibleToAttribute>().Any(x => x.AssemblyName == RestClient.FactoryAssemblyName))
                {
                    result = TypeAttributes.Public;
                }
            }

            return(result == TypeAttributes.Public);
        }