2011-02-11 15 views
9

मैं ईएफ 4.0 में अपनी .tt फ़ाइल को अनुकूलित कर रहा हूं। अब भाग एफ अनुकूलन के रूप में मुझे पीओसीओ कक्षा पीढ़ी में किसी संपत्ति में कुछ कोड जोड़ने की आवश्यकता है, अगर संपत्ति का प्रकार Nullable<System.DateTime> या System.DateTime है। मैं तुलना के लिए उचित वाक्यविन्यास नहीं ढूंढ पा रहा हूं।किसी टी 4 टेम्पलेट फ़ाइल में किसी इकाई में किसी संपत्ति के डेटाटाइप को कैसे जांचें

मेरे पास .tt फ़ाइल में निम्न कोड है।

foreach (EdmProperty edmProperty in entity.Properties.Where(p => p.TypeUsage.EdmType is PrimitiveType && p.DeclaringType == entity)) 
{ 
bool isDefaultValueDefinedInModel = (edmProperty.DefaultValue != null); 
//Here I need to check whether my edmProperty is Nullable<System.DateTime> or System.DateTime, so that I can insert custom code. 
} 

कृपया मदद करें।

उत्तर

12
if (((PrimitiveType)edmProperty.TypeUsage.EdmType). 
     PrimitiveTypeKind == PrimitiveTypeKind.DateTime && edmProperty.Nullable) 
-1

नियमित जांच:

if(edmproperty.GetType() == typeof(System.DateTime)){ } 

Nullable जांच:

if(edmproperty != null && edmproperty.GetType() == typeof(Nullable<System.DateTime>)) 
+0

आपको बहुत बहुत धन्यवाद। मैंने इसे एक अलग तरीके से हल किया। कोड निम्नलिखित है। अगर (((PrimitiveType) edmProperty.TypeUsage.EdmType) .PrimitiveTypeKind == PrimitiveTypeKind.DateTime && edmProperty.Nullable) \t \t { – WPFProgrammer

+0

'edmproperty.GetType()' हमेशा एक 'typeof (EdmProperty)', कभी नहीं लौटेगा एक ' डेटटाइम 'या' न्यूबल योग्य '। – xr280xr

संबंधित मुद्दे