Skip to content

Commit 382cbf6

Browse files
committed
Add generated attributes
1 parent 2be727f commit 382cbf6

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

AttributeGenerator/Program.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ static void Main(string[] args)
4141
static HashSet<string> MethodNames()
4242
{
4343
HashSet<string> methodNames = new HashSet<string>();
44-
MethodInfo[] methods = typeof(Chance).GetMethods(BINDING_FLAGS);
44+
45+
IEnumerable<MethodInfo> methods = typeof(Chance).GetMethods(BINDING_FLAGS).Where(m => !m.IsSpecialName);
46+
4547
foreach (MethodInfo method in methods)
4648
{
4749
if (!EXCLUDE.Contains(method.Name))
@@ -55,7 +57,7 @@ static HashSet<string> MethodNames()
5557
static List<MethodInfo> MethodsWithName(string name)
5658
{
5759
List<MethodInfo> methods = new List<MethodInfo>();
58-
foreach (MethodInfo method in typeof(Chance).GetMethods(BINDING_FLAGS))
60+
foreach (MethodInfo method in typeof(Chance).GetMethods(BINDING_FLAGS).Where(m => !m.IsSpecialName))
5961
{
6062
if (method.Name == name)
6163
methods.Add(method);

Chance.NET/Attributes/Generated/GenderAttribute.Generated.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,18 @@ namespace ChanceNET.Attributes
1010
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
1111
public class GenderAttribute : ChanceAttribute
1212
{
13+
Double maleLikelihood = 0.5;
1314

1415

15-
public GenderAttribute()
16+
public GenderAttribute(Double maleLikelihood = 0.5)
1617
{
18+
this.maleLikelihood = maleLikelihood;
1719

1820
}
1921

2022
internal override object GetValue(Chance chance)
2123
{
22-
return chance.Gender();
24+
return chance.Gender(maleLikelihood);
2325
}
2426
}
2527
}

Chance.NET/Attributes/Generated/UrlAttribute.Generated.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ namespace ChanceNET.Attributes
1010
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
1111
public class UrlAttribute : ChanceAttribute
1212
{
13-
String protocol = null;
13+
String scheme = null;
1414
String domain = null;
1515
String path = null;
1616
String extension = null;
1717

1818

19-
public UrlAttribute(String protocol = "null", String domain = "null", String path = "null", String extension = "null")
19+
public UrlAttribute(String scheme = "null", String domain = "null", String path = "null", String extension = "null")
2020
{
21-
this.protocol = protocol;
21+
this.scheme = scheme;
2222
this.domain = domain;
2323
this.path = path;
2424
this.extension = extension;
@@ -27,7 +27,7 @@ public UrlAttribute(String protocol = "null", String domain = "null", String pat
2727

2828
internal override object GetValue(Chance chance)
2929
{
30-
return chance.Url(protocol, domain, path, extension);
30+
return chance.Url(scheme, domain, path, extension);
3131
}
3232
}
3333
}

0 commit comments

Comments
 (0)