예제 #1
0
        public static PocoToTableEntityConverter <TInput> Create()
        {
            IPropertyGetter <TInput, string>         partitionKeyGetter = GetGetter <string>("PartitionKey");
            IPropertyGetter <TInput, string>         rowKeyGetter       = GetGetter <string>("RowKey");
            IPropertyGetter <TInput, DateTimeOffset> timestampGetter    = GetGetter <DateTimeOffset>("Timestamp");
            IPropertyGetter <TInput, string>         eTagGetter         = GetGetter <string>("ETag");
            Dictionary <string, IPropertyGetter <TInput, EntityProperty> > otherPropertyGetters =
                new Dictionary <string, IPropertyGetter <TInput, EntityProperty> >();

            PropertyInfo[] properties = typeof(TInput).GetProperties(BindingFlags.Instance | BindingFlags.Public);
            Debug.Assert(properties != null);

            foreach (PropertyInfo property in properties)
            {
                Debug.Assert(property != null);

                if (TableClient.IsSystemProperty(property.Name) || !property.CanRead ||
                    property.GetIndexParameters().Length != 0 || !property.HasPublicGetMethod())
                {
                    continue;
                }

                IPropertyGetter <TInput, EntityProperty> otherPropertyGetter = GetOtherGetter(property);
                otherPropertyGetters.Add(property.Name, otherPropertyGetter);
            }

            return(new PocoToTableEntityConverter <TInput>(partitionKeyGetter, rowKeyGetter, timestampGetter, eTagGetter,
                                                           otherPropertyGetters));
        }