Click here to Skip to main content
15,891,864 members
Home / Discussions / C#
   

C#

 
AnswerRe: Subjective question: which one of these Lazy Init is best Pin
BillWoodruff20-Oct-17 22:42
professionalBillWoodruff20-Oct-17 22:42 
GeneralRe: Subjective question: which one of these Lazy Init is best Pin
Super Lloyd20-Oct-17 23:01
Super Lloyd20-Oct-17 23:01 
GeneralRe: Subjective question: which one of these Lazy Init is best Pin
BillWoodruff21-Oct-17 0:44
professionalBillWoodruff21-Oct-17 0:44 
GeneralRe: Subjective question: which one of these Lazy Init is best Pin
Super Lloyd21-Oct-17 1:21
Super Lloyd21-Oct-17 1:21 
QuestionRe: Subjective question: which one of these Lazy Init is best Pin
Super Lloyd20-Oct-17 21:10
Super Lloyd20-Oct-17 21:10 
AnswerRe: Subjective question: which one of these Lazy Init is best Pin
Sascha Lefèvre21-Oct-17 2:54
professionalSascha Lefèvre21-Oct-17 2:54 
GeneralRe: Subjective question: which one of these Lazy Init is best Pin
BillWoodruff22-Oct-17 6:08
professionalBillWoodruff22-Oct-17 6:08 
QuestionAttributes on fields in a DataTable/DataRow Pin
hpjchobbes18-Oct-17 10:27
hpjchobbes18-Oct-17 10:27 
I am using a DataRow to get and set values (based on the manually typed data table from How to Manually Create a Typed DataTable[^]. The fields in the datarow can have different attributes that I would need to track, the main one being a maximum number of characters for some strings, but different versions have different lengths. I was trying to use Attributes to help with this, but I am stuck with how to be able to set/determine the 'version' when going through the attributes. I'd like to be able to set the version on the dataset as a whole and have the fields of the data row be able to use that to determine how to get values.

Here's how I setup my attribute class:
C#
[AttributeUsage(AttributeTargets.Property, AllowMultiple =true)]
public class MaxLengthAttribute : Attribute
{

    public string Version;
    public int MaxLength;

    public MaxLengthAttribute(string version, int max)
    {
       Version= version;
       MaxLength = max;
    }
}
Here's what the data row looks like and how I am envisioning this would work.
C#
public CustomerRow : DataRow
{
   [MaxLength("1.0", 40)]
   [MaxLength("2.0", 45)]
   public string Name
   {
        get
        {
            if(base["Name"] == DBNull.Value) throw new NullException("Name is null.");
            return ((TruncatedString)base["Name"]).Value;
        }
   }
}
I created a class called TruncatedString that has a string and bool, which i am using as the data type for the field in the data row. In the TruncatedString I am trying to get the version of the data set and the max length attribute to find out how long my field can be:
C#
public class TruncatedString
{
    public bool AutoTruncate;
    private string _Value;
    public string Value
    {
        get
        {
            if(AutoTruncate)
            {
                int maxLength = ???
                // How to get the version from the DataSet
                // And the MaxLength attribute for the field in the data row
                if(maxLength >= 0 && Value.Length > maxLength) return _Value.Substring(0, maxLength);
            }
                return _Value;
         }
         set { _Value = value; }
    }
}


I am not sure if Attributes are the best way to go with this setup, but I do need to be able to store the untruncated string as well as a way to get the truncated but be able to have different lengths for different versions. I also want to be able to do other attributes, for example a field that was added in version 2.0 but not available in 1.0.
AnswerRe: Attributes on fields in a DataTable/DataRow Pin
Gerry Schmitz18-Oct-17 18:08
mveGerry Schmitz18-Oct-17 18:08 
QuestionHow to reverse an array without using Array.Reverse()? Pin
Mubi Ace17-Oct-17 4:58
Mubi Ace17-Oct-17 4:58 
AnswerRe: How to reverse an array without using Array.Reverse()? Pin
Eddy Vluggen17-Oct-17 5:22
professionalEddy Vluggen17-Oct-17 5:22 
GeneralRe: How to reverse an array without using Array.Reverse()? Pin
Richard Deeming17-Oct-17 9:08
mveRichard Deeming17-Oct-17 9:08 
QuestionHow can I change an icon in the Windows taskbar at run time? Pin
Member 1063109916-Oct-17 11:30
Member 1063109916-Oct-17 11:30 
QuestionHow to prevent stopping application Pin
Mou_kol16-Oct-17 4:12
Mou_kol16-Oct-17 4:12 
AnswerRe: How to prevent stopping application Pin
OriginalGriff16-Oct-17 4:31
mveOriginalGriff16-Oct-17 4:31 
SuggestionRe: How to prevent stopping application PinPopular
Richard Deeming16-Oct-17 7:56
mveRichard Deeming16-Oct-17 7:56 
AnswerRe: How to prevent stopping application Pin
jschell17-Oct-17 7:24
jschell17-Oct-17 7:24 
SuggestionFYI: FileOptions.WriteThrough / FileStream.Flush(true) / FlushFileBuffers Pin
Sascha Lefèvre15-Oct-17 0:28
professionalSascha Lefèvre15-Oct-17 0:28 
Questionvoipsdk.dll..... basic ivr c# Pin
karimkarimkarim13-Oct-17 14:50
karimkarimkarim13-Oct-17 14:50 
AnswerRe: voipsdk.dll..... basic ivr c# Pin
Richard Andrew x6413-Oct-17 16:38
professionalRichard Andrew x6413-Oct-17 16:38 
QuestionC# multitasking Pin
Member 1346321013-Oct-17 0:51
Member 1346321013-Oct-17 0:51 
AnswerRe: C# multitasking Pin
OriginalGriff13-Oct-17 1:59
mveOriginalGriff13-Oct-17 1:59 
QuestionThread WaitReason.UserRequest Pin
Bernhard Hiller12-Oct-17 21:44
Bernhard Hiller12-Oct-17 21:44 
QuestionC# - run exe from within a form, and keep the exe's borders within the actual boundary of the form... Pin
Member 1184284812-Oct-17 13:38
Member 1184284812-Oct-17 13:38 
AnswerRe: C# - run exe from within a form, and keep the exe's borders within the actual boundary of the form... Pin
Afzaal Ahmad Zeeshan12-Oct-17 16:24
professionalAfzaal Ahmad Zeeshan12-Oct-17 16:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.