コード例 #1
0
ファイル: Deserialiser.cs プロジェクト: faraplay/ImasArchiveS
 private static void SetProperty(Binary binary, Type objType, object newObject, PropertyInfo prop, SerialisePropertyAttribute attribute)
 {
     if (attribute.ConditionProperty != null)
     {
         var conditionProperty = objType.GetProperty(attribute.ConditionProperty);
         if (conditionProperty == null)
         {
             throw new Exception($"Property {attribute.ConditionProperty} was not found.");
         }
         if (conditionProperty.PropertyType != typeof(bool))
         {
             throw new Exception($"Property {attribute.ConditionProperty} is not of type bool.");
         }
         if (!(bool)conditionProperty.GetValue(newObject))
         {
             return;
         }
     }
     if (prop.PropertyType.IsArray)
     {
         DeserialiseArray(binary, prop.GetValue(newObject));
         return;
     }
     if (prop.PropertyType.IsGenericType && prop.PropertyType.GetGenericTypeDefinition() == typeof(List <>))
     {
         DeserialiseList(binary, prop.GetValue(newObject));
         return;
     }
     prop.SetValue(newObject, Deserialise(binary, prop.PropertyType));
 }
コード例 #2
0
ファイル: Serialiser.cs プロジェクト: faraplay/ImasArchiveS
 private static void SerialiseProperty(Binary binary, Type objType, object obj, PropertyInfo prop, SerialisePropertyAttribute attribute)
 {
     if (attribute.ConditionProperty != null)
     {
         var conditionProperty = objType.GetProperty(attribute.ConditionProperty);
         if (conditionProperty == null)
         {
             throw new Exception($"Property {attribute.ConditionProperty} was not found.");
         }
         if (conditionProperty.PropertyType != typeof(bool))
         {
             throw new Exception($"Property {attribute.ConditionProperty} is not of type bool.");
         }
         if (!(bool)conditionProperty.GetValue(obj))
         {
             return;
         }
     }
     Serialise(binary, prop.GetValue(obj));
 }