/// <summary> /// Initializes a new instance. /// </summary> /// <param name="description"> /// A <see cref="System.String"/> /// </param> /// <param name="typeCode"> /// A <see cref="System.TypeCode"/> /// </param> protected PixelBand(string description, System.TypeCode typeCode) { Description = description; TypeCode = typeCode; Size = ComputeSize(typeCode); }
public void Enum_BitStreamerUpCastTest() { const int k_bit_count = 64; using (var ms = new System.IO.MemoryStream()) using (var s = new IO.BitStream(ms)) { const System.TypeCode kExpectedValue = System.TypeCode.String; var value = kExpectedValue; s.StreamMode = System.IO.FileAccess.Write; TypeCodeStreamer64.Write(s, value, k_bit_count); s.Flush(); s.SeekToStart(); s.StreamMode = System.IO.FileAccess.Read; TypeCodeStreamer64.Read(s, out value, k_bit_count); Assert.AreEqual(kExpectedValue, value); ////////////////////////////////////////////////////////////////////////// // Test the instance interface var streamer_instance = TypeCodeStreamer64.Instance; s.SeekToStart(); s.StreamMode = System.IO.FileAccess.Write; streamer_instance.Write(s, value, k_bit_count); s.Flush(); s.SeekToStart(); s.StreamMode = System.IO.FileAccess.Read; streamer_instance.Read(s, out value, k_bit_count); Assert.AreEqual(kExpectedValue, value); } }
public static bool IsInteger(object value) { if (value == null) { return(false); } if (int.TryParse(value.ToString(), out _)) { return(true); } System.TypeCode type = System.Type.GetTypeCode(value.GetType()); switch (type) { case System.TypeCode.String: return(IsNumeric(value)); default: return(false); } }
public static object ToEnumsNumericType(ulong v, System.TypeCode code) { switch (code) { case System.TypeCode.Byte: return(System.Convert.ToByte(v)); case System.TypeCode.SByte: return(System.Convert.ToSByte(v)); case System.TypeCode.Int16: return(System.Convert.ToInt16(v)); case System.TypeCode.UInt16: return(System.Convert.ToUInt16(v)); case System.TypeCode.Int32: return(System.Convert.ToInt32(v)); case System.TypeCode.UInt32: return(System.Convert.ToUInt32(v)); case System.TypeCode.Int64: return(System.Convert.ToInt64(v)); case System.TypeCode.UInt64: return(System.Convert.ToUInt64(v)); default: return(null); } }
public void AddValue(object addition) { if (IsProperty) { PropertyInfo p = (PropertyInfo)memberInfo; try { System.TypeCode typeCode = System.Type.GetTypeCode(p.PropertyType); switch (typeCode) { case System.TypeCode.UInt16: case System.TypeCode.UInt32: case System.TypeCode.UInt64: case System.TypeCode.Int16: case System.TypeCode.Int32: case System.TypeCode.Int64: p.GetSetMethod().Invoke(DebuggerOptions.Current, new object[] { (int)((int)GetValue() + (float)addition) }); break; case System.TypeCode.Decimal: case System.TypeCode.Single: p.GetSetMethod().Invoke(DebuggerOptions.Current, new object[] { (float)GetValue() + (float)addition }); break; case System.TypeCode.Double: p.GetSetMethod().Invoke(DebuggerOptions.Current, new object[] { (double)((double)GetValue() + (float)addition) }); break; default: break; } } catch (System.Exception ex) { Debug.LogError("Cannot Add Value\n" + ex.StackTrace); } } }
private bool disposed = false; // track whether resources have been released /// <summary> /// Constructor - takes an already constructed ERDAS image file /// </summary> public OutputRaster(WritableImage image) { this.image = image; // make sure we got valid image if (this.image == null) { throw new System.ApplicationException("OutputRaster constructor passed null image"); } // Begin test bandtype compatibilities T desiredLayout = new T(); int bandCount = desiredLayout.BandCount; System.TypeCode bandType = desiredLayout[0].TypeCode; // check band 0 if (bandType != image.BandType) { throw new System.ApplicationException("OutputRaster band type mismatch"); } // check bands 1 to n-1 for (int i = 1; i < bandCount; i++) { IPixelBand band = desiredLayout[i]; if (band.TypeCode != bandType) { throw new System.ApplicationException("OutputRasters with mixed band types not supported"); } } }
public static bool ToBoolean(object value) { if (value == null) { return(false); } if (int.TryParse(value.ToString(), out int outValue)) { return(System.Convert.ToBoolean(outValue)); } System.TypeCode type = System.Type.GetTypeCode(value.GetType()); switch (type) { case System.TypeCode.String: return(SymbolToBoolean()); case System.TypeCode.Char: return(SymbolToBoolean()); case System.TypeCode.Boolean: return(System.Convert.ToBoolean(value)); default: return(false); } bool SymbolToBoolean() { string symbol = (string)value; if (string.IsNullOrWhiteSpace(symbol)) { return(false); } else { switch (symbol.Trim().ToUpperInvariant()) { case "TRUE": return(true); case "T": return(true); case "YES": return(true); case "Y": return(true); case "1": return(true); default: return(false); } } } }
public void Enum_BinaryStreamerUpCastTest() { using (var ms = new System.IO.MemoryStream()) using (var br = new IO.EndianReader(ms)) using (var bw = new IO.EndianWriter(ms)) { const System.TypeCode kExpectedValue = System.TypeCode.String; var value = kExpectedValue; TypeCodeStreamer64.Write(bw, value); ms.Position = 0; TypeCodeStreamer64.Read(br, out value); Assert.IsTrue(value == kExpectedValue); ////////////////////////////////////////////////////////////////////////// // Test the instance interface var streamer_instance = TypeCodeStreamer64.Instance; ms.Position = 0; streamer_instance.Write(bw, value); ms.Position = 0; streamer_instance.Read(br, out value); Assert.IsTrue(value == kExpectedValue); } }
private static object ToEnumsNumericType(ulong v, System.TypeCode code) { switch (code) { case System.TypeCode.Byte: return((byte)v); case System.TypeCode.SByte: return((sbyte)v); case System.TypeCode.Int16: return((short)v); case System.TypeCode.UInt16: return((ushort)v); case System.TypeCode.Int32: return((int)v); case System.TypeCode.UInt32: return((uint)v); case System.TypeCode.Int64: return((long)v); case System.TypeCode.UInt64: return(v); default: return(null); } }
internal static void SignatureKeyToConsole(object value) { if (value == null) { return; } System.Diagnostics.Trace.WriteLine($"current signature: " + Properties.Settings.Default.Signature); System.TypeCode type = System.Type.GetTypeCode(value.GetType()); string plainText = null; switch (type) { case System.TypeCode.Int32: plainText = value.ToString(); break; case System.TypeCode.String: plainText = value.ToString(); break; default: System.Diagnostics.Trace.WriteLine($"Invalid object:" + plainText); break; } if (plainText == null) { return; } string encryptString = Encryption.AESThenHMAC.SimpleEncrypt(plainText, byteCryptKey, byteAuthKey); byte[] byteSignature = System.Text.Encoding.Default.GetBytes(encryptString); string hexSignature = ClassLibraryFramework.StringMethods.GetBytesToString(byteSignature); string encryptedString = System.Text.Encoding.Default.GetString(byteSignature); string decryptedString = Encryption.AESThenHMAC.SimpleDecrypt(encryptString, byteCryptKey, byteAuthKey); System.Diagnostics.Trace.WriteLine($"encryptString: " + encryptString); System.Diagnostics.Trace.WriteLine($"hexSignature: " + hexSignature); System.Diagnostics.Trace.WriteLine($"encryptedString: " + encryptedString); System.Diagnostics.Trace.WriteLine($"decryptedString: " + decryptedString); }
private bool IsNumeric(System.Type objType, System.TypeCode typeCode) { if (objType.IsPrimitive && typeCode != System.TypeCode.Object) { return(typeCode != System.TypeCode.Char && typeCode != System.TypeCode.Boolean); } else if (typeCode == System.TypeCode.Decimal) { return(true); } return(false); }
/// <summary> /// Open a writer on a new file /// </summary> public WritableImage(string filename, Dimensions dimensions, int bandCount, System.TypeCode bandType, IMetadata metadata) : base(filename, dimensions, bandCount, bandType, metadata) { this.pixelsWritten = 0; // open file for writing this.file = new FileStream(filename, FileMode.Open); this.fileWriter = new BinaryWriter(this.file); }
private static void Write(BinaryWriter writer, object value, System.TypeCode typeCode) { switch (typeCode) { case System.TypeCode.String: writer.Write((string)value); break; case System.TypeCode.Boolean: writer.Write((bool)value); break; case System.TypeCode.Byte: writer.Write((byte)value); break; case System.TypeCode.Decimal: writer.Write((decimal)value); break; case System.TypeCode.Double: writer.Write((double)value); break; case System.TypeCode.Int16: writer.Write((short)value); break; case System.TypeCode.Int32: writer.Write((int)value); break; case System.TypeCode.Int64: writer.Write((long)value); break; case System.TypeCode.Single: writer.Write((float)value); break; default: Debug.Fail("Unexpected type of value supplied for writing to binary: " + value.GetType().ToString()); break; } }
private bool disposed = false; // track whether resources have been released /// <summary> /// Constructor - takes an already constructed ERDAS image file /// </summary> public ErdasOutputRaster(ErdasImageFile image, string path, Dimensions dimensions, IMetadata metadata) : base(path, dimensions, metadata) { this.image = image; // make sure we got valid image if (this.image == null) { throw new System.ApplicationException("OutputRaster constructor passed null image"); } // make sure image is not readonly if (this.image.Mode == RWFlag.Read) { throw new System.ApplicationException("OutputRaster cannot be constructed on ReadOnly image"); } // Begin test bandtype compatibilities T desiredLayout = new T(); int bandCount = desiredLayout.BandCount; System.TypeCode bandType = desiredLayout[0].TypeCode; // check band 0 if (bandType != image.BandType) { throw new System.ApplicationException("OutputRaster band type mismatch"); } // check bands 1 to n-1 for (int i = 1; i < bandCount; i++) { IPixelBand band = desiredLayout[i]; if (band.TypeCode != bandType) { throw new System.ApplicationException("OutputRasters with mixed band types not supported"); } } }
/// <summary> /// /// </summary> public IOutputRaster <T> Create <T>(string path, Dimensions dimensions, IMetadata metadata) where T : IPixel, new() { // extract necessary parameters from pixel for image creation T desiredLayout = new T(); int bandCount = desiredLayout.BandCount; System.TypeCode bandType = desiredLayout[0].TypeCode; // open image file for writing ErdasImageFile image = new ErdasImageFile(path, dimensions, bandCount, bandType, metadata); // construct an OutputRaster from that return(new OutputRaster <T>(image)); }
static int _m_GetTypeCode(RealStatePtr L) { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); System.Enum __cl_gen_to_be_invoked = (System.Enum)translator.FastGetCSObj(L, 1); try { { System.TypeCode __cl_gen_ret = __cl_gen_to_be_invoked.GetTypeCode( ); translator.Push(L, __cl_gen_ret); return(1); } } catch (System.Exception __gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + __gen_e)); } }
private static object Read(BinaryReader reader, System.TypeCode typeCode) { switch (typeCode) { case System.TypeCode.Empty: return(null); case System.TypeCode.String: return(reader.ReadString()); case System.TypeCode.Boolean: return(reader.ReadBoolean()); case System.TypeCode.Byte: return(reader.ReadByte()); case System.TypeCode.Decimal: return(reader.ReadDecimal()); case System.TypeCode.Double: return(reader.ReadDouble()); case System.TypeCode.Int16: return(reader.ReadInt16()); case System.TypeCode.Int32: return(reader.ReadInt32()); case System.TypeCode.Int64: return(reader.ReadInt64()); case System.TypeCode.Single: return(reader.ReadSingle()); default: Debug.Fail("Unexpected type code read from binary: " + typeCode.ToString()); return(null); } }
private static object XmlFromString(string value, System.TypeCode typeCode) { switch (typeCode) { case System.TypeCode.String: return(value); case System.TypeCode.Boolean: return(XmlConvert.ToBoolean(value)); case System.TypeCode.Byte: return(XmlConvert.ToByte(value)); case System.TypeCode.Decimal: return(XmlConvert.ToDecimal(value)); case System.TypeCode.Double: return(XmlConvert.ToDouble(value)); case System.TypeCode.Int16: return(XmlConvert.ToInt16(value)); case System.TypeCode.Int32: return(XmlConvert.ToInt32(value)); case System.TypeCode.Int64: return(XmlConvert.ToInt64(value)); case System.TypeCode.Single: return(XmlConvert.ToSingle(value)); default: Debug.Fail("Invalid type code"); return(string.Empty); } }
private static string XmlToString(object value, System.TypeCode typeCode) { switch (typeCode) { case System.TypeCode.String: return((string)value); case System.TypeCode.Boolean: return(XmlConvert.ToString((bool)value)); case System.TypeCode.Byte: return(XmlConvert.ToString((byte)value)); case System.TypeCode.Decimal: return(XmlConvert.ToString((decimal)value)); case System.TypeCode.Double: return(XmlConvert.ToString((double)value)); case System.TypeCode.Int16: return(XmlConvert.ToString((short)value)); case System.TypeCode.Int32: return(XmlConvert.ToString((int)value)); case System.TypeCode.Int64: return(XmlConvert.ToString((long)value)); case System.TypeCode.Single: return(XmlConvert.ToString((float)value)); default: Debug.Fail("Invalid type code"); return(string.Empty); } }
/// <summary> /// Computes the size in bytes for a pixel band's data type. /// </summary> /// <param name="typeCode"> /// A <see cref="System.TypeCode"/> representing the pixel band's data /// type. /// </param> /// <returns> /// A <see cref="System.Int32"/> /// </returns> /// <exception cref="System.ArgumentException">Thrown if /// <paramref name="typeCode"/> is not Byte, SByte, Int16, UInt16, /// Int32, UInt32, Single or Double. /// </exception> public static int ComputeSize(System.TypeCode typeCode) { switch (typeCode) { case System.TypeCode.Byte: case System.TypeCode.SByte: return(1); case System.TypeCode.Int16: case System.TypeCode.UInt16: return(2); case System.TypeCode.Int32: case System.TypeCode.UInt32: case System.TypeCode.Single: return(4); case System.TypeCode.Double: return(8); default: throw new System.ArgumentException("Invalid type for pixel band"); } }
/// <summary> /// Open an existing file /// </summary> public ErdasImageFile(string filename, RWFlag mode) { this.open = false; this.mode = mode; // if filename does not end in .gis or .lan throw exception string extension = Path.GetExtension(filename).ToLower(); if (!(extension.Equals(".gis")) && !(extension.Equals(".lan"))) throw new System.ApplicationException("Erdas file must have either GIS or LAN as extension"); // open file this.file = new FileStream(filename,FileMode.Open); this.fileReader = new BinaryReader(this.file); this.open = true; try { // prepare to build metadata while reading Metadata metadata = new Metadata(); // Read Header // if not start with "HEAD74" throw exception byte[] sentinel = fileReader.ReadBytes(6); if ((sentinel[0] != (byte)'H') || (sentinel[1] != (byte)'E') || (sentinel[2] != (byte)'A') || (sentinel[3] != (byte)'D') || (sentinel[4] != (byte)'7') || (sentinel[5] != (byte)'4')) throw new System.ApplicationException(filename+" is not an ERDAS 7.4 compatible image file"); // packing System.UInt16 ipack = this.fileReader.ReadUInt16(); if ((ipack != 0) && (ipack != 2)) throw new System.ApplicationException("Only 8 and 16 bit bands are supported by Erdas reader"); // nbands System.UInt16 nbands = this.fileReader.ReadUInt16(); // unused byte[] unused = this.fileReader.ReadBytes(6); // icols System.UInt32 icols = this.fileReader.ReadUInt32(); // irows System.UInt32 irows = this.fileReader.ReadUInt32(); // xstart System.Int32 xstart = this.fileReader.ReadInt32(); metadata[RASTER_ULX] = xstart; // ystart System.Int32 ystart = this.fileReader.ReadInt32(); metadata[RASTER_ULY] = ystart; // unused unused = this.fileReader.ReadBytes(56); // maptyp System.UInt16 maptyp = this.fileReader.ReadUInt16(); string projection = Projections.find(maptyp); if (projection != null) metadata[PROJECTION] = projection; if (maptyp == 0) metadata[SCALE_UNITS] = "degrees"; else if (maptyp == 2) metadata[SCALE_UNITS] = "feet"; else metadata[SCALE_UNITS] = "meters"; // nclass : calc if needed but never has been in past System.UInt16 nclass = this.fileReader.ReadUInt16(); // unused unused = this.fileReader.ReadBytes(14); // iautyp System.UInt16 iautyp = this.fileReader.ReadUInt16(); // acre System.Single acre = this.fileReader.ReadSingle(); // xmap System.Single xmap = this.fileReader.ReadSingle(); metadata[WORLD_ULX] = xmap; // ymap System.Single ymap = this.fileReader.ReadSingle(); metadata[WORLD_ULY] = ymap; // xcell System.Single xcell = this.fileReader.ReadSingle(); metadata[X_SCALE] = xcell; // ycell System.Single ycell = this.fileReader.ReadSingle(); metadata[Y_SCALE] = ycell; // construct instance variables based upon hedaer info this.dimensions = new Dimensions((int)irows,(int)icols); if (ipack == 0) { this.bandType = System.TypeCode.Byte; this.bandSize = 1; } else // ipack == 2 due to earlier screening { this.bandType = System.TypeCode.UInt16; this.bandSize = 2; } this.bandCount = nbands; this.currPixel = 0; this.totalPixels = (int)irows * (int)icols; this.metadata = metadata; if (mode == RWFlag.Write) { this.fileReader.Close(); this.fileReader = null; // need to reopen stream - fileReader.Close() shuts it this.file = new FileStream(filename,FileMode.Open); this.fileWriter = new BinaryWriter(this.file); } } catch (System.Exception) { Close(); throw; } }
public object Convert(object value, System.TypeCode typeCode) { throw null; }
//----------------------------------------------------------------------------- static bool CheckInComponent(Component comp, Object findObject) { if (comp == null) { return(false); } PropertyInfo pi = null; try { MemberInfo[] meminfos = comp.GetType().GetMembers(); foreach (MemberInfo mi in meminfos) { // finding in field if (mi.MemberType == MemberTypes.Field) { FieldInfo fi = (FieldInfo)mi; System.TypeCode tcode = System.Type.GetTypeCode(fi.FieldType); if (tcode == System.TypeCode.Object) { object obj = fi.GetValue(comp); if (obj != null) { if (obj.GetType() == findObject.GetType() && obj == findObject) { return(true); } if (fi.FieldType.IsArray) { if (CheckInArray(fi.Name, (System.Array)obj, findObject)) { return(true); } } } } } if (mi.MemberType == MemberTypes.Property) { pi = (PropertyInfo)mi; string excludeName = pi.Name.ToLower(); if (excludeName == "mesh" || excludeName == "material" || excludeName == "materials") { continue; } System.TypeCode tcode = System.Type.GetTypeCode(pi.PropertyType); if (tcode == System.TypeCode.Object) { if (pi.CanWrite && pi.GetSetMethod().IsStatic == false) { object obj = pi.GetValue(comp, null); if (obj == null) { continue; } if (obj.GetType() == findObject.GetType() && obj == findObject) { return(true); } if (pi.PropertyType.IsArray) { if (CheckInArray(pi.Name, (System.Array)obj, findObject)) { return(true); } } } } } } } catch (System.Exception ex) { string errorStr = ex.ToString(); if (pi != null) { errorStr = "Property:" + pi.Name + "-" + ex.ToString(); } Debug.LogWarning("comp:" + comp.name + "-" + errorStr); } return(false); }
private static tAsyncCall *Parse_Internal(byte *pThis, byte *pParams, byte *pReturnValue, System.TypeCode typecode) { System.Globalization.NumberStyles numberStyle; tSystemString *pStr; // byte* pFormatProvider; string s; pStr = (*((tSystemString **)(pParams + 0))); s = ToMonoString(pStr); numberStyle = (System.Globalization.NumberStyles)(*((int *)(pParams + Sys.S_PTR))); // Ignore IFormatProvider (for now) //pFormatProvider = (*((tSystemString**)(pParams + Sys.S_PTR + Sys.S_INT32))); switch (typecode) { case System.TypeCode.Byte: (*(uint *)pReturnValue) = byte.Parse(s, numberStyle); break; case System.TypeCode.SByte: (*(uint *)pReturnValue) = (uint)sbyte.Parse(s, numberStyle); break; case System.TypeCode.UInt16: (*(uint *)pReturnValue) = ushort.Parse(s, numberStyle); break; case System.TypeCode.Int16: (*(uint *)pReturnValue) = (uint)short.Parse(s, numberStyle); break; case System.TypeCode.UInt32: (*(uint *)pReturnValue) = uint.Parse(s, numberStyle); break; case System.TypeCode.Int32: (*(uint *)pReturnValue) = (uint)int.Parse(s, numberStyle); break; case System.TypeCode.UInt64: (*(ulong *)pReturnValue) = ulong.Parse(s, numberStyle); break; case System.TypeCode.Int64: (*(long *)pReturnValue) = long.Parse(s, numberStyle); break; case System.TypeCode.Single: (*(float *)pReturnValue) = float.Parse(s, numberStyle); break; case System.TypeCode.Double: (*(double *)pReturnValue) = double.Parse(s, numberStyle); break; default: throw new System.NotImplementedException(); } return(null); }
public static tAsyncCall *TryParse_Internal(byte *pThis, byte *pParams, byte *pReturnValue, System.TypeCode typecode) { System.Globalization.NumberStyles numberStyle; tSystemString *pStr; // byte* pFormatProvider; string s; byte * pResult; pStr = (*((tSystemString **)(pParams + 0))); s = ToMonoString(pStr); numberStyle = (System.Globalization.NumberStyles)(*((int *)(pParams + Sys.S_PTR))); //pFormatProvider = (*((tSystemString**)(pParams + Sys.S_PTR + Sys.S_INT32))); pResult = (*((byte **)(pParams + Sys.S_PTR + Sys.S_INT32 + Sys.S_PTR))); // Ignore IFormatProvider switch (typecode) { case System.TypeCode.Byte: byte b; (*(uint *)pReturnValue) = byte.TryParse(s, numberStyle, null, out b) ? 1U : 0U; (*(uint *)pResult) = (uint)b; break; case System.TypeCode.SByte: sbyte sb; (*(uint *)pReturnValue) = sbyte.TryParse(s, numberStyle, null, out sb) ? 1U : 0U; (*(int *)pResult) = (int)sb; break; case System.TypeCode.UInt16: ushort us; (*(uint *)pReturnValue) = ushort.TryParse(s, numberStyle, null, out us) ? 1U : 0U; (*(uint *)pResult) = (uint)us; break; case System.TypeCode.Int16: short ss; (*(uint *)pReturnValue) = short.TryParse(s, numberStyle, null, out ss) ? 1U : 0U; (*(int *)pResult) = (int)ss; break; case System.TypeCode.UInt32: uint ui; (*(uint *)pReturnValue) = uint.TryParse(s, numberStyle, null, out ui) ? 1U : 0U; (*(uint *)pResult) = ui; break; case System.TypeCode.Int32: int si; (*(uint *)pReturnValue) = int.TryParse(s, numberStyle, null, out si) ? 1U : 0U; (*(int *)pResult) = si; break; case System.TypeCode.UInt64: ulong ul; (*(uint *)pReturnValue) = ulong.TryParse(s, numberStyle, null, out ul) ? 1U : 0U; (*(ulong *)pResult) = ul; break; case System.TypeCode.Int64: long sl; (*(uint *)pReturnValue) = long.TryParse(s, numberStyle, null, out sl) ? 1U : 0U; (*(long *)pResult) = sl; break; case System.TypeCode.Single: float f; (*(uint *)pReturnValue) = float.TryParse(s, numberStyle, null, out f) ? 1U : 0U; (*(float *)pResult) = f; break; case System.TypeCode.Double: double d; (*(uint *)pReturnValue) = double.TryParse(s, numberStyle, null, out d) ? 1U : 0U; (*(double *)pResult) = d; break; default: throw new System.NotImplementedException(); } return(null); }
public static tAsyncCall *GetTypeCode(tJITCallNative *pCallNative, byte *pThis_, byte *pParams, byte *pReturnValue) { tRuntimeType *pRuntimeType = *(tRuntimeType **)pParams; System.TypeCode typeCode = System.TypeCode.Object; switch (pRuntimeType->pTypeDef->typeInitId) { case Type.TYPE_SYSTEM_DATETIME: typeCode = System.TypeCode.DateTime; break; case Type.TYPE_SYSTEM_BOOLEAN: typeCode = System.TypeCode.Boolean; break; case Type.TYPE_SYSTEM_CHAR: typeCode = System.TypeCode.Char; break; case Type.TYPE_SYSTEM_STRING: typeCode = System.TypeCode.String; break; case Type.TYPE_SYSTEM_BYTE: typeCode = System.TypeCode.Byte; break; case Type.TYPE_SYSTEM_SBYTE: typeCode = System.TypeCode.SByte; break; case Type.TYPE_SYSTEM_INT16: typeCode = System.TypeCode.Int16; break; case Type.TYPE_SYSTEM_UINT16: typeCode = System.TypeCode.UInt32; break; case Type.TYPE_SYSTEM_INT32: typeCode = System.TypeCode.Int32; break; case Type.TYPE_SYSTEM_UINT32: typeCode = System.TypeCode.UInt32; break; case Type.TYPE_SYSTEM_INT64: typeCode = System.TypeCode.Int64; break; case Type.TYPE_SYSTEM_UINT64: typeCode = System.TypeCode.UInt64; break; case Type.TYPE_SYSTEM_SINGLE: typeCode = System.TypeCode.Single; break; case Type.TYPE_SYSTEM_DOUBLE: typeCode = System.TypeCode.Double; break; } *(uint *)pReturnValue = (uint)typeCode; return(null); }
private static tAsyncCall *ToString_Internal(byte *pThis, byte *pParams, byte *pReturnValue, System.TypeCode typecode) { tSystemString *pFormat; // byte* pFormatProvider; string format, s; tSystemString *pResult; pFormat = (*((tSystemString **)(pParams + 0))); format = ToMonoString(pFormat); // Ignore IFormatProvider for now! //pFormatProvider = (*((tSystemString**)(pParams + Sys.S_PTR))); switch (typecode) { case System.TypeCode.Byte: s = (*(byte *)pThis).ToString(format); break; case System.TypeCode.SByte: s = (*(sbyte *)pThis).ToString(format); break; case System.TypeCode.UInt16: s = (*(ushort *)pThis).ToString(format); break; case System.TypeCode.Int16: s = (*(short *)pThis).ToString(format); break; case System.TypeCode.UInt32: s = (*(uint *)pThis).ToString(format); break; case System.TypeCode.Int32: s = (*(int *)pThis).ToString(format); break; case System.TypeCode.UInt64: s = (*(ulong *)pThis).ToString(format); break; case System.TypeCode.Int64: s = (*(long *)pThis).ToString(format); break; case System.TypeCode.Single: s = (*(float *)pThis).ToString(format); break; case System.TypeCode.Double: s = (*(double *)pThis).ToString(format); break; default: throw new System.NotImplementedException(); } pResult = System_String.FromMonoString(s); Sys.INTERNALCALL_RESULT_PTR(pReturnValue, pResult); return(null); }
public CookieParameter(string name, System.TypeCode type, string cookieName) { }
public SessionParameter(string name, System.TypeCode type, string sessionField) { }
RWFlag mode; // file open mode: Read or Write /// <summary> /// Create a file given specs /// </summary> public ErdasImageFile(string filename, Dimensions dimensions, int bandCount, System.TypeCode bandType, IMetadata metadata) { // set instance variables this.open = false; this.mode = RWFlag.Write; this.dimensions = dimensions; this.bandType = bandType; this.bandCount = bandCount; this.currPixel = 0; this.totalPixels = dimensions.Rows*dimensions.Columns; this.metadata = metadata; // if filename does not end in .gis or .lan throw exception string extension = Path.GetExtension(filename).ToLower(); if (!(extension.Equals(".gis")) && !(extension.Equals(".lan"))) throw new System.ApplicationException("Erdas file must have either GIS or LAN as extension"); // if dimensions are messed up throw exception if ((dimensions.Rows < 1) || (dimensions.Columns < 1)) throw new System.ApplicationException("Erdas file given invalid dimensions"); // if bandCount messed up throw exception if ((bandCount < 1) || (bandCount > 0xffff)) throw new System.ApplicationException("Erdas file given invalid band count"); // more bandCount checking if (extension.Equals(".gis")) { if (bandCount > 1) throw new System.ApplicationException("Erdas GIS files cannot support multiband images"); if (bandType != System.TypeCode.Byte) throw new System.ApplicationException("Erdas GIS files only suupport byte for bandtype"); } // if bandType not System.Byte or System.UInt16 throw exception if (bandType == System.TypeCode.Byte) this.bandSize = 1; else if (bandType == System.TypeCode.UInt16) this.bandSize = 2; else throw new System.ApplicationException("Erdas file given unsupported band type"); // open file for writing this.file = new FileStream(filename,FileMode.OpenOrCreate); this.fileWriter = new BinaryWriter(this.file); this.open = true; // write header (using metadata whenever possible) try { // sentinel byte[] sentinel = new byte[6]; sentinel[0] = (byte) 'H'; sentinel[1] = (byte) 'E'; sentinel[2] = (byte) 'A'; sentinel[3] = (byte) 'D'; sentinel[4] = (byte) '7'; sentinel[5] = (byte) '4'; this.fileWriter.Write(sentinel); // packing System.UInt16 ipack; if (bandType == System.TypeCode.Byte) ipack = 0; else ipack = 2; this.fileWriter.Write(ipack); // nbands System.UInt16 nbands = (System.UInt16)bandCount; this.fileWriter.Write(nbands); // unused for (int i = 0; i < 6; i++) this.fileWriter.Write((byte)0); // icols System.UInt32 icols = (System.UInt32)dimensions.Columns; this.fileWriter.Write(icols); // irows System.UInt32 irows = (System.UInt32)dimensions.Rows; this.fileWriter.Write(irows); // xstart System.Int32 xstart = 0; if ((metadata != null) && (metadata.TryGetValue<System.Int32>(RASTER_ULX,ref xstart))) { } this.fileWriter.Write(xstart); // ystart System.Int32 ystart = 0; if ((metadata != null) && (metadata.TryGetValue<System.Int32>(RASTER_ULY,ref ystart))) { } this.fileWriter.Write(ystart); // unused for (int i = 0; i < 56; i++) this.fileWriter.Write((byte)0); // maptyp System.UInt16 maptyp = 99; // 99 means NONE string projection = null; if ((metadata != null) && (metadata.TryGetValue<string>(PROJECTION,ref projection))) { int projNum = Projections.find(projection); if (projNum != -1) maptyp = (System.UInt16)projNum; } this.fileWriter.Write(maptyp); // nclass : calc if needed but never has been in past System.UInt16 nclass = 0; this.fileWriter.Write(nclass); // unused for (int i = 0; i < 14; i++) this.fileWriter.Write((byte)0); // iautyp : first need xcell and ycell and then acre System.Single xcell = 0; if ((metadata != null) && (metadata.TryGetValue<System.Single>(X_SCALE,ref xcell))) { } if (maptyp == 99) xcell = 0; System.Single ycell = 0; if ((metadata != null) && (metadata.TryGetValue<System.Single>(Y_SCALE,ref ycell))) { } if (maptyp == 99) ycell = 0; System.UInt16 iautyp = 0; System.Single acre = 0; switch (maptyp) // iautyp depends upon maptyp indirectly { case 0: // Lat/Long -> dist unit == degrees iautyp = 0; // default to no area unit break; case 2: // State Plane -> dist unit == feet iautyp = 1; // default to acres acre = xcell * ycell; // acre = sq.feet at this pt // so now convert to acres acre = (float) ((double)acre * 0.0000229568411386593); break; default: // dist unit == meters iautyp = 2; // default to hectares acre = xcell * ycell; // acre = sq.meters at this pt // so now convert to hectares acre *= 0.0001f; break; } this.fileWriter.Write(iautyp); // acre this.fileWriter.Write(acre); // xmap System.Single xmap = 0; if ((metadata != null) && (metadata.TryGetValue<System.Single>(WORLD_ULX,ref xmap))) { } this.fileWriter.Write(xmap); // ymap System.Single ymap = 0; if ((metadata != null) && (metadata.TryGetValue<System.Single>(WORLD_ULY,ref ymap))) { } this.fileWriter.Write(ymap); // xcell this.fileWriter.Write(xcell); // ycell this.fileWriter.Write(ycell); // now create pixel data as zeroes for now // many nested for loops avoids index calc overflows for (int row = 0; row < dimensions.Rows; row++) for (int bandNum = 0; bandNum < this.bandCount; bandNum++) for (int col = 0; col < dimensions.Columns; col++) for (int byteNum = 0; byteNum < this.bandSize; byteNum++) this.fileWriter.Write((byte)0); } catch (System.Exception) { Close(); throw; } }
public ProfileParameter(string name, System.TypeCode type, string propertyName) { }
/// <summary> /// Formats the log event as a JSON document for writing. /// </summary> /// <param name="logEvent">The log event to be formatted.</param> /// <returns>A JSON string representation of the log event.</returns> protected override string GetFormattedMessage(LogEventInfo logEvent) { StringBuilder sb = null; //Memory profiling pointed out that using a foreach-loop was allocating //an Enumerator. Switching to a for-loop avoids the memory allocation. for (int i = 0; i < this.Attributes.Count; i++) { var attrib = this.Attributes[i]; string text = attrib.LayoutWrapper.Render(logEvent); if (!string.IsNullOrEmpty(text)) { bool first = sb == null; if (first) { sb = new StringBuilder(attrib.Name.Length + text.Length + 10); sb.Append(SuppressSpaces ? "{" : "{ "); } AppendJsonAttributeValue(attrib, text, sb, first); } } if (this.IncludeAllProperties && logEvent.HasProperties) { JsonAttribute dynAttrib = null; foreach (var prop in logEvent.Properties) { //Determine property name string propName = prop.Key.ToString(); //Skips properties in the ExcludeProperties list if (this.ExcludeProperties.Contains(propName)) { continue; } if (dynAttrib == null) { dynAttrib = new JsonAttribute(); } if (prop.Value == null) { dynAttrib.Name = propName; dynAttrib.Encode = false; // Don't put quotes around null values; dynAttrib.Layout = "null"; } else { System.Type objType = prop.Value.GetType(); System.TypeCode objTypeCode = System.Type.GetTypeCode(objType); if (objTypeCode == System.TypeCode.Boolean || IsNumeric(objType, objTypeCode)) { dynAttrib.Name = propName; dynAttrib.Encode = false; //Don't put quotes around numbers or boolean values dynAttrib.Layout = string.Concat("${event-properties:item=", propName, "}"); } else { dynAttrib.Name = propName; dynAttrib.Encode = true; dynAttrib.Layout = string.Concat("${event-properties:item=", propName, "}"); } } string text = dynAttrib.LayoutWrapper.Render(logEvent); if (!string.IsNullOrEmpty(text)) { bool first = sb == null; if (first) { sb = new StringBuilder(dynAttrib.Name.Length + text.Length + 10); sb.Append(SuppressSpaces ? "{" : "{ "); } AppendJsonAttributeValue(dynAttrib, text, sb, first); } } } if (sb == null) { if (!RenderEmptyObject) { return(string.Empty); } else { return(SuppressSpaces ? "{}" : "{ }"); } } sb.Append(SuppressSpaces ? "}" : " }"); return(sb.ToString()); }