473,394 Members | 1,746 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Component model and attributes with AllowMultiple=true

It appears that when using the component model (or the default
implementation, at least), then any duplicated attributes (e.g. from
properties) are dropped. In my test, component-model outputs "abc" only, and
reflection ouotputs "def" and "abc" (in that order).

Is there any way to get duplicated attributes to present themselves in the
component model? Runnable demo code follows at foot.

In context, I was looking to see if I could hang some regex expressions off
properties for validity checking (by another component, and it doesn't
prevent setting). Sometimes a single property needs to be validated by a
number (>1) of regex expressions [or at least, it is far cleaner that way].
And yes, I could perhaps use a single params array, but I was also trying to
capture "must match" and "must not match" separately as an additional
attribute parameter.

*alternatively*, can anybody brute-force this pair of patterns (which I
think meet the spec.) into a single regex? The first should match, the
second should fail (exclusions):

//
http://www.govtalk.gov.uk/gdsc/html/...-1-Release.htm
//1. Must be 9 characters.
//2. First 2 characters must be alpha.
//3. Next 6 characters must be numeric.
//4. Final character can be A, B, C, D or space.
//5. First character must not be D,F,I,Q,U or V
//6. Second characters must not be D, F, I, O, Q, U or V.
//7. First 2 characters must not be combinations of GB, NK, TN or ZZ
(the term combinations covers both GB and BG etc.)

regex1 (should match): @"^[A-CEGHJ-PRSTW-Z][A-CEGHJ-NPR-TW-Z]\d{6}[ABCD]?$"
regex1 (shouldn't match): @"^(GB|BG|NK|KN|TN|NT|ZZ)"

Marc

// duplicated attribute demo

using System;
using System.ComponentModel;

class Program {
static void Main() {
TestClass obj = new TestClass();
Console.WriteLine("Component model");
foreach (Attribute attrib in
TypeDescriptor.GetProperties(obj)["TestProperty"].Attributes) {
Console.WriteLine(attrib.GetType().Name + ": " +
attrib.ToString());
}
Console.WriteLine();
Console.WriteLine("Reflection [no inherit]");
foreach (Attribute attrib in
obj.GetType().GetProperty("TestProperty").GetCusto mAttributes(false)) {
Console.WriteLine(attrib.GetType().Name + ": " +
attrib.ToString());
}
Console.WriteLine();
Console.WriteLine("Reflection [with inherit]");
foreach (Attribute attrib in
obj.GetType().GetProperty("TestProperty").GetCusto mAttributes(true)) {
Console.WriteLine(attrib.GetType().Name + ": " +
attrib.ToString());
}
}
}
[ImmutableObject(true), AttributeUsage(AttributeTargets.Property,
AllowMultiple = true)]
public class TestAttribute : Attribute {
private readonly string _value;
public string Value { get { return _value; } }
public override string ToString() {
return Value;
}
public TestAttribute(string value) {
_value = value;
}
}
public class TestClass {
[Test("abc")]
[Test("def")]
public string TestProperty { get { return "Fred"; } }
}
Nov 7 '06 #1
2 3420
In article <#p**************@TK2MSFTNGP02.phx.gbl>,
Marc Gravell <ma**********@gmail.comwrote:

: [...]
:
: http://www.govtalk.gov.uk/gdsc/html/noframes
: /NationalInsuranceNumber-2-1-Release.htm

That page links to a schema[*] that provides the following pattern:

[A-CEGHJ-NOPR-TW-Z]{2}[0-9]{6}[ABCD\s]{1}
[*] http://www.govtalk.gov.uk/gdsc/schemas
/CitizenIdentificationTypes-v1-4.xsd

Yes, the trailing {1} is redundant, but it looks like a safe bet. :-)

Greg
--
Patriotism cannot be a love of government.
-- Robert LeFevre
Nov 9 '06 #2
Thanks anyway, but it doesn't fully meet the spec as stated, and is very
close to one of the pair of regex that I already posted.

I guess they couldn't brute-force it into a single regex either! Oh well, it
isn't always possible...

Of course, if somebody could explain the component-model / reflection
disparity that would be good too ;-p

Marc
Nov 9 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Scott Sauyet | last post by:
Hi folks, I'm new to this neighborhood. If my question should be posed elsewhere, I would appreciate a pointer as to where. Thanks. It took me a while to chase down what the Crimson parser...
15
by: F. Da Costa | last post by:
Hi all, Following two sniperts of code I'm using and getting very interesting results from. ..html <tr id="1" class="segment" open="false"> This is the segment under 'investigation' ..js
3
by: Nick | last post by:
My client uses a SQL Database to store their usernames and passwords, and I do not believe they have AD...no big deal... I wrote a class to create a generic identity and generic principal so that...
1
by: M | last post by:
Is it possible to define an attribute that describes a property of a class at runtime? For example, you have a class called "employee", and it has a property "name". The "name" property has an...
5
by: Martin | last post by:
Hi All, I'm trying to get at the data in a variable marked with my custom attribute. I'm not entirely sure where to begin. I've created my attribute class which is okay but at runtime I want to...
55
by: Steven Nagy | last post by:
Hi all, Sorry I have no time to test this myself.... Can I add the same attribute to a field twice? Eg. Public string myField;
1
by: Andreas Mueller | last post by:
Hi all, I have an attribute class: class MyAttribute : Attribute { public MyAttribute(){ } }
4
by: Tugrul HELVACI | last post by:
Changing DisplayNames of my properties using PropertyGrid component, how ?? I'm using Delphi 2006 and I have a class defination like this: TPerson = class fPersonName : String;...
1
by: =?Utf-8?B?d2luZHNpbQ==?= | last post by:
Hi, I have a custom attribute targing Property: public class StatefulPropertyAttribute : Attribute{} and all the properties marked with will be handled by public...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.