I am creating a class library and have different functions inside. I also have a Console application that can access this functions once they reference the class library. I would like to know how to make a function "invisible" so the client won't be able to see it exist and they can only use it if they write it out perfectly.
I have this function in my class Library :
public string custommessage(string messagetosend)
{
string receivedmessage = CallServer(messagetosend);
return receivedmessage;
}
and basicly when I am in a different program referencing the library I dont want to see this function in my list of avaiable functions to chose from :
Append
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
to your method as an attribute. This will hide the function from intellisense.
Related
I'm making an app and need to be able to check if settings like : Bluetooth/Phone Rotation/Flashlight/Plane Mode/GPS/Phone Brightness/Silent Mode, are activated on an android phone.
I haven't found any way to do it within Unity, using C#. I found ways to do it using Xamarin but none of them work with Unity (or maybe I haven't done it right), the only way I found is using Java and making it into a plugin and call it in a C# script. But I can't find a clear way to make this work. If this is the only solution could you please explain how to do it, all the documentation I find is from old versions from 2014.
I think there is a simple solution for this but I simply can't find it. And the manifest part is not a problem, I'll add the permissions needed.
In Java the methods you want to call should be public or static, you must build your java source as a library (in build.gradle: apply plugin: 'com.android.library'), and add the .aar to Unity's Assets/Plugins/Android/ folder.
Then you can instantiate your plugin in Unity like so:
// this class string is the package at the top of your Java class extended with the class name, e.g.:
// package com.yourcompany.you.package;
string classString = "com.yourcompany.you.package.className";
// Get the class
var tempAjc = new AndroidJavaClass(classString);
// Here you can call a static method on the class that returns an instance of the class if you want to pass some parameters upon creation
_androidObject = tempAjc.CallStatic<AndroidJavaObject>("CreateInstance",
new object[] {arg1, arg2});
// non static call on your new instance
_androidObject.Call("PassingMoreStuff", initParam);
// if you want to return something from Java to Unity:
int javaVal = _androidObject.Call<int>(methodName, parameters);
I'm trying to use a class on Access VBA 7.0 which implements an Interface I made and I'm still getting "Automation error" even after adding the usual headers.
DropBox.cs
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
[Guid("E2F07CD4-CE73-4102-B35D-119362624C47")]
[ComDefaultInterface(typeof(ICloudFileProvider))]
[ProgId("CloudFiles.dll")]
public class DropBox : ICloudFileProvider
{
public DropBox()
{
ConectaDropbox("TokenLongChicken");
}
public DropBox(string tokenUsuario)
{ //This was the original and good constructor. I know I can't use constructors with arguments on VBA. Just keeping it to compile with Test
ConectaDropbox(tokenUsuario);
}
public void ConectaDropbox(string tokenUsuario)
{
}
// This method and others come implemented from an interface (ICloudFileProvider)
public string SubirArchivo(string rutaLocal, string carpetaCloud, Tipos.TipoSobreescritura tipoSobreescritura)
{
}
This didn't work, so I saw I have to "create" a header for the Interface and I did it on the Interface itself. I'm still getting the error, so on the DropBox class, I added another header "enumerating" the methods I'm using on this class (which has no sense, but I've read another questions on SO which concretes you have to do so).
So I added this at the end of the DropBox class, noting it is as well on the ICloudFileProvider Interface (the real one).
[ComVisible(true)]
[Guid("E2F11CD4-CE73-4102-B35D-119362624C47")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IExposedClass
{
void DropBox();
void DropBox(string tokenUsuario);
void ConectaDropbox(string tokenUsuario);
string SubirArchivo(string rutaLocal, string carpetaCloud, Tipos.TipoSobreescritura tipoSobreescritura);
decimal ConvertBytesToMegabytes(long bytes);
void Descargar(string link, string carpetaLocal);
string GenerarLink(string rutaCloud);
void EliminarArchivo(string link);
}
I guess I'm doing something wrong but I'm kind of lost in this DLL and TLB hell. This project just works fine on C# but I need to integrate it on VBA and I see no examples with projects which uses real interfaces. I'm not really sure if the "InterfaceIsIUnkown" I add at the end of the DropBox class makes any sense, but I saw it on every example I found on the Internet (but none of them used a real Interface).
Could anybody help? Thanks.
P.S: yes, I perform the RegAsm.exe export to .TLB and then I add it to my Access, with no export errors apparently.
I have a class using UnityScript like this:
public class Responder{
private var completeHandler:Function;
public function addHandlers(completeHandler:Function):void {
completeHandler();
}
}
Now, i want to use this class in c# code,
public class MyGame : MonoBehaviour{
void Start(){
Responder res = new Responder();
res.addHandlers(?????); //how to pass the param??
}
}
Thanks!
Put the Javascript class in a folder called Plugins under assets. You will be able to call the methods written in JS from C# scripts.
The type Function in JS appears to me as Boo.Lang.ICallable in C#. As I couldn't import Boo.Lang by default, I took the Boo.Lang.dll from the Unity3D installed folder and copied it to the same Plugins folder in the project, then adding using Boo.Lang; at the top of my C# script.
You can now create and pass a new ICallable type as an argument from C# to JS.
I have to call C# managed class library in C++CLI which has the files with Wrapper.cpp and Wrapper.h.
My managed class library includes the code like:
namespace MyClassLbrary
{
public class MyImage
{
public void TestImage(DrawImage drawImage)
{
}
}
public class DrawImage
{
}
}
Next Step should be
I have to call this TestImage(DrawImage darwImage) method from C++CLI i.e.in Wrapper.cpp.
I have to write all the unmanaged code in my Wrapper.h file. related to this. but the problem is I have to declare this TestImage(DrawImage drawImage) in my Wrapper.h file which contains the object of my c# managed class .I am importing that C# class library in my C++CLI. Then how to call that method in my Wrapper.h file which contains only the things related to unmanaged code. Please let me know if you have any kind of generalized solution so that I can call my Methods like TestImage.
Use separate header files, and put your actual unmanaged code in .cpp files.
I have 2 completely independent projects one in vb and one in c#
Project A - VB
Project B - C#
We have scenario where by code in project A is currently using code in project B
e.g
Project A
Public Class SMS
Public Sub New()
End Sub
Public Function SendSMS() As String
Return "SMS Sent "
End Function
End Class
Project B
using ProjectA;
public class Email
{
public string SendEmail()
{
return "Email Sent ";
}
public string SendEmail(SMS sms)
{
sms.SendSMS();
return "Email Sent ";
}
}
This works fine However we now have a requirement to Send an Email from Project A which would create a circular reference After reading loads of help on here I created an interface and used the interface in project a as such:
Project C
Public Class Interface
Public Interface IEmail
Sub SendEmail()
End Interface
End Class
I have implemented the interface on Email and changed Project A to :
Public Function SendSMS(ByVal tEmail As IEmail) As String
tEmail.SendEmail()
Return "SMS Sent "
End Function
Which works fine from my ui as I can instantiate the object and all works fine.
However I have run into an issue where by I don’t want to instantiate the bject in the UI but instead in the Project A
Public Sub SendSMSAndEMail()
Dim temail As New email
Me.SendSMS(temail)
End Sub
I have hit a real road block? i think i should be looking at a factory class but i am getting confused as to how best to achieve this?
N.B Further info:
If we were to Design the system again project A and Project B would be in the same project (and Language) and this would not cause an issue. As it is we have 2 UI's A Console server app and a Win forms UI. Project B was originally for the console app and uses various functions that the main Win form app uses. It’s now arisen that there is code in the console app that we require from within the main app such as the ability to Send An E-mail however the code would be difficult to extract from the console app as it’s in a different language to the main application.
Evil solution: Static Factory Function
Declare this static class in your root project (example in interface project).
public static class EmailFactory{
public static Func<IEmail> Create{ get;set; }
}
Then in your UI (I assume that your Project will end up starting in UI), set it like:
EmailFactory.Create = new Func<IEmail>( () => { return new ProjectB.Email() } );
This way you can use it statically from Project A (even you still need to execute it from UI).
But forget it, you won't need it. Or at least, don't use it.
If you said that
The Current Sending process of SMS messages is Handled within Project A.
Does it means that Project A can be executed directly? I hope not. A library being executed is kind of evil for me. If you can, make the execution in separate project, and that project can reference to Project A and B as well. If so, then your interface approach is already fulfill the requirement.
EDIT:
Looks like the Project A or B itself is at UI level. It is a bad design to has library code inside UI project. However it will take months to refactor the whole application.
What I can suggest is to create a layer of library, which need to be used interactively between the project. So the architecture shall be:
infrastructure
|
|
library
/ \
/ \
[Project A] [Project B]
IMHO this is the only way to fix your problem.