/// <summary> /// Deletes <see cref="ModelBase"/> object given by <see cref="XmlElement"/> /// from a corresponding collection of the workspace. /// </summary> /// <param name="modelData"><see cref="ModelBase"/> object given by <see cref="XmlElement"/></param> public void DeleteModel(XmlElement modelData) { //When there is a Redo operation, model is removed from //the workspace but the model is "not disposed" from memory. //Identified this when redo operation is performed on groups ModelBase model = GetModelForElement(modelData); if (model is NoteModel) { var note = model as NoteModel; RemoveNote(note); note.Dispose(); } else if (model is AnnotationModel) { RemoveGroup(model); } else if (model is PresetModel) { this.RemovePreset(model as PresetModel); } else if (model is ConnectorModel) { var connector = model as ConnectorModel; connector.Delete(); } else if (model is NodeModel) { RemoveAndDisposeNode(model as NodeModel); } else if (model == null) { return; } //some unknown type else { // If it gets here we obviously need to handle it. throw new InvalidOperationException(string.Format( "Unhandled type: {0}", model.GetType())); } }
public void SetModel(ModelBase model) { _models.Value.Add(model.GetType().Name, model); var weekmh = new WeakReference <ModelsHolder>(this); model.PropertyChanged += (sender, args) => { ModelsHolder mh; weekmh.TryGetTarget(out mh); //mh?.OnPropertyChanged(args.PropertyName); var property = ModelProperties[args.PropertyName]; property.SetValue(this, model.ModelProperties[args.PropertyName].GetValue(model)); }; model.PropertyChanging += (sender, args) => { ModelsHolder mh; weekmh.TryGetTarget(out mh); mh?.OnPropertyChanging(args.PropertyName); }; }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="o"></param> /// <param name="values"></param> public static void AssignProperties <T>(this ModelBase <T> o, object values) { var type = values.GetType(); if (o.GetType() != type) { throw new ArgumentException($"Types of {nameof(o)} and {nameof(values)} are not identical."); } var props = type.GetProperties(); foreach (var prop in props) { var value = prop.GetValue(o); if (value != null) { prop.SetValue(o, value); } } }
/// <summary> /// Initializes a new instance of the <see cref="XmlSerializationContextInfo" /> class. /// </summary> /// <param name="xmlReader">The XML reader.</param> /// <param name="model">The model.</param> /// <exception cref="ArgumentNullException">The <paramref name="xmlReader" /> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException">The <paramref name="model" /> is <c>null</c>.</exception> public XmlSerializationContextInfo(XmlReader xmlReader, ModelBase model) { Argument.IsNotNull("xmlReader", xmlReader); Argument.IsNotNull("model", model); var modelType = model.GetType(); var elementStart = string.Format("<{0}", modelType.Name); if (xmlReader.HasAttributes) { for (int i = 0; i < xmlReader.AttributeCount; i++) { xmlReader.MoveToAttribute(i); var attributeName = xmlReader.LocalName; var attributeValue = xmlReader.Value; elementStart += string.Format(" {0}=\"{1}\"", attributeName, attributeValue); } xmlReader.MoveToElement(); } elementStart += ">"; xmlReader.MoveToContent(); var xmlContent = xmlReader.ReadInnerXml(); if (xmlContent.StartsWith("<")) { xmlContent = System.Net.WebUtility.HtmlDecode(xmlContent); } var elementEnd = string.Format("</{0}>", modelType.Name); var finalXmlContent = string.Format("{0}{1}{2}", elementStart, xmlContent, elementEnd); Initialize(finalXmlContent, model); }
public override bool Equals(ModelBase otherModel) { if (otherModel.GetType() != typeof(ManufacturerModel)) { return(false); } ManufacturerModel otherManufacturer = otherModel as ManufacturerModel; if (otherManufacturer.ID != this.ID) { return(false); } else if (otherManufacturer.Name != this.Name) { return(false); } else { return(true); } }
/// <summary> /// Deserializes the specified model. /// </summary> /// <remarks> /// When deserializing a stream, the binary serializer must use the <see cref="BinaryFormatter"/> because this will /// inject the right <see cref="SerializationInfo"/> into a new serializer. /// </remarks> /// <param name="model">The model.</param> /// <param name="stream">The stream.</param> public override void Deserialize(ModelBase model, Stream stream) { Argument.IsNotNull("model", model); using (var context = (SerializationContext <BinarySerializationContextInfo>)GetContext(model, stream, SerializationContextMode.Deserialization)) { var referenceManager = context.ReferenceManager; if (referenceManager.Count == 0) { Log.Debug("Reference manager contains no objects yet, adding initial reference which is the first model in the graph"); referenceManager.GetInfo(context.Model); } var binaryFormatter = CreateBinaryFormatter(SerializationContextMode.Deserialization); var propertyValues = (List <PropertyValue>)binaryFormatter.Deserialize(stream); var memberValues = ConvertPropertyValuesToMemberValues(context, model.GetType(), propertyValues); context.Context.MemberValues.AddRange(memberValues); Deserialize(model, context.Context); } }
private void listView1_SelectedIndexChanged(object sender, EventArgs e) { if (listItems.SelectedItems.Count == 0) { this.Cursor = Cursors.WaitCursor; this.viewPanel.Controls.Clear(); this.Cursor = Cursors.Default; return; } this.Cursor = Cursors.WaitCursor; ListViewItem lvi = listItems.SelectedItems[0]; ModelBase model = (ModelBase)lvi.Tag; Type typeOfModel = model.GetType(); PresetableViewBase view = null; foreach (KeyValuePair <string, AvailableModule> availableModule in AvailableModules) { if (availableModule.Value.Model == typeOfModel) { view = availableModule.Value.CreateNewView(); break; } } viewPanel.Controls.Clear(); if (view != null) { viewPanel.Controls.Add(view); view.Dock = DockStyle.Fill; view.PreInitMacroMode(); view.SetModelBase(model); } this.Cursor = Cursors.Default; }
public static int Insert(ModelBase s) { Type t = s.GetType();// 反射,程序运行的时候动态的获得类型 //如何得到类型的名称 string tableName = t.Name; List <SqlParameter> ls = new List <SqlParameter>(); StringBuilder sb = new StringBuilder(); StringBuilder sb1 = new StringBuilder(); sb.Append("insert into "); sb.Append(tableName); sb.Append("("); // 得到了这个类型里面的所有的公共的属性 (列名) PropertyInfo[] ps = t.GetProperties(); foreach (PropertyInfo item in ps) { if (item.GetValue(s, null) != null) { sb.Append(item.Name); sb.Append(","); SqlParameter p = new SqlParameter("@" + item.Name, item.GetValue(s, null)); ls.Add(p); //得到属性的值 // Console.WriteLine(item.GetValue(s, null)); sb1.Append("@" + item.Name); sb1.Append(","); } } sb.Remove(sb.Length - 1, 1); sb.Append(")"); sb.Append(" values ("); sb1.Remove(sb1.Length - 1, 1); sb1.Append(")"); sb.Append(sb1); return(DBHelp.CUD(sb.ToString(), ls.ToArray())); }
/// <summary> /// Stores a serializible model into the datacache /// </summary> /// <typeparam name="T"></typeparam> /// <param name="model"></param> internal void StoreOne(ModelBase model, bool isByteModel = false, ByteModel byteModel = null) { CheckDatacache(); // If its a normal ModelBase storing. if (!isByteModel) { var ds = new DataContractSerializer(model.GetType()); var settings = new XmlWriterSettings { Indent = true }; var currentSaveLocation = Path.Combine(_databasePath, TermHelper.GetDatabaseTerm(), model.GetType().Name); // Always check if a directory exists. If not, create it. IOPathHelper.CreateDirectory(currentSaveLocation); using (var sww = new StringWriter()) { using (var w = XmlWriter.Create(Path.Combine(currentSaveLocation, $"{model.Id}.xml"), settings)) { ds.WriteObject(w, model); } } } else if (isByteModel) // If it's a byteModel { var currentSaveLocation = Path.Combine(_databasePath, TermHelper.GetDatabaseTerm(), byteModel.GetType().Name); // It's important to write the bytes decrypted since MemProtection works with the localUser. So the data would be bound to this pc and user. var decryptedValue = CryptMemoryProtection.DecryptInMemoryData(byteModel.EncryptedValue); // Always check if a directory exists. If not, create it. IOPathHelper.CreateDirectory(currentSaveLocation); // Write the Value of byteModels into a file with the foreignKey as the name. File.WriteAllBytes($"{currentSaveLocation}\\{byteModel.ForeignKey}", decryptedValue); decryptedValue = null; } }
public bool Excute(SuperControl.ServiceModel.ExcuteAction[] actions) { bool issuccessed = false; List <ExcuteAction> retList = new List <ExcuteAction>(); lock (s_ServiceLocker) { foreach (ExcuteAction action in actions) { ModelBase model = action.ExcuteObject as ModelBase; if (model == null) { continue; } Exception ex = null; string logstring = string.Empty; int maxrid = 0; switch (action.ExcuteType) { case ExcuteType.Delete: ModelMapping mp = new ModelMapping(model.GetType()); ModelFactoryCollection.DeleteModel(model, mp, out ex); logstring = "delete"; if (ex == null) { ModelAccessManager.CacheManager.Remove(model); retList.Add(action); } break; case ExcuteType.Append: case ExcuteType.Insert: mp = new ModelMapping(model.GetType()); //model.Rid = ModelFactoryCollection.GetMaxRid(mp); ModelFactoryCollection.InsertModel(model, mp, out ex); logstring = "insert"; maxrid = ModelFactoryCollection.GetMaxRid(mp); if (ex == null) { ModelAccessManager.CacheManager.Save(model); retList.Add(action); } break; case ExcuteType.Update: mp = new ModelMapping(model.GetType()); logstring = "update"; ModelFactoryCollection.UpdateModel(model, mp, out ex); if (ex == null) { ModelAccessManager.CacheManager.Save(model); retList.Add(action); } break; default: break; } try { if (ex != null) { issuccessed = false; m_callback.ErrorNotify("Registration", ex.Message, action.ExcuteType); } else { issuccessed = true; } } catch (Exception e) { m_callback = null; Console.WriteLine(e.Message); } } if (retList.Count > 0) { SendAll(retList.ToArray()); } } return(issuccessed); }
/// <summary> /// 根据数据行初始化对象 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="dr"></param> private void initModel <T>(DataRow dr, ModelBase model) where T : ModelBase { var t = model.GetType(); initModel(dr, t, model); }
public BoletoFacilInvalidEntityException(ModelBase entity) : base($"{entity.GetType().Name} inválido.") { }
private static Record asSuitableRecordInstance(ModelBase model, bool autoSql) { var record = model as Record; if (record == null) throw new MsSQLDataAccessException(string.Format(StringConsts.MODEL_TYPE_NOT_RECORD_ERROR, model.GetType().Name)); if (autoSql) { if (string.IsNullOrEmpty(record.TableName)) throw new MsSQLDataAccessException(string.Format(StringConsts.RECORD_TABLE_NAME_ERROR, model.GetType().Name)); } return record; }
/// <summary> /// Gets the serializable members for the specified model. /// </summary> /// <param name="model">The model.</param> /// <param name="membersToIgnore">The members to ignore.</param> /// <returns>The list of members to serialize.</returns> /// <exception cref="ArgumentNullException">The <paramref name="model"/> is <c>null</c>.</exception> public virtual List <MemberValue> GetSerializableMembers(ModelBase model, params string[] membersToIgnore) { Argument.IsNotNull("model", model); var membersToIgnoreHashSet = new HashSet <string>(membersToIgnore); var modelType = model.GetType(); var catelTypeInfo = PropertyDataManager.Default.GetCatelTypeInfo(modelType); var catelPropertyNames = SerializationManager.GetCatelPropertyNames(modelType); var fieldsToSerialize = SerializationManager.GetFieldsToSerialize(modelType); var propertiesToSerialize = SerializationManager.GetPropertiesToSerialize(modelType); var listToSerialize = new List <MemberValue>(); var checkedMemberNames = new List <string>(); foreach (var fieldToSerialize in fieldsToSerialize) { checkedMemberNames.Add(fieldToSerialize); if (membersToIgnoreHashSet.Contains(fieldToSerialize) || ShouldIgnoreMember(model, fieldToSerialize)) { Log.Debug("Field '{0}' is being ignored for serialization", fieldToSerialize); continue; } try { Log.Debug("Adding field '{0}' to list of objects to serialize", fieldToSerialize); var fieldInfo = modelType.GetFieldEx(fieldToSerialize); var fieldValue = new MemberValue(SerializationMemberGroup.Field, modelType, fieldInfo.FieldType, fieldInfo.Name, fieldInfo.GetValue(model)); listToSerialize.Add(fieldValue); } catch (Exception ex) { Log.Warning(ex, "Failed to get value of member '{0}.{1}', skipping item during serialization", modelType.GetSafeFullName(), fieldToSerialize); } } foreach (var propertyToSerialize in propertiesToSerialize) { checkedMemberNames.Add(propertyToSerialize); if (membersToIgnoreHashSet.Contains(propertyToSerialize) || ShouldIgnoreMember(model, propertyToSerialize)) { Log.Debug("Property '{0}' is being ignored for serialization", propertyToSerialize); continue; } try { Log.Debug("Adding property '{0}' to list of objects to serialize", propertyToSerialize); if (catelPropertyNames.Contains(propertyToSerialize)) { var propertyData = catelTypeInfo.GetPropertyData(propertyToSerialize); var actualPropertyValue = model.GetValueFast(propertyToSerialize); var propertyValue = new MemberValue(SerializationMemberGroup.CatelProperty, modelType, propertyData.Type, propertyData.Name, actualPropertyValue); listToSerialize.Add(propertyValue); } else { var propertyInfo = modelType.GetPropertyEx(propertyToSerialize); var propertyValue = new MemberValue(SerializationMemberGroup.RegularProperty, modelType, propertyInfo.PropertyType, propertyInfo.Name, propertyInfo.GetValue(model, null)); listToSerialize.Add(propertyValue); } } catch (Exception ex) { Log.Warning(ex, "Failed to get value of member '{0}.{1}', skipping item during serialization", modelType.GetSafeFullName(), propertyToSerialize); } } return(listToSerialize); }
private void AddNewScriptBrickAction(ModelBase model) { lock (_actionsCollection) { if (model is EmptyDummyBrick) { return; } if (model == null || _isAdding) { return; } _isAdding = true; if (model is Brick) { _selectedBrick = (model as Brick).Clone(); } else if (model is Script) { _selectedBrick = (model as Script).Clone(); } List <Type> multiBrickBricks = new List <Type> { typeof(ForeverBrick), typeof(RepeatBrick), typeof(IfBrick) }; if (!multiBrickBricks.Contains(_selectedBrick.GetType()) && _selectedBrick is Brick) { (_selectedBrick as Brick).IsNewAdded = true; } _actionsCollection.AddScriptBrick(_selectedBrick, _firstVisibleScriptBrickIndex, _lastVisibleScriptBrickIndex); var foreverBrick = _selectedBrick as ForeverBrick; if (foreverBrick != null) { var endBrick = new EndForeverBrick { Begin = (ForeverBrick)_selectedBrick }; foreverBrick.End = endBrick; _actionsCollection.AddScriptBrick(endBrick, _firstVisibleScriptBrickIndex, _lastVisibleScriptBrickIndex + 1); } var repeatBrick = _selectedBrick as RepeatBrick; if (repeatBrick != null) { var endBrick = new EndRepeatBrick { Begin = (RepeatBrick)_selectedBrick }; repeatBrick.End = endBrick; _actionsCollection.AddScriptBrick(endBrick, _firstVisibleScriptBrickIndex, _lastVisibleScriptBrickIndex + 1); } var ifBrick = _selectedBrick as IfBrick; if (ifBrick != null) { var elseBrick = new ElseBrick(); var endBrick = new EndIfBrick(); elseBrick.Begin = ifBrick; elseBrick.End = endBrick; endBrick.Begin = ifBrick; endBrick.Else = elseBrick; ifBrick.Else = elseBrick; ifBrick.End = endBrick; _actionsCollection.AddScriptBrick(elseBrick, _firstVisibleScriptBrickIndex, _lastVisibleScriptBrickIndex + 1); _actionsCollection.AddScriptBrick(endBrick, _firstVisibleScriptBrickIndex, _lastVisibleScriptBrickIndex + 2); } var message = new GenericMessage <ModelBase>(_selectedBrick); Messenger.Default.Send(message, ViewModelMessagingToken.SelectedBrickListener); ServiceLocator.NavigationService.RemoveBackEntry(); base.GoBackAction(); _isAdding = false; } }
public static string GetAnsysModelSolverFile(ModelBase mb) { return(Path.Combine(D_AnsysSolver, mb.GetType().Name + FileExtensions.AnsysModelSolver)); }
public static Control CreateEditor(CrudDecoratorAttribute decorator, ModelBase model) { Control editor = null; var type = decorator.Property.PropertyType; if (type.Equals(typeof(DateTime))) { var p = new DateTimePicker(); p.CustomFormat = "dd/MM/yyyy"; p.Format = DateTimePickerFormat.Short; editor = p; p.DataBindings.Add("Value", model, decorator.Property.Name); } string pn = decorator.Property.Name; if (pn.ToLower().EndsWith("id")) { var tp = Type.GetType($"{model.GetType().Namespace}.{pn.Substring(0, pn.Length-2)}", false, true); if (tp != null && !tp.Equals(model.GetType())) { var cb = new ComboBox(); cb.FormattingEnabled = true; var fd = (ModelBase)Activator.CreateInstance(tp); cb.DataSource = fd.GetController().GetList(); editor = cb; PropertyInfo id = null; foreach (var p in tp.GetProperties()) { if (p.Name.Equals($"{tp.Name}id", StringComparison.CurrentCultureIgnoreCase)) { id = p; break; } } if (id != null) { cb.ValueMember = id.Name; } cb.DataBindings.Add("SelectedValue", model, pn); } } if (type.IsEnum) { var cb = new ComboBox(); var names = Enum.GetNames(type); var values = Enum.GetValues(type); List <EnumMap> map = new List <EnumMap>(); int index = 0; foreach (var e in type.GetMembers()) { if (!names.Contains(e.Name)) { continue; } var a = e.GetCustomAttributes(typeof(DescriptionAttribute), false); string name = null; if (a != null && a.Length > 0) { name = ((DescriptionAttribute)a[0]).Description; } else { name = e.Name; } map.Add(new EnumMap() { Name = name, Value = values.GetValue(index) }); index++; } cb.DataSource = map; cb.ValueMember = "Value"; cb.DataBindings.Add("SelectedValue", model, decorator.Property.Name); editor = cb; } if (editor == null) { editor = new TextBox(); editor.DataBindings.Add("Text", model, decorator.Property.Name); } return(editor); }
public static Record AsSuitableRecordInstance(ModelBase model, bool autoSql) { var record = model as Record; if (record == null) { throw new MySQLDataAccessException(string.Format(StringConsts.MODEL_TYPE_NOT_RECORD_ERROR, model.GetType().Name)); } if (autoSql) { if (string.IsNullOrEmpty(record.TableName)) { throw new MySQLDataAccessException(string.Format(StringConsts.RECORD_TABLE_NAME_ERROR, model.GetType().Name)); } } return(record); }
private static Record asSuitableRecordInstance(ModelBase model) { var record = model as Record; if (record == null) { throw new MongoDBDataAccessException(string.Format(StringConsts.MODEL_TYPE_NOT_RECORD_ERROR, model.GetType().Name)); } if (string.IsNullOrEmpty(record.TableName)) { throw new MongoDBDataAccessException(string.Format(StringConsts.RECORD_TABLE_NAME_ERROR, model.GetType().Name)); } return(record); }
public XmlObject Convert(ModelBase m, XmlModelConvertBackContext c) { return(_modelToXmlConverters[m.GetType()].Convert(m, c)); }
public static void UpdateEntity(ModelBase model, object entity, bool strictBinding = false) { foreach (PropertyInfo PI in model.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)) { IEnumerable <FieldMapperAttribute> attributes = PI.GetCustomAttributes <FieldMapperAttribute>(true); FieldMapperAttribute attribute = attributes.FirstOrDefault(E => E.EntityType == entity.GetType() || (E.EntityType != null && entity.GetType().Name == E.EntityType.Name + "Proxy")); if (attribute == null && !strictBinding) { attribute = attributes.FirstOrDefault(E => E.EntityType == null); } if (attribute != null && !attribute.ReadOnly) { if (attribute.IsArray) { object[] modelValue = (object[])PI.GetValue(model); if (modelValue != null) { int MaxLen = Math.Min(attribute.ArrayMaxRank, modelValue.Length); for (int index = 0; index < MaxLen; index++) { UpdateEntityArrayField(entity, attribute.SourceFieldName, index + 1, modelValue[index] ?? attribute.DefaultValue); } } else { for (int index = 0; index < attribute.ArrayMaxRank; index++) { UpdateEntityArrayField(entity, attribute.SourceFieldName, index + 1, attribute.DefaultValue); } } } else { PropertyInfo entityPI = entity.GetType().GetProperty(attribute.SourceFieldName); if (entityPI != null) { object modelValue = PI.GetValue(model); object entityValue = modelValue ?? attribute.DefaultValue; if (PI.PropertyType == typeof(bool) && entityPI.PropertyType == typeof(string)) { entityValue = (bool)modelValue ? "Y" : "N"; } else if (PI.PropertyType == typeof(bool?) && entityPI.PropertyType == typeof(string)) { if (PI.PropertyType == typeof(bool?) && modelValue != null) { entityValue = (bool)modelValue ? "Y" : "N"; } } /* * else if (PI.PropertyType == typeof(string) && entityPI.PropertyType == typeof(string)) * entityValue = CheckStringLength(entity, entityPI, (string)entityValue); */ entityPI.SetValue(entity, entityValue); } } } } UpdateEntityStandardFields(entity); }
/// <summary> /// Deletes <see cref="ModelBase"/> object given by <see cref="XmlElement"/> /// from a corresponding collection of the workspace. /// </summary> /// <param name="modelData"><see cref="ModelBase"/> object given by <see cref="XmlElement"/></param> public void DeleteModel(XmlElement modelData) { //When there is a Redo operation, model is removed from //the workspace but the model is "not disposed" from memory. //Identified this when redo operation is performed on groups ModelBase model = GetModelForElement(modelData); if (model is NoteModel) { var note = model as NoteModel; RemoveNote(note); note.Dispose(); } else if (model is AnnotationModel) { RemoveGroup(model); } else if (model is PresetModel) { this.RemovePreset(model as PresetModel); } else if (model is ConnectorModel) { var connector = model as ConnectorModel; connector.Delete(); } else if (model is ConnectorPinModel connectorPin) { ///The equivalent of 'deleting' a connectorPin var matchingConnector = Connectors.FirstOrDefault(connector => connector.GUID == connectorPin.ConnectorId); if (matchingConnector is null) { return; } matchingConnector.ConnectorPinModels.Remove(connectorPin); } else if (model is NodeModel) { var node = model as NodeModel; // Note that AllConnectors is duplicated as a separate list // by calling its "ToList" method. This is the because the // "Connectors.Remove" will modify "AllConnectors", causing // the Enumerator in this "foreach" to become invalid. foreach (var conn in node.AllConnectors.ToList()) { if (conn.ConnectorPinModels.Count > 0) { foreach (var connPin in conn.ConnectorPinModels.ToList()) { var matchingConnector = Connectors.FirstOrDefault(c => c.GUID == connPin.ConnectorId); if (matchingConnector is null) { return; } matchingConnector.ConnectorPinModels.Remove(connPin); } } conn.Delete(); } RemoveAndDisposeNode(model as NodeModel); } else if (model == null) { return; } //some unknown type else { // If it gets here we obviously need to handle it. throw new InvalidOperationException(string.Format( "Unhandled type: {0}", model.GetType())); } }
/// <summary> /// Gets the serializable members for the specified model. /// </summary> /// <param name="model">The model.</param> /// <param name="membersToIgnore">The members to ignore.</param> /// <returns>The list of members to serialize.</returns> /// <exception cref="ArgumentNullException">The <paramref name="model"/> is <c>null</c>.</exception> public virtual List <MemberValue> GetSerializableMembers(ModelBase model, params string[] membersToIgnore) { Argument.IsNotNull("model", model); var membersToIgnoreHashSet = new HashSet <string>(membersToIgnore); var modelType = model.GetType(); var modelInfo = _serializationModelCache.GetFromCacheOrFetch(modelType, () => { var catelPropertyNames = SerializationManager.GetCatelPropertyNames(modelType); var fieldsToSerialize = SerializationManager.GetFieldsToSerialize(modelType); var propertiesToSerialize = SerializationManager.GetPropertiesToSerialize(modelType); return(new SerializationModelInfo(modelType, catelPropertyNames, fieldsToSerialize, propertiesToSerialize)); }); var listToSerialize = new List <MemberValue>(); var checkedMemberNames = new HashSet <string>(); foreach (var propertyName in modelInfo.PropertiesByName.Keys) { if (checkedMemberNames.Contains(propertyName)) { continue; } checkedMemberNames.Add(propertyName); if (membersToIgnoreHashSet.Contains(propertyName) || ShouldIgnoreMember(model, propertyName)) { Log.Debug("Property '{0}' is being ignored for serialization", propertyName); continue; } try { //Log.Debug("Adding property '{0}' to list of objects to serialize", propertyName); var modelEditor = model as IModelEditor; if (modelEditor != null && modelInfo.CatelPropertyNames.Contains(propertyName)) { var propertyData = modelInfo.CatelPropertiesByName[propertyName]; var actualPropertyValue = modelEditor.GetValueFastButUnsecure(propertyName); var propertyValue = new MemberValue(SerializationMemberGroup.CatelProperty, modelType, propertyData.Type, propertyData.Name, actualPropertyValue); listToSerialize.Add(propertyValue); } else { var propertyInfo = modelInfo.PropertiesByName[propertyName]; var propertyValue = new MemberValue(SerializationMemberGroup.RegularProperty, modelType, propertyInfo.PropertyType, propertyName, propertyInfo.GetValue(model, null)); listToSerialize.Add(propertyValue); } } catch (Exception ex) { Log.Warning(ex, "Failed to get value of member '{0}.{1}', skipping item during serialization", modelType.GetSafeFullName(), propertyName); } } foreach (var field in modelInfo.Fields) { if (checkedMemberNames.Contains(field.Name)) { continue; } checkedMemberNames.Add(field.Name); if (membersToIgnoreHashSet.Contains(field.Name) || ShouldIgnoreMember(model, field.Name)) { Log.Debug("Field '{0}' is being ignored for serialization", field.Name); continue; } try { Log.Debug("Adding field '{0}' to list of objects to serialize", field.Name); var fieldValue = new MemberValue(SerializationMemberGroup.Field, modelType, field.FieldType, field.Name, field.GetValue(model)); listToSerialize.Add(fieldValue); } catch (Exception ex) { Log.Warning(ex, "Failed to get value of member '{0}.{1}', skipping item during serialization", modelType.GetSafeFullName(), field.Name); } } return(listToSerialize); }