|
Interfaces can't be extended because they are a very specific contract, and they contain no base material to override - they cannot define any concrete code at all, they just provide a set of signatures (methods, properties, events) which the implementing class is obliged to create in a concrete form as it's part of the contract.
They can't contain any implementation themselves, because that would make them abstract classes and provide a route to multiple inheritance which C# is absolutely not happy with - because it seriously complicates the source code.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I don't know why some people here post some abusive words and make me feel bad. I don't want to look at that replies.
I am seeing only good people replies.
Thank You so much Griff Sir. It is the only reason i am following to you because you better than better expert on code project.
|
|
|
|
|
|
He won't reply to you as you did not spoon feed him an answer, like sir Griff did. You expect him to go and do some research.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Ah well, once a help vampire always a help vampire.
|
|
|
|
|
Wow he disappeared quickly, I wonder if he jumped or was pushed.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
|
Ah thats funny, so he jumped AGAIN.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
StringBuilder strUserGroups = new StringBuilder();
foreach (IdentityReference userGroup in WindowsIdentity.GetCurrent().Groups) {
try { strUserGroups.AppendLine(userGroup.Translate(typeof(NTAccount)).Value); }
catch (Exception) { }
}
textBox1.Text = strUserGroups.ToString().Trim();
strUserGroups = null;
Output from program that's not been elevated
Quote: Everyone
BUILTIN\Performance Log Users
BUILTIN\Users
NT AUTHORITY\INTERACTIVE
CONSOLE LOGON
NT AUTHORITY\Authenticated Users
NT AUTHORITY\This Organization
MicrosoftAccount\hidden
NT AUTHORITY\Local account
LOCAL
NT AUTHORITY\Cloud Account Authentication
Output from program running as an elevated program
Quote: Everyone
NT AUTHORITY\Local account and member of Administrators group
BUILTIN\Administrators
BUILTIN\Performance Log Users
BUILTIN\Users
NT AUTHORITY\INTERACTIVE
CONSOLE LOGON
NT AUTHORITY\Authenticated Users
NT AUTHORITY\This Organization
MicrosoftAccount\hidden
NT AUTHORITY\Local account
LOCAL
NT AUTHORITY\Cloud Account Authentication
Note the two items I made bold in the above text block, they aren't there in the first one. Why? My user is part of the Administrator's user group. It seems that those two user groups only show up when the program is elevated. Why is that?
Tom Parkison
|
|
|
|
|
Security reasons.
Would you want some normal user being able to get all the group memberships for any ID in the system?
I would want that information kept private so I don't have hackers going after certain accounts.
|
|
|
|
|
Then how would you be able to determine if a user can elevate a program cleanly without having to use a secondary account to elevate it? And by that I mean, users who are "administrators" can elevate a program just fine but a "standard user" has to input the password of an "administrator" to elevate the program.
Tom Parkison
|
|
|
|
|
There is nothing in your code you can do to determine this before it's launched.
Either the user has the permissions to launch the app with appropriate priv's, be it Run As..., or a UAC admin context switch, or just straight admin account, you can't determine what is going to be required ahead of time.
|
|
|
|
|
You might be able to test for this using the "deny only SID" claim:
public static bool IsAdministrator(this WindowsIdentity identity)
{
if (identity == null) throw new ArgumentNullException(nameof(identity));
WindowsPrincipal principal = new WindowsPrincipal(identity);
if (principal.IsInRole(WindowsBuiltInRole.Administrator)) return true;
return identity.FindAll(ClaimTypes.DenyOnlySid).Any(c => c.Value == "S-1-5-114");
}
S-1-5-114
Local account and member of Administrators group
You can use this SID when restricting network logon to local accounts instead of "administrator" or equivalent. This SID can be effective in blocking network logon for local users and groups by account type regardless of what they are actually named.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
That worked perfectly. Thank you
Tom Parkison
|
|
|
|
|
i want user to prevent write minus (-) with right number on textbox
|
|
|
|
|
|
You also might want to look at the NumericUpDown control if you are trying to manage a numeric value. You can set the minimum value to zero and the data type must be numeric so characters are invalid.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I want to create a class that has an optional property. I don't want to create a subclass
Example
public class MyClass
{
public MyClass( int extraPoperty)
{
// Something like this
public int ExtraPoperty { get; set; }
}
public int EntityId { get; set; }
}
Is this possible ?
|
|
|
|
|
No - you can't define a property within a method or constructor, only within the class body.
What exactly are you trying to do? Why do you think you need this?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
An optional property is the same as any other property; the optional bit depends on how you use it. Maybe you should consider a nullable type[^].
|
|
|
|
|
I would suggest that what you are asking about is going to violate the S in SOLID.
This space for rent
|
|
|
|
|
It depends on what you mean with "optional Property".
Do you mean something like this :
You have a Property "BorderStyle" and a Property "BorderSize".
If you select BoderStyle = None then you want that BorderSize isn't to be seen (invisible).
|
|
|
|
|
Check out the "ExpandoObject".
ExpandoObject Class (System.Dynamic)
(Always makes me think of "Plastic Man" for some reason).
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
5
|
|
|
|
|
I would add the optional property in an Interface. Then you inherit the Interface you want to apply optional methods or properties.
For example;
public interface IExtraProperty
{
public int ExtraPoperty { get; set; }
}
public class MyClass : IExtraProperty
Ben Scharbach
Temporalwars.Com
YouTube:Ben Scharbach
|
|
|
|