public static void ToString_InvalidFormat_ThrowsFormatException() { nuint i = 123; Assert.Throws <FormatException>(() => i.ToString("Y")); // Invalid format Assert.Throws <FormatException>(() => i.ToString("Y", null)); // Invalid format }
public override UIImage IconForSize(nuint size) { string text = null; nuint bucketIndex = 0; if (options.EnableBuckets) { var buckets = options.Buckets; bucketIndex = BucketIndexForSize((nint)size); text = size < (nuint)buckets[0] ? size.ToString() : $"{buckets[bucketIndex]}+"; } else { text = size.ToString(); } if (options.RendererCallback != null) { return(DefaultImageFactory.Instance.ToUIImage(options.RendererCallback(text))); } if (options.RendererImage != null) { return(GetIconForText(text, DefaultImageFactory.Instance.ToUIImage(options.RendererImage))); } return(GetIconForText(text, bucketIndex)); }
public static void ToStringTest(nuint i, string format, IFormatProvider provider, string expected) { // Format is case insensitive string upperFormat = format.ToUpperInvariant(); string lowerFormat = format.ToLowerInvariant(); string upperExpected = expected.ToUpperInvariant(); string lowerExpected = expected.ToLowerInvariant(); bool isDefaultProvider = (provider == null || provider == NumberFormatInfo.CurrentInfo); if (string.IsNullOrEmpty(format) || format.ToUpperInvariant() is "G" or "R") { if (isDefaultProvider) { Assert.Equal(upperExpected, i.ToString()); Assert.Equal(upperExpected, i.ToString((IFormatProvider)null)); } Assert.Equal(upperExpected, i.ToString(provider)); } if (isDefaultProvider) { Assert.Equal(upperExpected, i.ToString(upperFormat)); Assert.Equal(lowerExpected, i.ToString(lowerFormat)); Assert.Equal(upperExpected, i.ToString(upperFormat, null)); Assert.Equal(lowerExpected, i.ToString(lowerFormat, null)); } Assert.Equal(upperExpected, i.ToString(upperFormat, provider)); Assert.Equal(lowerExpected, i.ToString(lowerFormat, provider)); }
public override void DidSelectShape(SFMap map, NSObject data) { mapping.label5.Text = mappingLayer.SelectedItems.Count.ToString(); var selected = mappingLayer.SelectedItems; string text = ""; if (mappingLayer.SelectedItems.Count == 0) { mapping.button4.Enabled = false; mapping.button4.Alpha = (float)0.5; } for (nuint i = 0; i < mappingLayer.SelectedItems.Count; i++) { NSObject item = (NSObject)mappingLayer.SelectedItems.GetItem <NSObject>(i); NSDictionary dic1 = (NSDictionary)item; if ((NSString)(dic1["SeatNumber"]) == "1" || (NSString)(dic1["SeatNumber"]) == "2" || (NSString)(dic1["SeatNumber"]) == "8" || (NSString)(dic1["SeatNumber"]) == "9") { selected.RemoveObject(nint.Parse(i.ToString())); mappingLayer.SelectedItems = selected; mapping.label5.Text = mappingLayer.SelectedItems.Count.ToString(); if (selected.Count == 0) { mapping.button4.Enabled = false; mapping.button4.Alpha = (float)0.5; } else { if (text.EndsWith(",")) { text = text.Remove(text.Length - 1); } } } else { if (i == mappingLayer.SelectedItems.Count - 1) { text += "S" + ((NSString)(dic1["SeatNumber"])); } else { text += "S" + ((NSString)(dic1["SeatNumber"]) + ","); } mapping.button4.Enabled = true; mapping.button4.Alpha = (float)1; } } mapping.selection(text); }
void Uint() { uint a = uint.MaxValue; long h = a; ulong i = a; nuint k = a; var k2 = k.ToString(); float l = a; var l2 = $"{l:N}"; double m = a; decimal n = a; }
private UIImage TextToImage(nuint size) { var text = size.ToString(); var uiImage = UIImage.FromBundle("markClaster"); nfloat fWidth = uiImage.Size.Width; nfloat fHeight = uiImage.Size.Height; CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB(); using (CGBitmapContext ctx = new CGBitmapContext(IntPtr.Zero, (nint)fWidth, (nint)fHeight, 8 , 4 * (nint)fWidth, CGColorSpace.CreateDeviceRGB() , CGImageAlphaInfo.PremultipliedFirst)) { ctx.DrawImage(new CGRect(0, 0, (double)fWidth, (double)fHeight), uiImage.CGImage); ctx.SelectFont("Roboto-Bold", 12, CGTextEncoding.MacRoman); //Measure the text's width - This involves drawing an invisible string to calculate the X position difference float start, end, textWidth; //Get the texts current position start = (float)ctx.TextPosition.X; //Set the drawing mode to invisible ctx.SetTextDrawingMode(CGTextDrawingMode.Invisible); //Draw the text at the current position ctx.ShowText(text); //Get the end position end = (float)ctx.TextPosition.X; //Subtract start from end to get the text's width textWidth = end - start; //Set the fill color to black. This is the text color. ctx.SetFillColor(UIColor.White.CGColor); //Set the drawing mode back to something that will actually draw Fill for example ctx.SetTextDrawingMode(CGTextDrawingMode.Fill); //Draw the text at given coords. ctx.ShowTextAtPoint(uiImage.Size.Width / 2 - textWidth / 2, uiImage.Size.Height / 2, text); return(UIImage.FromImage(ctx.ToImage())); } }
public override UIImage IconForSize(nuint size) { /* Setup */ string text = null; nuint bucketIndex = 0; /* We're using buckets? */ if (this._options.EnableBuckets) { var buckets = this._options.Buckets; bucketIndex = this.BucketIndexForSize((nint)size); // If size is smaller to first bucket size, use the size as is otherwise round it down to the // nearest bucket to limit the number of cluster icons we need to generate. if (size < (nuint)buckets[0]) { text = size.ToString(); } else { text = $"{buckets[bucketIndex]}+"; } } /* How we're drawing this? */ if (this._options.RendererCallback != null) { /* We're using custom lambda callback */ return(this._options.RendererCallback(text).ToUIImage()); } else if (this._options.RendererImage != null) { /* We're using custom image */ return(this.GetIconForText(text, this._options.RendererImage.ToUIImage())); } else { /* We're using raw colors */ return(this.GetIconForText(text, bucketIndex)); } }
private static void VerifyPointer(nuint value, ulong expected) { Assert.Equal(expected, value.ToUInt64()); uint expected32 = unchecked ((uint)expected); if (expected32 != expected) { Assert.Throws <OverflowException>(() => value.ToUInt32()); return; } Assert.Equal(expected32, value.ToUInt32()); Assert.Equal(expected.ToString(), value.ToString()); Assert.Equal(value, checked ((nuint)expected)); Assert.True(value == checked ((nuint)expected)); Assert.False(value != checked ((nuint)expected)); Assert.NotEqual(value, checked ((nuint)expected + 1)); Assert.False(value == checked ((nuint)expected + 1)); Assert.True(value != checked ((nuint)expected + 1)); }
public PrintRangeCellView(nuint start, nuint end, nuint MaxRange) { NSNotificationCenter.DefaultCenter.AddObserver(UIKeyboard.WillHideNotification, OnKeyboardNotification); this.BackgroundColor = UIColor.Clear; this.Frame = new CGRect(0, 0, 200, 44); MAX_PRINT_RANGE = MaxRange; // StartField StartField = GenerateTextField(String.Empty, new CGPoint(10, 5), 0); StartField.AllEditingEvents += HandleStartFieldEditingEvents; if (start > 0) { StartField.Text = start.ToString(); } // toLabel UILabel toLabel = eBriefingAppearance.GenerateLabel(17, UIColor.Black); toLabel.Text = "to"; toLabel.TextAlignment = UITextAlignment.Center; toLabel.Frame = new CGRect(StartField.Frame.Right + 8, (StartField.Center.Y - (21f / 2f)), 21, 21); this.AddSubview(toLabel); // EndField EndField = GenerateTextField(String.Empty, new CGPoint(toLabel.Frame.Right + 8, StartField.Frame.Y), 1); EndField.ReturnKeyType = UIReturnKeyType.Done; EndField.AllEditingEvents += HandleEndFieldEditingEvents; if (end > 0) { EndField.Text = end.ToString(); } }
public override string ToString() => Value.ToString((sizeof(nint) == 4) ? "X8" : "X16");
bool GenerateImage(Dictionary <Page, eBriefingMobile.Annotation> dict1, Dictionary <Page, List <eBriefingMobile.Note> > dict2) { try { if (pageList != null) { nuint totalImageSize = 0; List <Note> notes = new List <eBriefingMobile.Note> (); foreach (var page in pageList) { String localPath = DownloadedFilesCache.BuildCachedFilePath(page.URL); var printItemDict = new Dictionary <UIImage, List <Note> >(); if (!String.IsNullOrEmpty(localPath)) { CGPDFDocument pdfDoc = CGPDFDocument.FromFile(localPath); if (pdfDoc != null) { CGPDFPage pdfPage = pdfDoc.GetPage(1); if (pdfPage != null) { CGRect pageRect = pdfPage.GetBoxRect(CGPDFBox.Media); UIImage pdfImg = ImageHelper.PDF2Image(pdfPage, pageRect.Width, scale); // Add annotation if option selected if (dict1.ContainsKey(page)) { Annotation annotation = dict1 [page]; if (annotation != null) { Dictionary <String, PSPDFInkAnnotation> coordinateDict = AnnotationsDataAccessor.GenerateAnnDictionary((UInt32)page.PageNumber - 1, annotation); if (coordinateDict != null) { foreach (KeyValuePair <String, PSPDFInkAnnotation> item in coordinateDict) { // Create full size annotation UIImage annImg = ImageHelper.DrawPSPDFAnnotation(item.Key, item.Value); if (annImg != null) { // Scale down the annotation image annImg = annImg.Scale(new CGSize(pdfImg.Size.Width, pdfImg.Size.Height)); // Overlap pdfImg and annImg pdfImg = ImageHelper.Overlap(pdfImg, annImg, CGPoint.Empty, CGPoint.Empty, scale); } } } } } // Create image from text bool printNote = false; UIImage noteImg = null; if (dict2.ContainsKey(page) && dict2 [page] != null) { printNote = true; notes = dict2 [page]; // Create image from text //noteImg = ImageHelper.Text2Image(_notesText, pdfImg.Size); } else { notes = null; } // Scale down and add to canvas // Used 900 and 1200 because couldn't control the paper margin // if (Orientation == ORIENTATION.PORTRAIT) // { // //if (printNote) // { // //pdfImg = ImageHelper.Scale(pdfImg, 500); // //pdfImg=ImageHelper.MaxResizeImage(pdfImg,1000,scale); // //pdfImg = ImageHelper.Add2Canvas(pdfImg, new CGPoint(0, (1024 / 2) - (pdfImg.Size.Height / 2)), scale); // // // Overlap pdfImg and noteImg // //pdfImg = ImageHelper.Overlap(pdfImg, noteImg, CGPoint.Empty, new CGPoint(500, 0), scale); // } // //else // { // //pdfImg=ImageHelper.MaxResizeImage(pdfImg,1000,scale); // //pdfImg = ImageHelper.Scale(pdfImg, 900); // //pdfImg = ImageHelper.Add2Canvas(pdfImg, new CGPoint((768 / 2) - (pdfImg.Size.Width / 2), (1024 / 2) - (pdfImg.Size.Height / 2)), scale); // } // } // else // { // //if (printNote) // { // //pdfImg=ImageHelper.MaxResizeImage(pdfImg,500,scale); // //pdfImg = ImageHelper.Scale(pdfImg, 500); // // pdfImg = ImageHelper.Add2Canvas(pdfImg, new CGPoint(0,0), scale*2, UIInterfaceOrientation.LandscapeLeft); // // Overlap pdfImg and noteImg // //pdfImg = ImageHelper.Overlap(pdfImg, noteImg, CGPoint.Empty, new CGPoint(756, 0), scale); // } // //else // { // //pdfImg=ImageHelper.MaxResizeImage(pdfImg,1000,scale); // //pdfImg = ImageHelper.Scale(pdfImg, 500); // ///pdfImg = ImageHelper.Add2Canvas(pdfImg, new CGPoint((1024 / 2) - (pdfImg.Size.Width / 2), (768 / 2) - (pdfImg.Size.Height / 2)), scale*2, UIInterfaceOrientation.LandscapeLeft); // } // // // Rotate canvas // //pdfImg = ImageHelper.Rotate(pdfImg); // } // Save // if (printItems == null) // { // printItems = new List<UIImage>(); // } // printItems.Add(pdfImg); if (dict == null) { dict = new Dictionary <int, Dictionary <UIImage, List <Note> > > (); } if (pdfImg != null) { printItemDict.Add(pdfImg, notes); dict.Add(page.PageNumber, printItemDict); var pngImage = pdfImg.AsPNG(); totalImageSize = pngImage.Length + totalImageSize; Console.WriteLine("Img : " + totalImageSize.ToString()); //image dispose pdfImg = null; if (CheckReachMemoryLimit(totalImageSize)) { PagesNum = dict.Count - 1; dict.Clear(); dict = null; return(false); } } } } } } PagesNum = dict.Count; return(true); } return(false); } catch (Exception ex) { return(false); } }
/// <inheritdoc cref="object.ToString" /> public override string ToString() => UseInt?_intValue.ToString() : _pointerValue.ToString();
public override string ToString() => Value.ToString();
/// <summary> /// Asserts whether the contents of a given <see cref="MemoryBuffer"/> lie in the <see cref="minAddress"/> to <see cref="maxAddress"/> address range. /// </summary> private unsafe void AssertBufferInRange(MemoryBuffer buffer, nuint minAddress, nuint maxAddress) { nuint bufferDataPtr = buffer.Properties.DataPointer; if ((void *)bufferDataPtr < (void *)minAddress || (void *)bufferDataPtr > (void *)maxAddress) { Assert.True(false, $"The newly allocated MemoryBuffer should lie in the {minAddress.ToString("X")} to {maxAddress.ToString("X")} range."); } }