Beispiel #1
0
        protected ObjectSchema()
        {
            HashSet <PropertyDefinition> hashSet        = new HashSet <PropertyDefinition>();
            List <PropertyDefinition>    list           = new List <PropertyDefinition>();
            List <FieldInfo>             list2          = ReflectionHelper.AggregateTypeHierarchy <FieldInfo>(base.GetType(), new AggregateType <FieldInfo>(ReflectionHelper.AggregateStaticFields));
            IEnumerable <FieldInfo>      declaredFields = base.GetType().GetTypeInfo().DeclaredFields;

            foreach (FieldInfo fieldInfo in list2)
            {
                object value = fieldInfo.GetValue(null);
                if (typeof(ProviderPropertyDefinition).GetTypeInfo().IsAssignableFrom(fieldInfo.FieldType.GetTypeInfo()) && value == null)
                {
                    throw new InvalidOperationException(string.Format("Property definition '{0}' is not initialized. This can be caused by loop dependency between initialization of one or more static fields.", fieldInfo.Name));
                }
                ProviderPropertyDefinition providerPropertyDefinition = value as ProviderPropertyDefinition;
                if (providerPropertyDefinition != null)
                {
                    bool flag = false;
                    foreach (FieldInfo fieldInfo2 in declaredFields)
                    {
                        if (fieldInfo2.Name.Equals(fieldInfo.Name) && !this.IsSameFieldHandle(fieldInfo2, fieldInfo))
                        {
                            flag = true;
                            break;
                        }
                    }
                    if (!this.containsCalculatedProperties && providerPropertyDefinition.IsCalculated)
                    {
                        this.containsCalculatedProperties = true;
                    }
                    if (!flag)
                    {
                        if (!providerPropertyDefinition.IsFilterOnly)
                        {
                            hashSet.TryAdd(providerPropertyDefinition);
                            if (!providerPropertyDefinition.IsCalculated)
                            {
                                continue;
                            }
                            using (ReadOnlyCollection <ProviderPropertyDefinition> .Enumerator enumerator3 = providerPropertyDefinition.SupportingProperties.GetEnumerator())
                            {
                                while (enumerator3.MoveNext())
                                {
                                    ProviderPropertyDefinition item = enumerator3.Current;
                                    hashSet.TryAdd(item);
                                }
                                continue;
                            }
                        }
                        if (!providerPropertyDefinition.IsCalculated)
                        {
                            list.Add(providerPropertyDefinition);
                        }
                    }
                }
            }
            this.AllProperties           = new ReadOnlyCollection <PropertyDefinition>(hashSet.ToArray());
            this.AllFilterOnlyProperties = new ReadOnlyCollection <PropertyDefinition>(list.ToArray());
            this.InitializePropertyCollections();
        }
Beispiel #2
0
        protected internal Schema()
        {
            HashSet <PropertyDefinition>      hashSet      = new HashSet <PropertyDefinition>();
            HashSet <PropertyDefinition>      hashSet2     = new HashSet <PropertyDefinition>();
            HashSet <PropertyDefinition>      hashSet3     = new HashSet <PropertyDefinition>();
            List <StoreObjectConstraint>      list         = new List <StoreObjectConstraint>();
            HashSet <PropertyDefinition>      propertySet  = new HashSet <PropertyDefinition>();
            HashSet <PropertyDefinition>      propertySet2 = new HashSet <PropertyDefinition>();
            HashSet <StorePropertyDefinition> propertySet3 = new HashSet <StorePropertyDefinition>();
            HashSet <StorePropertyDefinition> propertySet4 = new HashSet <StorePropertyDefinition>();

            foreach (FieldInfo fieldInfo in ReflectionHelper.AggregateTypeHierarchy <FieldInfo>(base.GetType(), new AggregateType <FieldInfo>(ReflectionHelper.AggregateStaticFields)))
            {
                object value = fieldInfo.GetValue(null);
                StorePropertyDefinition storePropertyDefinition = value as StorePropertyDefinition;
                if (storePropertyDefinition != null && (storePropertyDefinition.PropertyFlags & PropertyFlags.FilterOnly) == PropertyFlags.None)
                {
                    hashSet2.Add(storePropertyDefinition);
                    if (fieldInfo.IsPublic)
                    {
                        hashSet.Add(storePropertyDefinition);
                        if (storePropertyDefinition is SmartPropertyDefinition)
                        {
                            hashSet3.Add(storePropertyDefinition);
                        }
                    }
                    if (fieldInfo.GetCustomAttribute <DetectCodepageAttribute>() != null)
                    {
                        Schema.AddPropertyAndDependentPropertiesToSet <StorePropertyDefinition>(propertySet3, storePropertyDefinition);
                        Schema.AddPropertyAndDependentPropertiesToSet <PropertyDefinition>(propertySet, storePropertyDefinition);
                        Schema.AddPropertyAndDependentPropertiesToSet <PropertyDefinition>(propertySet2, storePropertyDefinition);
                    }
                    else if (fieldInfo.GetCustomAttribute <AutoloadAttribute>() != null)
                    {
                        Schema.AddPropertyAndDependentPropertiesToSet <PropertyDefinition>(propertySet, storePropertyDefinition);
                        Schema.AddPropertyAndDependentPropertiesToSet <PropertyDefinition>(propertySet2, storePropertyDefinition);
                    }
                    else if (storePropertyDefinition is SmartPropertyDefinition)
                    {
                        SmartPropertyDefinition smartPropertyDefinition = (SmartPropertyDefinition)storePropertyDefinition;
                        Schema.AddSmartPropertyToSet <PropertyDefinition>(propertySet, smartPropertyDefinition.Dependencies, PropertyDependencyType.NeedToReadForWrite);
                        Schema.AddSmartPropertyToSet <PropertyDefinition>(propertySet2, smartPropertyDefinition.Dependencies, PropertyDependencyType.NeedToReadForWrite);
                    }
                    else if (fieldInfo.GetCustomAttribute <OptionalAutoloadAttribute>() != null)
                    {
                        Schema.AddPropertyAndDependentPropertiesToSet <PropertyDefinition>(propertySet, storePropertyDefinition);
                    }
                    if (fieldInfo.GetCustomAttribute <LegalTrackingAttribute>() != null)
                    {
                        Schema.AddPropertyAndDependentLegalTrackingPropertiesToSet <StorePropertyDefinition>(propertySet4, storePropertyDefinition);
                    }
                    foreach (object obj in fieldInfo.GetCustomAttributes(typeof(ConstraintAttribute), false))
                    {
                        ConstraintAttribute constraintAttribute = obj as ConstraintAttribute;
                        if (constraintAttribute != null)
                        {
                            list.Add(constraintAttribute.GetConstraint(storePropertyDefinition));
                        }
                    }
                }
            }
            this.allProperties              = hashSet;
            this.allPropertiesInternal      = hashSet2;
            this.smartProperties            = hashSet3;
            this.autoloadProperties         = propertySet;
            this.requiredAutoloadProperties = propertySet2;
            this.detectCodepageProperties   = propertySet3;
            this.legalTrackingProperties    = propertySet4;
            this.AddConstraints(list);
            this.constraints = list.ToArray();
        }