Adding custom properties to an IsolatedStorageOfflineEntity

Answered Adding custom properties to an IsolatedStorageOfflineEntity

  • 28 июня 2011 г. 17:47
     
      С кодом

    It appears that I can not add custom properties to an IsolatedStorageOfflineEntity i.e.

     

     

     public partial class orders
     {
      public IList<order_details> OrderDetails { get; set; }
      }
    

     

    If I do I get an error when sync'ing. Am I correct in this observation and what is the best practice to work around this limitation?

     

     


Все ответы

  • 1 июля 2011 г. 0:44
    Владелец
     
     Отвечено

    What is the error you get when you sync?

    Yes I think currently the OfflineEntities are bound to the schema of the table you provision. The deserialization and serialization code reflects through all properties of the entity. When we release the source code of the project, you can change it to only read/write properties with a specific attribute and ignore other properties.

    • Помечено в качестве ответа GAX user 1 июля 2011 г. 15:07
    •  
  • 1 июля 2011 г. 15:07
     
     

    Thanks for your reply. 

    The error message I get is "TypeCode Object is not a supported type."

    I suppose asking when the source code will be released is getting rather redundant? 

  • 4 мая 2012 г. 23:43
     
      С кодом

    I was having the same issue and the source code is now available. After a couple of hours of trying to understand the code (and learning how to use attributes), I made the following changes and it works. In case anyone comes up against the same issue, I'm putting the code I used here. It might not be the best, and I haven't done any rigorous testing to make sure it won't fail, but for now it seems to be fine:

    I first created a class to be used as the attribute:

    [AttributeUsage(AttributeTargets.Property)]
    public class NonSerializedAttribute : Attribute { }

    I added a check to make sure it was NonSerialized in Line 55 of ReflectionUtility.cs

    props = props.Where((e) => 
                                (!e.Name.Equals("ServiceMetadata", StringComparison.Ordinal) && 
                                e.GetCustomAttributes(typeof(NonSerializedAttribute), false).Length == 0 &&
                                e.GetGetMethod() != null && 
                                e.GetSetMethod() != null && 
                                e.DeclaringType.Equals(type))).ToArray();

    Now, when I add a property to the partial class, I do the following:

    public partial class Items { 
        [NonSerialized] 
        public Person Owner {get; set;} 
    }

    I'll update this if I come against any issues. Hopefully this is useful for someone!

    • Изменено TWSouthwick 4 мая 2012 г. 23:48 Formatting
    •  
  • 8 мая 2012 г. 13:38
     
     

    ... I made the following changes and it works. In case anyone comes up against the same issue, I'm putting the code I used here. ... Hopefully this is useful for someone!

    Thank you very much for sharing your code! Someone definatly should put a copy of SyncFramework on CodePlex or something so we can share and collect patches in a much more professional way.

    Senior Jack of all trades