コード例 #1
0
ファイル: ModelBaseFacts.cs プロジェクト: lixingx86/Catel
            public void CorrectlyRegistersProperties()
            {
                var catelTypeInfo = new CatelTypeInfo(typeof(JohnDoe));

                Assert.IsNotNull(catelTypeInfo.GetPropertyData("FirstName"));
                Assert.IsNotNull(catelTypeInfo.GetPropertyData("LastName"));
            }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SerializationModelInfo"/> class.
        /// </summary>
        /// <param name="modelType">Type of the model.</param>
        /// <param name="catelProperties">The catel properties.</param>
        /// <param name="fields">The fields.</param>
        /// <param name="regularProperties">The properties.</param>
        public SerializationModelInfo(Type modelType, Dictionary <string, MemberMetadata> catelProperties, Dictionary <string, MemberMetadata> fields,
                                      Dictionary <string, MemberMetadata> regularProperties)
        {
            Argument.IsNotNull("modelType", modelType);
            Argument.IsNotNull("catelProperties", catelProperties);
            Argument.IsNotNull("fields", fields);
            Argument.IsNotNull("properties", regularProperties);

            ModelType = modelType;

            CatelTypeInfo catelTypeInfo = null;

            CatelPropertyNames    = new HashSet <string>(catelProperties.Keys);
            CatelProperties       = new List <PropertyData>();
            CatelPropertiesByName = catelProperties;
            foreach (var catelProperty in catelProperties)
            {
                var propertyData = catelProperty.Value.Tag as PropertyData;
                if (propertyData == null)
                {
                    if (catelTypeInfo == null)
                    {
                        catelTypeInfo = PropertyDataManager.Default.GetCatelTypeInfo(modelType);
                    }

                    propertyData = catelTypeInfo.GetPropertyData(catelProperty.Key);
                }

                CatelProperties.Add(propertyData);
            }

            FieldNames   = new HashSet <string>(fields.Keys);
            Fields       = new List <FieldInfo>();
            FieldsByName = fields;
            foreach (var field in fields)
            {
                var fieldInfo = field.Value.Tag as FieldInfo;
                if (fieldInfo == null)
                {
                    fieldInfo = modelType.GetFieldEx(field.Key);
                }

                Fields.Add(fieldInfo);
            }

            PropertyNames    = new HashSet <string>(regularProperties.Keys);
            Properties       = new List <PropertyInfo>();
            PropertiesByName = regularProperties;
            foreach (var regularProperty in regularProperties)
            {
                var propertyInfo = regularProperty.Value.Tag as PropertyInfo;
                if (propertyInfo == null)
                {
                    propertyInfo = modelType.GetPropertyEx(regularProperty.Key);
                }

                Properties.Add(propertyInfo);
            }
        }
コード例 #3
0
ファイル: CatelTypeInfoFacts.cs プロジェクト: xaecors/Catel
        public void CorrectlyRegistersNonCatelProperties()
        {
            var catelTypeInfo = new CatelTypeInfo(typeof(CatelTypeInfoTestModel));

            var properties = catelTypeInfo.GetNonCatelProperties();

            Assert.AreNotEqual(0, properties.Count);
            Assert.IsTrue(properties.Keys.Contains("NormalProperty"));
        }