internal static void BuildGetterSetterDictionaries(IDictionary <string, SchemaDictionary <T> .AccessDelegates> schemaDictionaryNameToAccessDelegates, IDictionary <string, Func <T, object> > allGetters, IDictionary <string, Action <T, object> > allSetters)
        {
            foreach (PropertyInfo propertyInfo in typeof(T).GetProperties(BindingFlags.Instance | BindingFlags.Public))
            {
                if (!SchemaDictionary <T> .ShouldIgnoreProperty(propertyInfo))
                {
                    Func <T, object> func = SchemaDictionary <T> .MakeGetterDelegate(propertyInfo, true);

                    if (func != null)
                    {
                        allGetters.Add(propertyInfo.Name, func);
                    }
                    Action <T, object> action = SchemaDictionary <T> .MakeSetterDelegate(propertyInfo, true);

                    if (action != null)
                    {
                        allSetters.Add(propertyInfo.Name, action);
                    }
                    string schemaDictionaryName = SchemaDictionary <T> .GetSchemaDictionaryName(propertyInfo);

                    SchemaDictionary <T> .AccessDelegates accessDelegates = null;
                    if (!schemaDictionaryNameToAccessDelegates.TryGetValue(schemaDictionaryName, out accessDelegates))
                    {
                        accessDelegates = new SchemaDictionary <T> .AccessDelegates();

                        schemaDictionaryNameToAccessDelegates.Add(schemaDictionaryName, accessDelegates);
                    }
                    func = SchemaDictionary <T> .MakeGetterDelegate(propertyInfo, false);

                    if (func != null)
                    {
                        accessDelegates._Getters.Add(propertyInfo.Name, func);
                    }
                    if (SchemaDictionary <T> .ShouldSerialize(propertyInfo))
                    {
                        accessDelegates._GettersForSerialization.Add(propertyInfo.Name, func);
                    }
                    action = SchemaDictionary <T> .MakeSetterDelegate(propertyInfo, false);

                    if (action != null)
                    {
                        accessDelegates._Setters.Add(propertyInfo.Name, action);
                    }
                    MethodInfo setMethod = propertyInfo.GetSetMethod(true);
                    if (setMethod != null && (setMethod.IsPrivate || setMethod.IsFamily))
                    {
                        accessDelegates._ForbiddenSetters.Add(propertyInfo.Name);
                    }
                }
            }
            foreach (PropertyInfo propertyInfo2 in typeof(T).GetProperties(BindingFlags.Instance | BindingFlags.NonPublic))
            {
                Func <T, object> func2 = SchemaDictionary <T> .MakeGetterDelegate(propertyInfo2, true);

                if (func2 != null)
                {
                    allGetters.Add(propertyInfo2.Name, func2);
                }
                Action <T, object> action2 = SchemaDictionary <T> .MakeSetterDelegate(propertyInfo2, true);

                if (action2 != null)
                {
                    allSetters.Add(propertyInfo2.Name, action2);
                }
                MethodInfo setMethod2 = propertyInfo2.GetSetMethod(true);
                if (setMethod2 != null)
                {
                    foreach (SchemaDictionary <T> .AccessDelegates accessDelegates2 in schemaDictionaryNameToAccessDelegates.Values)
                    {
                        accessDelegates2._ForbiddenSetters.Add(propertyInfo2.Name);
                    }
                }
            }
        }
Esempio n. 2
0
 private void InitializeRelation(Guid relationTypeId, Guid targetObjectId)
 {
     base.TypeId         = relationTypeId;
     this.targetObjectId = targetObjectId;
     this.Properties     = new SchemaDictionary <Relation>(this, "RelationProperties", null, null, null, null);
 }
 protected void ValidateValue(string key, object value)
 {
     if (value != null && !base.IsSupported(value.GetType()))
     {
         throw new ArgumentException("value is of a unsupported Type. The supported types are the primitive ones plus " + string.Join(", ", from type in SchemaDictionary.GetNonPrimitiveSupportedTypes()
                                                                                                                                      select type.ToString()) + ".", "value");
     }
     if (this._PropertyValueValidator != null)
     {
         this._PropertyValueValidator(key, value);
     }
 }