internal FieldModel(MemberInfo memberInfo, Type fieldType, TypeDesc fieldTypeDesc) {
this.name = memberInfo.Name;
this.fieldType = fieldType;
this.fieldTypeDesc = fieldTypeDesc;
this.checkShouldPersist = memberInfo.DeclaringType.GetMethod("ShouldSerialize" + memberInfo.Name, new Type[0]) != null;
FieldInfo specifiedField = memberInfo.DeclaringType.GetField(memberInfo.Name + "Specified");
if (specifiedField != null) {
if (specifiedField.FieldType != typeof(bool)) {
throw new InvalidOperationException(Res.GetString(Res.XmlInvalidSpecifiedType, specifiedField.Name, specifiedField.FieldType.FullName, typeof(bool).FullName));
}
this.checkSpecified = true;
}
else {
PropertyInfo specifiedProperty = memberInfo.DeclaringType.GetProperty(memberInfo.Name + "Specified");
if (specifiedProperty != null) {
this.checkSpecified = StructModel.CheckPropertyRead(specifiedProperty);
if (this.checkSpecified && specifiedProperty.PropertyType != typeof(bool)) {
throw new InvalidOperationException(Res.GetString(Res.XmlInvalidSpecifiedType, specifiedProperty.Name, specifiedProperty.PropertyType.FullName, typeof(bool).FullName));
}
}
}
if (memberInfo is PropertyInfo) {
readOnly = !((PropertyInfo)memberInfo).CanWrite;
isProperty = true;
}
else if (memberInfo is FieldInfo) {
readOnly = ((FieldInfo)memberInfo).IsInitOnly;
}
}