2011-03-21 14 views

cevap

9

yeni bir Microsoft var gibi varlıklar için bu sınıfın yararlanabilir

public class CustomSerializationTableEntity : TableEntity 
{ 
    public CustomSerializationTableEntity() 
    { 
    } 

    public CustomSerializationTableEntity(string partitionKey, string rowKey) 
     : base(partitionKey, rowKey) 
    { 
    } 

    public override IDictionary<string, EntityProperty> WriteEntity(Microsoft.WindowsAzure.Storage.OperationContext operationContext) 
    { 
     var entityProperties = base.WriteEntity(operationContext); 

     var objectProperties = this.GetType().GetProperties(); 

     foreach (PropertyInfo property in objectProperties) 
     { 
      // see if the property has the attribute to not serialization, and if it does remove it from the entities to send to write 
      object[] notSerializedAttributes = property.GetCustomAttributes(typeof(NotSerializedAttribute), false); 
      if (notSerializedAttributes.Length > 0) 
      { 
       entityProperties.Remove(property.Name); 
      } 
     } 

     return entityProperties; 
    } 
} 

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

: Ben müzik gibi, bütün varlıklar için bunu yapan bir sınıftan türetmek. WindowsAzure.Storage.Table.IgnoreProperty özniteliği. Daha fazla bilgi için 2.1 sürüm notlarına bakın: http://blogs.msdn.com/b/windowsazurestorage/archive/2013/09/07/announcing-storage-client-library-2-1-rtm.aspx.

5

Tablo Depolama SDK 2.0 sürümü için bunu başarmak için yeni bir yolu yoktur.

Artık TableEntity üzerinde WriteEntity yöntemini geçersiz ve üzerlerinde bir niteliğe herhangi bir kuruluş özelliklerini kaldırabilirsiniz. Sonra Version 2.1 için

public class MyEntity : CustomSerializationTableEntity 
{ 
    public MyEntity() 
    { 
    } 

    public string MySerializedProperty { get; set; } 

    [NotSerialized] 
    public List<string> MyNotSerializedProperty { get; set; } 
} 
İlgili konular