Hinweis: Dieser Artikel wurde ursprünglich veröffentlicht in 2011. Einige Schritte, Befehle oder Softwareversionen haben sich möglicherweise geändert. Überprüfen Sie die aktuelle Dokumentation von .Net für die neuesten Informationen.

Voraussetzungen

Bevor Sie beginnen, stellen Sie sicher, dass Sie Folgendes haben:

  • Visual Studio or .NET CLI installed
  • .NET Framework or .NET Core SDK
  • Basic C# programming knowledge

Recently I came across the need to convert a string stored in the database into an enumeration in our application. I wasn’t really excited about having to write a switch statement nor having to maintain that code. Fortunately there is a command in .Net that allows you to parse that string into any enumeration which is a great help! Below is a sample of how to use Enum.Parse():

///

/// This procedure generates the Permissions Mask necessary so that the correct permissions are applied by combining all the Masks that belong to a Sicherheit Permission Level

///

/// The Permission level for which the mask needs to be calculated

///

private static Microsoft.SharePoint.SPBasePermissions GeneratePermissionMask(Sicherheit___Permission_Levels permissionLevel)

{

Microsoft.SharePoint.SPBasePermissions permissionMask = Microsoft.SharePoint.SPBasePermissions.EmptyMask;

Type SPBasePermissionType = typeof(Microsoft.SharePoint.SPBasePermissions);

foreach (Model.Sicherheit___Permissions_definition individualPermissionValue in permissionLevel.Sicherheit___Permissions_definition)

{

permissionMask |= (Microsoft.SharePoint.SPBasePermissions)Enum.Parse(SPBasePermissionType, individualPermissionValue.Sicherheit_Mask, true);

}

return (Microsoft.SharePoint.SPBasePermissions)permissionLevel.Permissions;

}

Zusammenfassung

Verwandte Artikel