Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / October 2007

Tip: Looking for answers? Try searching our database.

reading ColumnAttribute data

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
lausivcid - 20 Oct 2007 05:01 GMT
Hi,

  How can ColumnAttribute data be read from xxDataClasses.cs Columns
like this?

        [Column(Storage="_Name", DbType="VarChar(256) NOT
NULL", CanBeNull=false)]
        public string Name
        {
            get
            {
                return this._Name;
            }
            set
            {
                if ((this._Name != value))
                {
                    this.OnNameChanging(value);
                    this.SendPropertyChanging();
                    this._Name = value;
this.SendPropertyChanged("Name");
                    this.OnNameChanged();
                }
            }
        }

Attribute.GetCustomAttribute(this.Name.GetType().Module,typeof(System.Data.Linq.Mapping.ColumnAttribute))
returned null,
Attribute.GetCustomAttributes(this.Name.GetType().Module) returned
only the System.Security.UnverifiableCodeAttribute attribute.
Specifically I want to parse DbType to get the maximum length of the
column.   Is there any other way to find the column width?

Thanks,
lausivcid
Nicholas Paldino [.NET/C# MVP] - 20 Oct 2007 18:02 GMT
lausivcid,

   Well, you have applied the attribute to a property, so you have to get
the PropertyInfo for that property (Name) and then call GetCustomAttributes
on that.

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

> Hi,
>
[quoted text clipped - 31 lines]
> Thanks,
> lausivcid
lausivcid - 23 Oct 2007 21:30 GMT
Thanks!  For

        [Column(Storage="_Name", DbType="VarChar(256) NOT
NULL", CanBeNull=false)]
        public string Name
        {
            get
            {
                return this._Name;
            }
            set
            {
                if ((this._Name != value))
                {
                    this.OnNameChanging(value);
                    this.SendPropertyChanging();
                    this._Name = value;
this.SendPropertyChanged("Name");
                    this.OnNameChanged();
                }
            }
        }

The class tyoe for this property is "job".  The below code gets the
DbType string I am looking for.

                      foreach (MemberInfo mi in
job.GetType().GetMembers())
                       {
                               string attrib=
((System.Data.Linq.Mapping.ColumnAttribute)(mi.GetCustomAttributes(false)[0])).DbType;
                       }

>lausivcid,
>
>    Well, you have applied the attribute to a property, so you have to get
>the PropertyInfo for that property (Name) and then call GetCustomAttributes
>on that.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.