Explicit interface implementation and Reflection.Emit - reflection.emit

Does anybody know how to implement an interface's property explicitly
using Reflection.Emit?

See the MSDN documentation for TypeBuilder.DefineMethodOverride, which includes an example of using Reflection.Emit to generate an explicit interface implementation using that method.

This Reflector Addin should help you. It translates the IL code of a given method into the C# code that would be needed to generate the same IL code using System.Reflection.Emit.

Related

Using CSOM in VBS [duplicate]

I've compiled C# code into a DLL, but have little experience with them. My C# code contains a class HelloWorld with a static method Print(). I'd like to use this DLL in VBScript to call the method Print(). I know this is base, but I'm using this as a test for a larger scale project that will be compiled to DLL in the end. What's the declare look like for that and how would the method call look?
Important: Both methods will work only if the DLL exposes a COM interface.
If your dll is registered with the system, use CreateObject with it's ProgID.
Set myObject = CreateObject("MyReallyCoolObject.HelloWorld")
myObject.Print
If your object is not registered on the system, use GetObject with a path to the file containing your object. Make sure your object exposes the proper interface. (The second parameter is optional. Here you can provide a class name if your object exposes more than one.)
Set myObject = GetObject("C:\some\path\helloworld.dll", "appname.HelloWorld")
myObject.Print
I think you might be looking for Registration-Free COM. This SO answer regarding the Microsoft.Windows.ActCtx should help specifically for VBScript.
Keep in mind that COM doesn't support static methods, so you'll have to make your Print method into an instance method.
How to call a .NET DLL from a VBScript

What is the proper way of resetting a password?

Until today, I used UserManager's GeneratePasswordResetTokenAsync method to generate tokens. AFAIK, it is implemented by ASP.NET Identity.
But, I just found out about UserManager's SetNewPasswordResetCode method implemented by ABP.
I understand the differences between both. Why didn't ABP reimplement or use Identity's methods?
Also, which should I use?
Thanks in advance.
They are same. The reason why the ABP has duplicate this functionality is, at some time we needed to implement IUserTokenStore that's why reimplemented that method.
You can use ABP's method.

Sample Code for Creating Custom Membership Provider

I am writing an MVC 3 application and I am trying to implement my own custom membership provider (following the sample in Apress' Pro ASP.NET MVC 3 Framework).
I created my custom class, inherited from MembershipProvider and (using ReSharper) implemented all 27 of the methods with NotImplementedExceptions.
Now, I have overridden the ValidateUser method as the book states and it works fine, but I would like to make my provider more robust and implement the other methods (e.g. set MinRequiredPasswordLength and GetNumberOfUsersOnline).
Is there some sample code that I can use to start populating these methods that I can tweak to fit my own DB/Model schema?
I can certainly use trial and error to figure it out, but a base code sample would greatly help.
EDIT:
This question was just downvoted twice. If you are going to downvote, please post a comment as to why so that I can work on improving my questions.
EDIT 2:
For example, for the following method:
public override int GetNumberOfUsersOnline()
{
throw new System.NotImplementedException();
}
I can try to write code from scratch to look at some web log, determine the users login time and approximate if they are still on, but that will take a large amount of time for me to figure out. Since all this code is from the same interface that Microsoft wrote for the standard SqlMembershipProvider, isn't there code out there (even from MS) that contains this method? If so, I want take it, modify it so it uses my DB schema instead of the aspnetdb default schema. I would prefer to have some sort of base code to work from. I thought this would be a simple and fairly standard request, but perhaps not.
You can't use the default provider's code for your custom provider, that is why you are implementing a custom one, to tweak it according to your requirements, use your own db tables etc.
Take a look at my blog posts about custom membership, custom role providers and custom membership user. There is an example there of how you can use your own database to get/set membership information.
Here's a of sample implementation of custom MembershipProvider on MSDN.
http://msdn.microsoft.com/en-us/library/6tc47t75.aspx

Disable Images, ActiveX Etc in VB6 WebBrowser control using DLCTL_NO_

Like the title says, i want to disable images, and ActiveX Controls in the vb6 webbrowser control using DLCTL_NO_RUNACTIVEXCTLS and DLCTL_NO_DLACTIVEXCTLS
Microsoft talk about it here: http://msdn.microsoft.com/en-us/library/aa741313.aspx
But i dont see any way to access IDispatch::Invoke from the vb6 application.
Any help would be greatly appreciated.
I do not think VB6 let you to add the ambient properties. Try host the ActiveX in another container (e.g. an ActiveX host written by yourself - but I do not know how much time you want to invest to declare VB-friendly OLE interfaces and implement them - or use another ActiveX like the one at http://www.codeproject.com/KB/atl/vbmhwb.aspx instead.
You don't access IDispatch::Invoke in VB6, you just write you method and IDispatch is automagically implemented.
Public Function DlControl() As Long
DlControl = DLCTL_NO_DLACTIVEXCTLS Or ...
End FUnction
Then just open Tools->Procedure Attributes and for DlControl function open Advanced and assign Procedure ID to -5512 (DISPID_AMBIENT_DLCONTROL). That's first part.
Second part is to set the client site to you custom implementation of IOleClientSite. You'll need a custom typelib, try Edanmo's OLELIB for declaration of these interfaces.
Here is a delphi sample how to hook your implementation of IOleClientSite. Apparently you'll alse have to call OnAmbientPropertyChange at some point.

How to invoke NdrClientCall2() function directly?

Does anybody know how the NdrClientCall2() function in rpcrt4.dll can be called in code or how it can be used?
We've gone through the MSDN help -
http://msdn.microsoft.com/en-us/library/aa374215(VS.85).aspx,
but didn't get any examples/samples how to use this function.
Please provide help.
Thank you.
Typically you don't ever call it directly - it requires a huge set of parameters prepared in a special barely-manageable way. Instead you use IDL to specify your RPC interface, compile it with MIDL and this gives you a client proxy that calls that function with proper parameters.
The easiest would be to use and idl-file and use midl.exe to generate the client RPC stub, which utilizes the NdrClientCall2 internally.
This is normally called via the RPC client MIDL code - why do you want to call this directly?

Resources