I need to implement a RegExpInputFilter as an IInputFilter in Mono for Android but I do not understand how to do it. Is there some guidance on how to implement Java interfaces somewhere that explains this in detail? Or even better, has anyone written their own IInputFilter in Mono for Android that can share the code or just some tips?
IInputFilter is already part of the Mono for Android framework
It is part of the Android.Text namespace
http://androidapi.xamarin.com/?link=T:Android.Text.IInputFilter
class RegExInputFilter : Java.Lang.Object, IInputFilter
{
public Java.Lang.ICharSequence FilterFormatted(Java.Lang.ICharSequence source, int start, int end, ISpanned dest, int dstart, int dend)
{
//filter
}
}
Related
I am having hard time figuring out why I cannot see/use some methods from C# type in F# function.
public class KafkaBus : IKafkaBus
{
// this works and can be used
public IObservable<Shared.Model.Message<T>> CreateConsumer<T>(string topic, Func<byte[], T> deserialize = null)
// those cannot be found
public Task<Confluent.Kafka.CommittedOffsets> CommitAsync<T>(Message<T> message)
public Task<Confluent.Kafka.CommittedOffsets> CommitAsync(string topic, int partition, long offSet)
}
If I check object browser in F# solution under references, I see those methods listed:
I am using VS 2017 15.3, .NET Framework 4.6.1, library is referenced via nuget.
So in the end reopening project, rebuilding or simply restarting a machine helps the cause... Seems like a bug in Visual Studio. Got help on MSDN forums
can I invoke Java functions from Rascal. I want to write RASCAL analyser, but want access CFG nodes by calling a java function. Is this possible in Rascal. To put it simply, can I wrap the existing java application and invoke it from RASCAL
Sure. It works as follows.
Treat your Rascal project in Eclipse as a Java project as well.
Add source code and libraries and make the stuff compile.
Learn about the pdb.values API (in particular IValueFactory)
In Rascal write something like this:
#javaClass{com.mypackage.MyClass}
java int myFunction(str arg);
Then in Java:
package com.mypackage;
public class MyClass {
private final IValueFactor vf;
public MyClass(IValueFactory vf) {
this.vf = vf;
}
IValue myFunction(IString x) {
return vf.integer(-1);
}
}
I am using a third party API that rather clumsily makes use of ref parameters to produce outputs. Personally I really hate this design of an API but it's what I have available to me right now. I've had to hide the datatypes of the API slightly due to proprietary code but this should be irrelevant to the problem at hand.
Anyway in C# I can pass a null reference as a ref parameter successfully as follows:
IDataType tl = null;
bool success = api.myFunction(ref tl);
However in F# the following will not work
let mutable tl : IDataType = null //null reference assignment in F#
let success = api.myFunction(&tl) //& means ref in F#
It returns a null reference exception error. No such error is returned in C#.
Has anyone experiences this before? I am thinking it must be a bug in the API itself which is relatively ancient design.
**Edit: This should be closed, I believe the answer does not lie in the F# code but in the API as it's already a number of known bugs similar to this.
Quick and dirty prototyping of your API in C#
namespace API
{
public interface IDataType { void Hi(); }
public class API: IDataType {
public void Hi() { System.Console.WriteLine("Hi!"); }
public bool MyFunction(ref IDataType iface) {
iface = new API();
return true;
}
}
}
and then using it from F# exactly your way while staying within the same CLR:
let mutable iface : API.IDataType = null
if API.API().MyFunction(&iface) then iface.Hi()
works without any problem.
So, indeed, your problem is specific to your given API and has nothing to do with the form of its use from F#.
Using a ref cell is also an option here. Does this work?
let tl = ref null
let success = api.myFunction(tl)
The problem was with the API being compiled in .NET 2.0 which works fine under C# but not F#.
I have bmp (or jpg) file.
I need to convert it to dds file programmatically (I can use C++, C# with or without .NET; I can try any other language if I would see some clues in it)
I know that there are software that do this, but I need it to integrate into my programm, this should be a part of a longer manipulations on my application.
BTW, my question is:
1) Are there any opensource program that does this, so I can look into the code of it?
2) Are there any tutorials found somewhere in web that can help me to write this code?
I could not found any helpfull information.
Thank you!
I'm sure there are standalone converters you can use calling them via command line, if you need a programmatically solution the easiest way I may think about is to use built-in XNA classes to do the job. Because XNA handles all these file formats you can open source .bmp and then save it back to .dds (using the Texture class):
public static void ConvertToDds(
GraphicsDevice graphicsDevice, string sourcePath, string targetPath)
{
Texture.FromFile(graphicsDevice, sourcePath)
.Save(targetPath, ImageFileFormat.Dds);
}
Things changed with XNA 4.0 (these methods have been removed), try the DDSLib to write and Texture2D to read:
public static void ConvertToDds(
GraphicsDevice graphicsDevice, string sourcePath, string targetPath)
{
using (var stream = File.Open(sourcePath))
{
var texture = Texture2D.FromStream(graphicsDevice, stream);
DDSLib.DDSToFile(targetPath, true, texture, false);
}
}
See linked pages for more details and examples. By the way you can't have C# without .NET!
Say I want to create a source code editor for ocaml programming language, where do I start? I am looking to create an editor for the Windows platform as a hobby project. My primary skill is in web development. I have developed windows apps long time ago. I have no clue how it is done with todays available tools. I have visual studio 2008 and C# is my language of choice.
You need to know:
OCAML Syntax, Features, Keywords, Functions etc...
C# as this is your native language I guess
You need to know what features you wanna implement
...if it's using a GUI or just from a terminal like nano/vim
how syntax highlighting works
how to open and save files
how autocompletion works
etc..
You might want to take look at some open source editors like dev-c++ or gedit
Also, as you in person are more web-devvy, you might want to start creating one which runs in a web browser. This is often easier and helps you understand the basics of creating a code editor. Later you can always write one for desktops.
If you are most comfortable in Visual Studio, then you can use the Visual Studio Shell to create your own IDE based on that foundation.
Here is a podcast that gives a good overview:
http://www.code-magazine.com/codecast/index.aspx?messageid=32b9401a-140d-4acb-95bb-6accd3a3dafc
Also, as a reference, the IronPython Studio was created using the Visual Studio 2008 Shell:
http://ironpythonstudio.codeplex.com/
Browsing that source code should give you a good starting point.
a lighter-weight alternative is to use the RichEdit control
example:
http://www.codeproject.com/Messages/3401956/NET-Richedit-Control.aspx
// http://www.codeproject.com/Messages/3401956/NET-Richedit-Control.aspx
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace RichEditor
{
public class RichTextBoxEx : RichTextBox
{
IntPtr mHandle = IntPtr.Zero;
protected override CreateParams CreateParams
{
get
{
// Prevent module being loaded multiple times.
if (this.mHandle == IntPtr.Zero)
{
// load the library to obtain an instance of the RichEdit50 class.
this.mHandle = LoadLibrary("msftedit.dll");
}
// If module loaded, reset ClassName.
if (this.mHandle != IntPtr.Zero)
{
CreateParams cParams = base.CreateParams;
// Check Unicode or ANSI system and set appropriate ClassName.
if (Marshal.SystemDefaultCharSize == 1)
{
cParams.ClassName = "RichEdit50A";
}
else
{
cParams.ClassName = "RichEdit50W";
}
return cParams;
}
else // Module wasnt loaded, return default .NET RichEdit20 CreateParams.
{
return base.CreateParams;
}
}
}
~RichTextBoxEx()
{
//Free loaded Library.
if (mHandle != IntPtr.Zero)
{
FreeLibrary(mHandle);
}
}
[DllImport("kernel32.dll", SetLastError = true)]
private static extern IntPtr LoadLibrary(String lpFileName);
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool FreeLibrary(IntPtr hModule);
}
}
You could use Scintilla. It has syntax highlighting and some other features. Also, it has a .NET Version available here.
Another good tool is Alsing Syntax Box:
Powerful Syntax Highlight Windows
Forms Control for the Microsoft.NET
Platform. Written in 100% managed C#.
Supports syntax highlighting and code
folding for just about any programming
language.
With Alsing Syntax Box, you can define a syntax file (just like this one for C#) and later have a intellisense like feature.
You can start with one of them for your editor.