|
Hi,
I have implemented a custom membership provider. I have a class called ProviderUtility. In this class I have a method called EncodePassword.
I want to use the EncryptPassword method, but when I type MembershipProvider. then the method does not appear. Can someone please explain how do I use this method? I did use using System.Web.Security; at the top of my class.
Regards
ma se
|
|
|
|
|
Do you mean that you've written a class derived from MembershipProvider ? In your own instance methods, you should simply call EncryptPassword , without qualifying it with the MembershipProvider name (which indicates use of a static method). Optionally, to indicate that you're calling a method in a base class, you qualify it with base . This is required if your class overrides the base class method if you want the base class method to be called rather than your own.
Otherwise, EncryptPassword is a protected instance method, so it can only be called by instance methods of MembershipProvider and instance methods of classes derived from MembershipProvider . Since you cannot call it from other locations, IntelliSense does not show it in the list of available methods. If you type the name of a class followed by a dot, IntelliSense shows you a list of all public , static fields, methods, events and properties of that class (and internal static ones if the code you're working on is a member of the same assembly).
|
|
|
|
|
hai,what is the main difference between "methods" and "get" "set" properties? In properties we can assign and return values , but the same thing is possible in methods also and even calling the properties and methods is also similar.my question is why we go for properties??
thank u
dot net !!! definetely a revolution
|
|
|
|
|
Hi,
you dont need properties, but they make things easier and more readable.
which statement do you prefer:
myForm.Width+=100;
myForm.SetWidth(myForm.GetWidth()+100);
|
|
|
|
|
- Some features of C# rely on properties: i.e. design support and heavy use of attributes
- Properties are inlined (if I'm not mistaken)
- property link a set and get "method" together.
- properties are used i.e. in xml serialization (properties are serialized by default, fields not (and methods of course, too))
- I think it makes code more readable then properties stand for the state of an object where as methods stand for actions on this state.
-^-^-^-^-^-
no risk no funk
|
|
|
|
|
Urs Enzler wrote: - Properties are inlined (if I'm not mistaken)
The IL generates get_ and set_ methods
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Urs Enzler wrote: Properties are inlined (if I'm not mistaken)
The JIT may choose to inline any method that's short enough. If a property setter or getter method is particularly long, it probably won't be inlined - the fact that it's a property is irrelevant.
The CLR doesn't really 'understand' properties or events - the compiler is responsible for compiling a call to the correct underlying functions. In C# they're always called set_Property , get_Property and add_Event , remove_Event respectively (for a property called Property and an event named Event ). The metadata links them into a single property or event. An standard event written in C# also has a field of the appropriate delegate type which is invisible to the user. It's possible to write an event which has custom add and remove methods; Windows Forms does this, making use of a list so that for example Control (which has 69 events in .NET 2.0) does not need to have 69 delegate fields unnecessarily bloating the memory footprint of each object. The feature is so useful that the implementation mostly lives in System.ComponentModel.Component 's Events property.
|
|
|
|
|
Properties and methods are semantically different.
The normal behaviour of a property is that it represents a single value in the object. Getting the value should not change the state of the object. Setting the value should not change the state of the object in any other way than is reasonable to expect for the change of that property.
A method on the other hand may take any form, contain a simple or complex process, and change the state of the object in any way.
---
single minded; short sighted; long gone;
|
|
|
|
|
Hello,
I am writing an interface and its implementation in C#. I want some events to be defined in implementation.
I want to know how to declare events in Interface???
for example the event defined in Implementation is
public delegate void OperatorBtInsertHandler();
public event OperatorBtInsertHandler OperatorBtInsertClicked;
public void OperatorBtinserted(string strAddress)
{
}
what i need to write in interface????
Gajesh
|
|
|
|
|
Hi!
event OperatorBtInsertHandler OperatorBtInsertClicked; will do.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
Hi,
I'm making a hotkey app and don't know how to know which hotkey has been pressed. Here's the relevant part of my source:
My hotkey class
class Hotkey : IMessageFilter
{
[DllImport("user32.dll", SetLastError = true)]
private static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vlc);
[DllImport("user32.dll", SetLastError = true)]
private static extern bool UnregisterHotKey(IntPtr hWnd, int id);
private const int WMHotkey = 0x0312;
#region Properties
private IntPtr _Handle;
public IntPtr Handle
{
get { return _Handle; }
set { _Handle = value; }
}
private int _Key;
public int Key
{
get { return _Key; }
set
{
UnregisterHotkey();
try
{
RegisterHotKey(value, _Mod);
}
catch (Exception e)
{
MessageBox.Show("Could not register Hotkey - there is probably a conflict. " + "/br " + e.ToString(), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
_Key = value;
}
}
private byte _Mod;
public byte Mod
{
get { return _Mod; }
set
{
UnregisterHotkey();
try
{
RegisterHotKey(Key, value);
}
catch (Exception e)
{
MessageBox.Show("Could not register Hotkey - there is probably a conflict. " + "/br " + e.ToString(), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
_Mod = value;
}
}
private bool _isPressed;
public bool isPressed
{
get { return _isPressed; }
set { _isPressed = value; }
}
#endregion
private event EventHandler HotkeyPressed;
public Hotkey(Keys key, byte modifier, EventHandler hotKeyPressed)
{
if (key != Keys.None)
{
HotkeyPressed = hotKeyPressed;
try
{
RegisterHotKey(CharCodeFromKeys(key), modifier);
}
catch (Exception e)
{
MessageBox.Show("Could not register Hotkey " + key.ToString() + " - there is probably a conflict. " + "/br " + e.ToString(), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
Application.AddMessageFilter(this);
}
}
public Hotkey(Keys key, Keys modifier, EventHandler hotKeyPressed)
{
if (key != Keys.None)
{
HotkeyPressed = hotKeyPressed;
try
{
RegisterHotKey(CharCodeFromKeys(key), ModifiersFromKeys(modifier));
}
catch (Exception e)
{
MessageBox.Show("Could not register Hotkey " + key.ToString() + " - there is probably a conflict. " + "/br " + e.ToString(), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
Application.AddMessageFilter(this);
}
}
public static byte CharCodeFromKeys(Keys k)
{
byte charCode = 0;
if ((k.ToString().Length == 1) || ((k.ToString().Length > 2) && (k.ToString()[1] == ',')))
charCode = (byte)k.ToString()[0];
else if ((k.ToString().Length > 3) && (k.ToString()[0] == 'D') && (k.ToString()[2] == ','))
charCode = (byte)k.ToString()[1];
return charCode;
}
private const byte ModAlt = 1, ModControl = 2, ModShift = 4, ModWin = 8;
public static byte ModifiersFromKeys(Keys k)
{
byte total = 0;
if (((int)k & (int)Keys.Shift) == (int)Keys.Shift)
total += ModShift;
if (((int)k & (int)Keys.Control) == (int)Keys.Control)
total += ModControl;
if (((int)k & (int)Keys.Alt) == (int)Keys.Alt)
total += ModAlt;
if (((int)k & (int)Keys.LWin) == (int)Keys.LWin)
total += ModWin;
return total;
}
~Hotkey()
{
Application.RemoveMessageFilter(this);
UnregisterHotKey(this._Handle, this.GetType().GetHashCode());
}
public void UnregisterHotkey()
{
Application.RemoveMessageFilter(this);
UnregisterHotKey(this._Handle, this.GetType().GetHashCode());
}
private void RegisterHotKey(int key, int modifier)
{
bool isKeyRegisterd = RegisterHotKey(this._Handle, this.GetType().GetHashCode(), modifier, key);
if (!isKeyRegisterd)
throw new ApplicationException("Hotkey already in use");
}
public bool PreFilterMessage(ref Message m)
{
switch (m.Msg)
{
case WMHotkey:
{
if ((int)m.LParam != 1114112)
{
isPressed = true;
HotkeyPressed(this, new EventArgs());
return true;
}
else
return false;
}
}
return false;
}
}
The class works fine for 1 hotkey but when I try and implement multiple instances of the class I can't tell which hotkey is pressed. For example:
<br />
Hotkeys[0] = new Hotkey(Properties.Settings.Default.Play, Properties.Settings.Default.PlayMod, OnHotkeyPressed);
Hotkeys[1] = new Hotkey(Properties.Settings.Default.Next, Properties.Settings.Default.NextMod, OnHotkeyPressed);
When I check the isPressed properties the Hotkeys[0](Play hotkey) isPressed property is always true and the Hotkeys[1] is always false(next hokey) even when that hotkey is pressed.
Also another problem I have is that I can only create a hotkey for the letters on the keyboard(keys A-Z) but not PageDown, the F1-F2 keys, the Arrow keys. Does anyone know a work around for this?
Can anyone help me with these problems
Thanks a lot
Luke Dyer
|
|
|
|
|
Hi,
the id parameter in RegisterHotkey must be unique (your _Mod is not good); it is used
internally to discriminate the different hotkeys; I once used the following code:
int chr=(int)name[0];
if (chr>=(int)'a' && chr<=(int)'z') chr+=(int)'A'-(int)'a';
int ident=GetType().GetHashCode()+(modifiers<<16)+chr;
but that is just one attempt to get unique numbers for some command based on its
name (some textual description) and the modifier keys (similar to Control.ModifierKeys)
all inside a form.
|
|
|
|
|
Hi
I am using Visual Studio 2005 and C# to develop a Windows application. I am trying to trigger a keypress or keydown event on the form.
When there are no other controls on the form it works well. Testing with the following:
private void Form1_KeyDown(object sender, KeyEventArgs e)<br />
{<br />
if (e.KeyCode == Keys.C)<br />
{<br />
<br />
}<br />
}
The moment I add another control onto the form, for example a Button, the KeyDown event does not fire anymore.
What am I missing here?
Thanks.
Kobus
|
|
|
|
|
Hi,
part of the GUI job is to dispatch events to the appropriate Control.
If you want your Form to also get keyboard events even when one of its Controls has focus,
look at Form.KeyPreview property.
|
|
|
|
|
Hi!
Is there a way to check a string in all the variations that it can be, i mean that if i will set a string:
string temp_s = "This is the one";
and i will search for "this" and "thiS" then i will get true.
is there a way to configure the string object to do so??
Thanks for your help
|
|
|
|
|
If you are concerned about case, you should change both things you are check to be a certain case. So your code:
temp_s.ToLower() = "this is the one" should always match no matter what the begining case of temp_s is.
Hope that helps.
Ben
|
|
|
|
|
Hi,
as Kubben said, or use String.Compare (String, String, Boolean)
which internally does the same, hence costs more if you must compare one string variable
against several string literals.
|
|
|
|
|
Rotation
Smile: A curve that can set a lot of things straight!
(\ /)
(O.o)
(><)
|
|
|
|
|
You forgot to ask a question.
---
single minded; short sighted; long gone;
|
|
|
|
|
Hi Guffa I posted the Rotation matrix link of which I wanted to use to rotate a rectangle drawn using the graphics abstract class and wanted to implement that in C# but I dont have a clue how to do it
Smile: A curve that can set a lot of things straight!
(\ /)
(O.o)
(><)
|
|
|
|
|
Hi,
all this inside a Form:
declare class members "float angle=0.0f", "int w=300" and "int h=300";
put a Control (say Panel) with size=new Size(2*w, 2*h);
wire a Paint handler for it, which includes:
Graphics g=e.Graphics;
g.TranslateTransform(w,h);
g.RotateTransform(angle);
... now draw whatever you like in the x-range (-w,+w) and y-range (-h,+h)
now add a Forms.Timer that takes care of animantion; in its Tick handler vary angle,
e.g. angle+=10.0f; // add 10 degrees
[Edit: dont forget to also invalidate the panel]
That's all.
-- modified at 5:57 Wednesday 18th July, 2007
|
|
|
|
|
Thanks Luc, I should give it a try tonight, sorry for the late replay as I'm out of my town lately.. Thanks again my friend
Smile: A curve that can set a lot of things straight!
(\ /)
(O.o)
(><)
|
|
|
|
|
Hi
What is the possibility to Build my C# Windows application by using another C# application. If so how to do it,
http://www.codeproject.com/csharp/cscompiler.asp[^]
This one says how to comiple few lines of code, the same way i have to excute and create EXE for whole application, by setting up path.
Thanks
|
|
|
|
|
Hello everyone,
I am a developer from C++ COM to C# COM. I feel confused about the entry point function for a C# COM object.
In C++, we always initialize object through GetClassObject or DLLGetClassObject, but it seems C# does not need these functions?
Here is a sample from MSDN.
http://msdn2.microsoft.com/en-us/library/aa645738(VS.71).aspx
So, in C# do we need to implement the required functions like GetClassObject? If no need, which function is the entry point for C# COM object -- I want to find the entry point function so that I can verify that my C# COM object can begin to talk with other COM clients.
thanks in advance,
George
|
|
|
|
|
The framework implements the class factory object itself, inside the COM Callable Wrapper. It also implements DllGetClassObject itself. In fact, if you look at the registry for your object, you will see that your DLL isn't actually recorded in the InprocServer32 key; instead, mscoree.dll is registered. To run your object, COM runs mscoree.dll 's DllGetClassObject function, which in turn loads the appropriate version of the CLR (the highest installed that is listed in supportedRuntime elements in the application's .exe.config file, if present, or if none are present, the highest version installed), then uses the Assembly and Class registry values (with the assistance of Codebase , if present) to locate the assembly containing your class and the appropriate class to load.
If you want to influence construction, you can do so only using the class's static constructor or instance constructor.
Be aware that all public classes with no constructors, or a constructor that takes no arguments, are registered when you use the regasm tool, except where marked [ComVisible(false)] . Consider using the ComVisible attribute at assembly level to hide all types except those you explicitly mark as being visible.
|
|
|
|
|