2011-07-19 44 views

回答

2

我不會建議,但這可以做到。

創建匹配SubSonics屬性(像OrmIgnore而不是SubSonicIgnore你自己的屬性時,還是要實現SubSonic.SqlGeneration.Schema.IClassMappingAttributeSubSonic.SqlGeneration.Schema.IPropertyMappingAttributeSubSonic.SqlGeneration.Schema.IRelationMappingAttribute

看從SubSonic.Core \擴展\ Object.cs此代碼來獲得一個想法發生了什麼

public static ITable ToSchemaTable(this Type type, IDataProvider provider) 
    { 

     ... 

     var typeAttributes = type.GetCustomAttributes(typeof(IClassMappingAttribute), false); 

     foreach (IClassMappingAttribute attr in typeAttributes) 
     { 
      if (attr.Accept(result)) 
      { 
       attr.Apply(result); 
      } 
     } 

     ... 

     // Now work with attributes 
     foreach (IPropertyMappingAttribute attr in attributes.Where(x => x is IPropertyMappingAttribute)) 
     { 
      if (attr.Accept(column)) 
      { 
       attr.Apply(column); 
      } 
     } 

     .... 

    } 

您的應用實現應修改架構做你想做什麼 贊一個(從SubSonicDefaultSettingAttribute):

public void Apply(IColumn column) 
    { 
     column.DefaultSetting = DefaultSetting; 
    } 

你應該檢查亞音速源和標記每一個自定義屬性爲過時

[Obsolete("Use OrmIgnore instead", true)] 
[AttributeUsage(AttributeTargets.Property)] 
public class SubSonicIgnoreAttribute : Attribute { } 

有到您將需要修復的屬性(不使用的接口)的一些直接引用。

,你將不得不尋找字符串引用

private static bool ColumnIsIgnored(object[] attributes) 
    { 
     foreach (var att in attributes) 
     { 
      if (att.ToString().Equals("SubSonic.SqlGeneration.Schema.SubSonicIgnoreAttribute")) 
      { 
       return true; 
      } 
     } 

     return false; 
    } 

private static bool ColumnIsIgnored(object[] attributes) 
    { 
     foreach (var att in attributes) 
     { 
      if (att.ToString().EndsWith("OrmIgnoreAttribute")) 
      { 
       return true; 
      } 
     } 

     return false; 
    } 
相關問題