rangeOfComposedCharacterSequenceAtIndex in Xamarin? - c#

I'm trying to port the iosMath LaTeX library to C#. iosMath uses NSString's rangeOfComposedCharacterSequenceAtIndex in certain places. But I can't find any equivalent in Xamarin's NSString API. What am I missing? Is this functionality available some other way? If so, how?
Cross-posted on the Xamarin forums here.

Is this functionality available some other way?
We have to implement it by ourselves using C# if the api can not be found in the Class.
For example :
rangeOfString in NSString also can't be found ,and we can create the method instead.
static NSRange CalcRangeFor (string source, string substring)
{
var range = new NSRange {
Location = source.IndexOf (substring),
Length = substring.Length
};
return range;
}
However, rangeOfComposedCharacterSequenceAtIndex is a bit of complex, you can search the source code and implement with your new method. But I'm afraid it is still hard to do the work, since it is related to CoreFoundtion and we know little about it.
So why didn't you try to create a binding project? You don't have to transform the code from objective-c to c# but need some extra works for binding.
Refer to Binding iOS Libraries

Related

Elm Architecture (MVU) in C# and Deep Copy

I'm looking into the possibility of implementing an MVU pattern in a Xamarin app using C#. This mostly seems to hinge on the immutability of the model being provided to the view and the Update function that will keep producing a new model whenever the model needs to be changed.
Is it possible in C# to properly achieve this without implementing some sort of deep copy if the model might contain reference types?
I'm aware that frameworks like Fabulous exist for doing this in F# but I'm just trying to understand if C#'s lack of support for immutability means it isn't possibly to implement a pure form of MVU without resorting to implementing some sort of deep copy operation?
Seems like Microsoft will answer to this questions with its upcoming Multi-platform App UI (MAUI) framework soon:
readonly State<int> count = 0;
[Body]
View body() => new StackLayout
{
new Label("Welcome to .NET MAUI!"),
new Button(
() => $"You clicked {count} times.",
() => count.Value ++)
)
};
More info:
https://aka.ms/maui
GitHub
Roadmap
Comet is likely the library you're looking for. It will also be the foundation of the MVU pattern MAUI will support, and that #sevenate was referring to.
There's a library for doing full MVU in C# with Xamarin.Forms: https://github.com/shirshov/laconic (I'm the author)

C# Bouncy Castle FipsDRBG

