Ejemplo n.º 1
0
 /// <summary> Reads a property value (value type or reference) from the string. </summary>
 /// <remarks> If AInstance and AMember are null, than fixups will not be performed for references. </remarks>
 private object AttributeToValue(string tempValue, Type type, object instance, MemberInfo member)
 {
     if (IsValueType(type))             // value types (strings are effectively a value type)
     {
         return(ReflectionUtility.StringToValue(tempValue, type));
     }
     else if (type.IsSubclassOf(typeof(Delegate)))
     {
         throw new BOPException(BOPException.Codes.DelegatesNotSupported);                               // TODO: Read delegates
     }
     else
     {
         // reference type, try a type converter, then assume it is a reference to another object in the tree
         // Attempt to load the reference using a value converter, maybe it's not a name but a converted value
         var converter = Persistence.GetTypeConverter(type);
         if (converter != null)
         {
             return(converter.ConvertFromString(tempValue));
         }
         else
         {
             return(GetReference(tempValue, instance, member));
         }
     }
 }
Ejemplo n.º 2
0
 /// <summary> Determines an attribute string for the given instance reference. </summary>
 private string ReferenceToString(object tempValue, out bool reference)
 {
     reference = true;
     if (tempValue == null)
     {
         return(String.Empty);
     }
     else
     {
         Type type = tempValue.GetType();
         PublishNameAttribute attribute = ((PublishNameAttribute)ReflectionUtility.GetAttribute(type, typeof(PublishNameAttribute)));
         if (attribute != null)
         {
             return((string)ReflectionUtility.GetMemberValue(ReflectionUtility.FindSimpleMember(type, attribute.MemberName), tempValue));
         }
         else
         {
             var converter = Persistence.GetTypeConverter(type);
             if (converter != null)
             {
                 reference = false;
                 return(converter.ConvertToString(tempValue));
             }
         }
         return(String.Empty);
     }
 }