Skip to content

Normalize trailing spaces in samples, Part 2 #4126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 20, 2020
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
using System;
using System.Reflection;

namespace DefAttrCS
namespace DefAttrCS
{
// An enumeration of animals. Start at 1 (0 = uninitialized).
public enum Animal
public enum Animal
{
// Pets.
Dog = 1,
Expand All @@ -14,16 +14,16 @@ public enum Animal
}

// A custom attribute to allow a target to have a pet.
public class AnimalTypeAttribute : Attribute
public class AnimalTypeAttribute : Attribute
{
// The constructor is called when the attribute is set.
public AnimalTypeAttribute(Animal pet)
public AnimalTypeAttribute(Animal pet)
{
thePet = pet;
}

// Provide a default constructor and make Dog the default.
public AnimalTypeAttribute()
public AnimalTypeAttribute()
{
thePet = Animal.Dog;
}
Expand All @@ -32,14 +32,14 @@ public AnimalTypeAttribute()
protected Animal thePet;

// .. and show a copy to the outside world.
public Animal Pet
public Animal Pet
{
get { return thePet; }
set { thePet = Pet; }
}

// Override IsDefaultAttribute to return the correct response.
public override bool IsDefaultAttribute()
public override bool IsDefaultAttribute()
{
if (thePet == Animal.Dog)
return true;
Expand All @@ -48,30 +48,30 @@ public override bool IsDefaultAttribute()
}
}

public class TestClass
public class TestClass
{
// Use the default constructor.
[AnimalType]
public void Method1()
{}
}

class DemoClass
class DemoClass
{
static void Main(string[] args)
static void Main(string[] args)
{
// Get the class type to access its metadata.
Type clsType = typeof(TestClass);
// Get type information for the method.
MethodInfo mInfo = clsType.GetMethod("Method1");
// Get the AnimalType attribute for the method.
AnimalTypeAttribute atAttr =
AnimalTypeAttribute atAttr =
(AnimalTypeAttribute)Attribute.GetCustomAttribute(mInfo,
typeof(AnimalTypeAttribute));
// Check to see if the default attribute is applied.
Console.WriteLine("The attribute {0} for method {1} in class {2}",
atAttr.Pet, mInfo.Name, clsType.Name);
Console.WriteLine("{0} the default for the AnimalType attribute.",
atAttr.Pet, mInfo.Name, clsType.Name);
Console.WriteLine("{0} the default for the AnimalType attribute.",
atAttr.IsDefaultAttribute() ? "is" : "is not");
}
}
Expand Down
8 changes: 4 additions & 4 deletions samples/snippets/csharp/VS_Snippets_CLR/IsDefined/CS/id1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@ static void Main(string[] args)
// Store the assembly's name.
String assyName = assy.GetName().Name;
// See if the Assembly Description is defined.
bool isdef = Attribute.IsDefined(assy,
bool isdef = Attribute.IsDefined(assy,
typeof(AssemblyDescriptionAttribute));
if (isdef)
{
// Affirm that the attribute is defined.
Console.WriteLine("The AssemblyDescription attribute " +
"is defined for assembly {0}.", assyName);
// Get the description attribute itself.
AssemblyDescriptionAttribute adAttr =
AssemblyDescriptionAttribute adAttr =
(AssemblyDescriptionAttribute)Attribute.GetCustomAttribute(
assy, typeof(AssemblyDescriptionAttribute));
// Display the description.
if (adAttr != null)
Console.WriteLine("The description is \"{0}\".",
Console.WriteLine("The description is \"{0}\".",
adAttr.Description);
else
Console.WriteLine("The description could not " +
"be retrieved.");
"be retrieved.");
}
else
Console.WriteLine("The AssemblyDescription attribute is not " +
Expand Down
4 changes: 2 additions & 2 deletions samples/snippets/csharp/VS_Snippets_CLR/IsDefined/CS/id2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ static void Main(string[] args)
// Get the class type to access its metadata.
Type clsType = typeof(DemoClass);
// See if the Debuggable attribute is defined for this module.
bool isDef = Attribute.IsDefined(clsType.Module,
bool isDef = Attribute.IsDefined(clsType.Module,
typeof(DebuggableAttribute));
// Display the result.
Console.WriteLine("The Debuggable attribute {0} " +
Expand All @@ -25,7 +25,7 @@ static void Main(string[] args)
{
// Retrieve the attribute itself.
DebuggableAttribute dbgAttr = (DebuggableAttribute)
Attribute.GetCustomAttribute(clsType.Module,
Attribute.GetCustomAttribute(clsType.Module,
typeof(DebuggableAttribute));
if (dbgAttr != null)
{
Expand Down
16 changes: 8 additions & 8 deletions samples/snippets/csharp/VS_Snippets_CLR/IsDefined/CS/id3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
using System.Reflection;
using System.Runtime.InteropServices;

namespace IsDef3CS
namespace IsDef3CS
{
// Assign a Guid attribute to a class.
[Guid("BF235B41-52D1-46cc-9C55-046793DB363F")]
public class TestClass
public class TestClass
{
}

public class DemoClass
public class DemoClass
{
static void Main(string[] args)
static void Main(string[] args)
{
// Get the class type to access its metadata.
Type clsType = typeof(TestClass);
Expand All @@ -23,15 +23,15 @@ static void Main(string[] args)
Console.WriteLine("The Guid attribute {0} defined for class {1}.",
isDef ? "is" : "is not", clsType.Name);
// If it's defined, display the GUID.
if (isDef)
if (isDef)
{
GuidAttribute guidAttr =
(GuidAttribute)Attribute.GetCustomAttribute(clsType,
GuidAttribute guidAttr =
(GuidAttribute)Attribute.GetCustomAttribute(clsType,
typeof(GuidAttribute));
if (guidAttr != null)
Console.WriteLine("GUID: {" + guidAttr.Value + "}.");
else
Console.WriteLine("The Guid attribute could " +
Console.WriteLine("The Guid attribute could " +
"not be retrieved.");
}
}
Expand Down
14 changes: 7 additions & 7 deletions samples/snippets/csharp/VS_Snippets_CLR/IsDefined/CS/id4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
using System;
using System.Reflection;

namespace IsDef4CS
namespace IsDef4CS
{
public class TestClass
public class TestClass
{
// Assign the Obsolete attribute to a method.
[Obsolete("This method is obsolete. Use Method2 instead.")]
Expand All @@ -14,9 +14,9 @@ public void Method2()
{}
}

public class DemoClass
public class DemoClass
{
static void Main(string[] args)
static void Main(string[] args)
{
// Get the class type to access its metadata.
Type clsType = typeof(TestClass);
Expand All @@ -28,10 +28,10 @@ static void Main(string[] args)
Console.WriteLine("The Obsolete Attribute {0} defined for {1} of class {2}.",
isDef ? "is" : "is not", mInfo.Name, clsType.Name);
// If it's defined, display the attribute's message.
if (isDef)
if (isDef)
{
ObsoleteAttribute obsAttr =
(ObsoleteAttribute)Attribute.GetCustomAttribute(
ObsoleteAttribute obsAttr =
(ObsoleteAttribute)Attribute.GetCustomAttribute(
mInfo, typeof(ObsoleteAttribute));
if (obsAttr != null)
Console.WriteLine("The message is: \"{0}\".",
Expand Down
14 changes: 7 additions & 7 deletions samples/snippets/csharp/VS_Snippets_CLR/IsDefined/CS/id5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,35 @@
using System;
using System.Reflection;

namespace IsDef5CS
namespace IsDef5CS
{
public class TestClass
public class TestClass
{
// Assign a ParamArray attribute to the parameter using the keyword.
public void Method1(params String[] args)
{}
}

public class DemoClass
public class DemoClass
{
static void Main(string[] args)
static void Main(string[] args)
{
// Get the class type to access its metadata.
Type clsType = typeof(TestClass);
// Get the MethodInfo object for Method1.
MethodInfo mInfo = clsType.GetMethod("Method1");
// Get the ParameterInfo array for the method parameters.
ParameterInfo[] pInfo = mInfo.GetParameters();
if (pInfo != null)
if (pInfo != null)
{
// See if the ParamArray attribute is defined.
bool isDef = Attribute.IsDefined(pInfo[0],
bool isDef = Attribute.IsDefined(pInfo[0],
typeof(ParamArrayAttribute));
// Display the result.
Console.WriteLine("The ParamArray attribute {0} defined for " +
"parameter {1} of method {2}.",
isDef ? "is" : "is not",
pInfo[0].Name,
pInfo[0].Name,
mInfo.Name);
}
else
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
//Types:System.Security.Permissions.IsolatedStorageContainment (enum)
//Types:System.Security.Permissions.IsolatedStoragePermissionAttribute
//Types:System.Security.Permissions.SecurityAction
//Types:System.Security.Permissions.IsolatedStorageContainment (enum)
//Types:System.Security.Permissions.IsolatedStoragePermissionAttribute
//Types:System.Security.Permissions.SecurityAction
//<snippet1>
using System;
using System.Security.Permissions;
using System.IO.IsolatedStorage;
using System.IO;

// Notify the CLR to only grant IsolatedStorageFilePermission to called methods.
// This restricts the called methods to working only with storage files that are isolated
// Notify the CLR to only grant IsolatedStorageFilePermission to called methods.
// This restricts the called methods to working only with storage files that are isolated
// by user and assembly.
[IsolatedStorageFilePermission(SecurityAction.PermitOnly, UsageAllowed = IsolatedStorageContainment.AssemblyIsolationByUser)]
public sealed class App
Expand All @@ -20,7 +20,7 @@ static void Main()
private static void WriteIsolatedStorage()
{
// Attempt to create a storage file that is isolated by user and assembly.
// IsolatedStorageFilePermission granted to the attribute at the top of this file
// IsolatedStorageFilePermission granted to the attribute at the top of this file
// allows CLR to load this assembly and execution of this statement.
using (Stream s = new IsolatedStorageFileStream("AssemblyData", FileMode.Create, IsolatedStorageFile.GetUserStoreForAssembly()))
{
Expand Down
Loading