I'm trying to access a few things from FipsDRBG class.
My code is shown below. How do I access fromEntropySource()? This function is within the internal class Base in FipsDRBG.
MyEntropyProvider entropyProvider = new MyEntropyProvider(#params);
FipsDrbg.BuilderService shaAlgo = FipsDrbg.Sha1; // Here I tried to use FipsDrbg.Base but then again it is internal
FipsDrbg.Builder builder = shaAlgo.fromEntropySource(entropyProvider);
I've compared C# FipsDrbg with Java FipsDrbg. In Java, all classes are declared public which is why I can access them easily. I can neither access FipsDrbg.Base or fromEntropySource().
Can someone please suggest how to proceed with this?
I could access all the FIPS related code after getting a paid version of the library. It has great support for all the FIPS related functions which may or may not be available in the free version.

Creating new Excel formulas/functions with C#

We are looking to be able to programmatically create an Excel workbook which would call custom code from within a cell. Cells would look something like:
=MyCode(A1:A10)
My first thought was to use VBA, but since the algorithm is proprietary the powers that be want it to be protected. I can put a password on it, but it is well documented (here on StackOverflow) on how to get around such passwords.
My second thought was to create an Excel 2013 Workbook project in Visual Studio, but I haven't found anything useful on how to expose a function in C# so it can be called like I described.
Next I thought about having VBA call the C#, and found instructions at https://msdn.microsoft.com/en-us/library/bb608613.aspx. I followed those instructions to the letter, but when I try to run the VBA code I get an error with the GetManagedClass function: Object Library Feature not Supported.
Are there any good references on how to do something like this?
You're looking for Excel-DNA.
This open-source library allows you to create managed Excel add-ins, and supports making user-defined functions, but also macros, real-time RTD data sources etc.
Creating an Excel UDF in C# is then as simple as:
[ExcelFunction(Description = "My first .NET function")]
public static string SayHello(string name)
{
return "Hello " + name;
}
and you can call from a cell as:
=SayHello("Walter")
For code protection with .NET, you'd need to use an obfuscator - there are a variety of free and paid-for ones available.
I have also tried this sample, with the same error. I found a solution that worked for me.
In the ISheet1.cs file, replace the ISheet1 interface declaration with the following code. This code makes the ISheet1 interface public, and it applies the http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.comvisibleattribute.aspx attribute to make the interface visible to COM.
C#
[System.Runtime.InteropServices.ComVisible(true)]
public interface ISheet1
{
void CreateVstoNamedRange(Microsoft.Office.Interop.Excel.Range range, string name);
}
Full article her: http://www.nullskull.com/q/10059408/c-code-to-set-excel-workbook-macro-enabled-and-to-trust-vba-projects.aspx

Parsing C# code for contextually aware semantic highlighting

I'm working on a semantic highlighting plugin for VS. Here you can see a web Example.
The goal:
Acquiring all variables and creating different Classifications for every one of them.
The problem:
Getting the variables from the code without writing a C# lexer.
My current approach uses an ITagger. I use an ITagAggregator to get the tags of all the spans that get passed to the ITagger. Then I filter those and get only spans with the "identifier" classification which includes varibles, methods names, class names, usings and properties.
public class Classifier : ITagger<ClassificationTag> {
public IEnumerable<ITagSpan<ClassificationTag>> GetTags(NormalizedSnapshotSpanCollection spans) {
ITextSnapshot snapshot = spans[0].Snapshot;
var tags = _aggregator.GetTags(spans).Where((span) => span.Tag.ClassificationType.Classification.Equals("identifier")).ToArray();
foreach(var classifiedSpan in tags) {
foreach(SnapshotSpan span in classifiedSpan.Span.GetSpans(snapshot)) {
//generate classification based on variable name
yield return new TagSpan<ClassificationTag>(span, new ClassificationTag(_classification));
}
}
}
}
It would be a lot easier to use the builtin C# Lexer to get a list of all variables bundled to a bunch of meta data. Is this data available for plugin development? Is there an alternative way I could acquire it, if not?
The problem: Getting the variables from the code without writing a C# lexer.
Roslyn can do this: https://roslyn.codeplex.com/
There's even a Syntax Visualizer sample that might interest you. I also found an example using Roslyn to create a Syntax Highlighter.
Visual Studio exposes that information as a code model.
Here is an example how you can access class, and then find attribute on the class, and parse attribute arguments:
Accessing attribute info from DTE
Here is more information about code models:
http://msdn.microsoft.com/en-us/library/ms228763.aspx
Here's also automation object model chart what I've been using quite few times: http://msdn.microsoft.com/en-us/library/za2b25t3.aspx
Also, as said, Roslyn is indeed also a possible option. Here is an example for VS2015 using roslyn: https://github.com/tomasr/roslyn-colorizer/blob/master/RoslynColorizer/RoslynColorizer.cs
For building language tools if may be better to use a parser generator for C#. The GOLD parsing system is one such toolkit which can handle LALR grammars. It has a .NET component based engine that you can use in your project and it can be used to integrate with any IDE. You can also find the grammars for various programming languages including C#.

mongodb : How do I create text index with C# driver?

For mongodb, how can I create the following index in C# ?
db.reviews.ensureIndex( { comments: "text" } )
I don't see any "Text" option for IndexOptions at http://api.mongodb.org/csharp/current/?topic=html/7e62224e-33ab-098b-4e07-797c45494a63.htm
You'll need to set this up through a script or directly on the MongoDB database as the C# driver doesn't expose the text index creation feature as it's still in "beta".
Unfortunately, you can't easily override the behavior either ... as the classes that control the behavior aren't easily overriden/extensible.
If you created a copy of the IndexKeysBuilder class (here), and added a new method (something like below):
public IndexKeysBuilder Text(string name)
{
_document.Add(name, "text");
return this;
}
You could use that instead of the built in stuff and in theory, it should work (I've not tested this).
the easiest way to create text indexes in c# is by using the driver wrapper library MongoDB.Entities. here's an example of creating a text index:
DB.Index<Review>()
.Key(a => a.Comment, Type.Text)
.Create();
haven't seen anything else that makes it simpler than that.

Categories

Resources