Click here to Skip to main content
14,697,682 members
Home » Discussions » C#
   

C#

 
AnswerRe: How to launch a form only once Pin
OriginalGriff26-Oct-20 9:35
mveOriginalGriff26-Oct-20 9:35 
GeneralRe: How to launch a form only once Pin
Member 1479239326-Oct-20 11:09
MemberMember 1479239326-Oct-20 11:09 
GeneralRe: How to launch a form only once Pin
OriginalGriff26-Oct-20 22:15
mveOriginalGriff26-Oct-20 22:15 
GeneralRe: How to launch a form only once Pin
Member 1479239327-Oct-20 11:40
MemberMember 1479239327-Oct-20 11:40 
GeneralRe: How to launch a form only once Pin
OriginalGriff27-Oct-20 11:42
mveOriginalGriff27-Oct-20 11:42 
AnswerRe: How to launch a form only once Pin
Gerry Schmitz26-Oct-20 15:50
mveGerry Schmitz26-Oct-20 15:50 
AnswerRe: How to launch a form only once Pin
Richard Deeming26-Oct-20 23:10
mveRichard Deeming26-Oct-20 23:10 
QuestionDesign an elegant solution for choosing a class whose method gets called Pin
Member 1497555126-Oct-20 7:13
MemberMember 1497555126-Oct-20 7:13 
Hi all,

I would appreciate a hand in designing my code.

I have a number of classes for different entities (currently 7 but there can be more in the future). I need a method in each of these classes that authorizes user's access to a file resource. Implementation varies but an exception must be thrown if user does not have access to the file in question.

Problem is, when the file is being accessed, I need to call the authorization method of the correct class based on the data on the file. Files are stored in a db table and one of the fields in that table determines which entity the file is related to and how to find which user has access to the file.

So I must read the file data from db, then see which entity it's related to and then call the authorization method of the correct class.

Is there a way in C# to accomplish this without having to make a switch case structure on the file field value and initialize a class and call a method?


Example of the classes used:
public class FileAttachment
{
    // other FileAttachment class stuff 
	
    protected void AuthorizeFileAccess(FileAttachmentData file)
    {
        // file has a field which tells which entity it relates to
        // here I need to choose which class to use based on the file data
    }
}


// simplified example of related entity
public class ChatMessage
{
	public int SenderUserId;
	public int RecipientUserId;
	
	// here I need a method that checks that chat message sender's or recipient's
	// user id matches the user id of the logged in user
	// if not, throw exception
}

AnswerRe: Design an elegant solution for choosing a class whose method gets called Pin
Gerry Schmitz26-Oct-20 15:58
mveGerry Schmitz26-Oct-20 15:58 
Questionan apparent violation of C#-generic "physics" ? (language issue) Pin
BillWoodruff25-Oct-20 23:18
mveBillWoodruff25-Oct-20 23:18 
AnswerRe: an apparent violation of C#-generic "physics" ? (language issue) Pin
pkfox25-Oct-20 23:58
professionalpkfox25-Oct-20 23:58 
GeneralRe: an apparent violation of C#-generic "physics" ? (language issue) Pin
BillWoodruff26-Oct-20 0:15
mveBillWoodruff26-Oct-20 0:15 
GeneralRe: an apparent violation of C#-generic "physics" ? (language issue) Pin
pkfox26-Oct-20 0:59
professionalpkfox26-Oct-20 0:59 
GeneralRe: an apparent violation of C#-generic "physics" ? (language issue) Pin
BillWoodruff26-Oct-20 3:13
mveBillWoodruff26-Oct-20 3:13 
GeneralRe: an apparent violation of C#-generic "physics" ? (language issue) Pin
pkfox26-Oct-20 3:48
professionalpkfox26-Oct-20 3:48 
GeneralRe: an apparent violation of C#-generic "physics" ? (language issue) Pin
F-ES Sitecore26-Oct-20 2:15
mveF-ES Sitecore26-Oct-20 2:15 
GeneralRe: an apparent violation of C#-generic "physics" ? (language issue) Pin
BillWoodruff26-Oct-20 3:09
mveBillWoodruff26-Oct-20 3:09 
GeneralRe: an apparent violation of C#-generic "physics" ? (language issue) Pin
Richard MacCutchan26-Oct-20 3:38
mveRichard MacCutchan26-Oct-20 3:38 
GeneralRe: an apparent violation of C#-generic "physics" ? (language issue) Pin
F-ES Sitecore26-Oct-20 3:55
mveF-ES Sitecore26-Oct-20 3:55 
GeneralRe: an apparent violation of C#-generic "physics" ? (language issue) Pin
Richard Deeming26-Oct-20 3:34
mveRichard Deeming26-Oct-20 3:34 
GeneralRe: an apparent violation of C#-generic "physics" ? (language issue) Pin
BillWoodruff26-Oct-20 4:50
mveBillWoodruff26-Oct-20 4:50 
AnswerRe: an apparent violation of C#-generic "physics" ? (language issue) Pin
BillWoodruff27-Oct-20 0:59
mveBillWoodruff27-Oct-20 0:59 
GeneralRe: an apparent violation of C#-generic "physics" ? (language issue) Pin
harold aptroot27-Oct-20 1:45
Memberharold aptroot27-Oct-20 1:45 
GeneralRe: an apparent violation of C#-generic "physics" ? (language issue) Pin
BillWoodruff27-Oct-20 6:46
mveBillWoodruff27-Oct-20 6:46 
QuestionHow to allow numbers and special characters in a textBox in C#? Pin
Alex Dunlop25-Oct-20 6:51
MemberAlex Dunlop25-Oct-20 6:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.