Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ You can create your own custom attributes by defining an attribute class, a clas
public class AuthorAttribute : System.Attribute
{
private string Name;
public double Version;
public string Version;

public AuthorAttribute(string name)
{
Name = name;
Version = 1.0;
Version = "1.0";
}
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
public class AuthorAttribute : System.Attribute
{
string Name;
public double Version;
public string Version;

public AuthorAttribute(string name)
{
Name = name;

// Default value.
Version = 1.0;
Version = "1.0";
}

public string GetName() => Name;
Expand All @@ -39,7 +39,7 @@ public class SecondClass

// Class with multiple Author attributes.
// <MultipleAuthors>
[Author("P. Ackerman"), Author("R. Koch", Version = 2.0)]
[Author("P. Ackerman"), Author("R. Koch", Version = "2.0")]
public class ThirdClass
{
// ...
Expand Down Expand Up @@ -67,23 +67,23 @@ private static void PrintAuthorInfo(System.Type t)
{
if (attr is AuthorAttribute a)
{
System.Console.WriteLine($" {a.GetName()}, version {a.Version:f}");
System.Console.WriteLine($" {a.GetName()}, version {a.Version}");
}
}
}
}
/* Output:
Author information for FirstClass
P. Ackerman, version 1.00
P. Ackerman, version 1.0
Author information for SecondClass
Author information for ThirdClass
R. Koch, version 2.00
P. Ackerman, version 1.00
R. Koch, version 2.0
P. Ackerman, version 1.0
*/
// </DefineAndReadAttribute>

// <SampleWithVersion>
[Author("P. Ackerman", Version = 1.1)]
[Author("P. Ackerman", Version = "1.1")]
class SampleClass
{
// P. Ackerman's code goes here...
Expand Down