<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="RSS_xslt_style.asp" version="1.0" ?>
<rss version="2.0" xmlns:WebWizForums="http://syndication.webwiz.co.uk/rss_namespace/">
 <channel>
  <title>DevForce Community Forum : Retreive max string length at runtime</title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : DevForce 2010 : Retreive max string length at runtime</description>
  <pubDate>Wed, 29 Jul 2026 18:43:08 -700</pubDate>
  <lastBuildDate>Mon, 21 Mar 2011 10:44:02 -700</lastBuildDate>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Web Wiz Forums 9.69</generator>
  <ttl>360</ttl>
  <WebWizForums:feedURL>www.ideablade.com/forum/RSS_post_feed.asp?TID=2571</WebWizForums:feedURL>
  <image>
   <title>DevForce Community Forum</title>
   <url>http://www.ideablade.com/forum/forum_images/IdeaBlade_logo_tm.png</url>
   <link>http://www.ideablade.com/forum/</link>
  </image>
  <item>
   <title>Retreive max string length at runtime : Hello again Chuck,  You might...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2571&amp;PID=10230#10230</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=892" rel="nofollow">sbelini</a><br /><strong>Subject:</strong> 2571<br /><strong>Posted:</strong> 21-Mar-2011 at 10:44am<br /><br />Hello again Chuck,<DIV>&nbsp;</DIV><DIV>You might actually be able to do that by using reflection:</DIV><DIV>&nbsp;</DIV><DIV><DIV><DIV>public void GetMaxStringLengthSample() {</DIV><DIV>&nbsp;&nbsp; &nbsp; &nbsp;var maxStringLength = GetMaxStringLengthAttribute(typeof(Customer), &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</DIV><DIV>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; Customer.PropertyMetadata.CompanyName.Name);</DIV><DIV>&nbsp;&nbsp; &nbsp; &nbsp;</DIV><DIV>&nbsp;&nbsp; &nbsp; &nbsp; Assert.IsTrue(maxStringLength == 40, "This should not fail");</DIV><DIV>}</DIV><DIV><BR></DIV><DIV>public int GetMaxStringLengthAttribute(Type entityType, String propertyName) {</DIV><DIV>&nbsp;&nbsp; &nbsp; &nbsp;var propertyInfo = entityType.GetProperty(propertyName);</DIV><DIV>&nbsp;&nbsp; &nbsp; &nbsp;var attributes = (StringLengthVerifierAttribute)propertyInfo</DIV><DIV>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;.GetCustomAttributes(typeof(StringLengthVerifierAttribute), false).First();</DIV><DIV><BR></DIV><DIV>&nbsp;&nbsp; &nbsp; &nbsp;return attributes.MaxValue;</DIV><DIV>}</DIV><DIV>&nbsp;</DIV><DIV>You can also find this snippet in its original thread at <a href="http://www.ideablade.com/forum/forum_posts.asp?TID=2152&amp;title=string-field-maxlength" target="_blank">http://www.ideablade.com/forum/forum_posts.asp?TID=2152&amp;title=string-field-maxlength</A></DIV><DIV>&nbsp;</DIV><DIV>Silvio.</DIV></DIV></DIV>]]>
   </description>
   <pubDate>Mon, 21 Mar 2011 10:44:02 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2571&amp;PID=10230#10230</guid>
  </item> 
  <item>
   <title>Retreive max string length at runtime : Hi Chuck,  Unfortunatelly this...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2571&amp;PID=10225#10225</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=892" rel="nofollow">sbelini</a><br /><strong>Subject:</strong> 2571<br /><strong>Posted:</strong> 21-Mar-2011 at 2:31am<br /><br /><DIV>Hi Chuck,</DIV><DIV>&nbsp;</DIV><DIV>Unfortunatelly this is not a trivial task. You will need to retrieve this information from the EDMX. There is some information on how to do this at <a href="http://blogs.msdn.com/b/ad&#111;net/archive/2008/01/24/how-to-extract-csdl-from-edmx.aspx" target="_blank">http://blogs.msdn.com/b/adonet/archive/2008/01/24/how-to-extract-csdl-from-edmx.aspx</A>.</DIV><DIV>&nbsp;</DIV><DIV>The link above has been posted in a previous thread at <a href="http://www.ideablade.com/forum/forum_posts.asp?TID=2403&amp;KW=maxlength&amp;PID=9482&amp;title=fixedlength-fields" target="_blank">http://www.ideablade.com/forum/forum_posts.asp?TID=2403&amp;KW=maxlength&amp;PID=9482&amp;title=fixedlength-fields</A>, where someone had a similar question.</DIV><DIV>&nbsp;</DIV><DIV>I hope it helps,</DIV><DIV>&nbsp;&nbsp; Silvio.</DIV>]]>
   </description>
   <pubDate>Mon, 21 Mar 2011 02:31:55 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2571&amp;PID=10225#10225</guid>
  </item> 
  <item>
   <title>Retreive max string length at runtime : Simple question:How does one retrieve...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2571&amp;PID=10219#10219</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=705" rel="nofollow">chuckc</a><br /><strong>Subject:</strong> 2571<br /><strong>Posted:</strong> 20-Mar-2011 at 6:01pm<br /><br /><div style=": rgb255, 255, 255; margin-left: 1px; margin-top: 1px; margin-right: 1px; margin-bottom: 1px; font-family: Verdana, Arial, Helvetica, sans-serif; color: rgb0, 0, 0; font-weight: normal; font-size: 12px; line-height: 1.4; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; -: n&#111;ne; ">Simple question:<div><br></div><div>How does one retrieve the max length of a entity string field at runtime? &nbsp;I see the value provided to the StringLengthVerifier, but what is the technique to get that value for use in my own code?</div><div><br></div><div><pre style="font-family: C&#111;nsolas; font-size: 13px; -: initial; -attachment: initial; -origin: initial; -clip: initial; : white; -: initial initial; -repeat: initial initial; ">&nbsp;&nbsp;<span style="color: gray; ">///</span><span style="color: green; ">&nbsp;</span><span style="color: gray; ">&lt;summary&gt;</span><span style="color: green; ">Gets&nbsp;or&nbsp;sets&nbsp;the&nbsp;Description.&nbsp;</span><span style="color: gray; ">&lt;/summary&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;&#091;<span style="color: rgb43, 145, 175; ">Bindable</span>(<span style="color: blue; ">true</span>,&nbsp;<span style="color: rgb43, 145, 175; ">BindingDirection</span>.TwoWay)&#093;&nbsp;&nbsp;&nbsp;&nbsp;&#091;<span style="color: rgb43, 145, 175; ">Editable</span>(<span style="color: blue; ">true</span>)&#093;&nbsp;&nbsp;&nbsp;&nbsp;&#091;<span style="color: rgb43, 145, 175; ">Display</span>(Name=<span style="color: rgb163, 21, 21; ">"Description"</span>,&nbsp;AutoGenerateField=<span style="color: blue; ">true</span>)&#093;&nbsp;&nbsp;&nbsp;&nbsp;&#091;IbVal.<span style="color: rgb43, 145, 175; ">StringLengthVerifier</span>(<b><font ="Apple-style-span" color="#FF0000">MaxValue=1000,</font></b>&nbsp;IsRequired=<span style="color: blue; ">false</span>,&nbsp;ErrorMessageResourceName=<span style="color: rgb163, 21, 21; ">"AccountTransactionDetail_Description"</span>)&#093;&nbsp;&nbsp;&nbsp;&nbsp;&#091;<span style="color: rgb43, 145, 175; ">DataMember</span>&#093;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue; ">public</span>&nbsp;<span style="color: blue; ">string</span>&nbsp;Description&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue; ">get</span>&nbsp;{&nbsp;<span style="color: blue; ">return</span>&nbsp;<span style="color: rgb43, 145, 175; ">PropertyMetadata</span>.Description.GetValue(<span style="color: blue; ">this</span>);&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue; ">set</span>&nbsp;{&nbsp;<span style="color: rgb43, 145, 175; ">PropertyMetadata</span>.Description.SetValue(<span style="color: blue; ">this</span>,&nbsp;<span style="color: blue; ">value</span>);&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;}</pre><pre style="font-family: C&#111;nsolas; font-size: 13px; -: initial; -attachment: initial; -origin: initial; -clip: initial; : white; -: initial initial; -repeat: initial initial; ">Thanks!</pre></div></div>]]>
   </description>
   <pubDate>Sun, 20 Mar 2011 18:01:09 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2571&amp;PID=10219#10219</guid>
  </item> 
 </channel>
</rss>