/** * <summary>Loads the font data.</summary> */ private void Load( ) { try { ParseHeader(); Index nameIndex = Index.Parse(fontData); Index topDictIndex = Index.Parse(fontData); stringIndex = Index.Parse(fontData); #pragma warning disable 0219 Index globalSubrIndex = Index.Parse(fontData); string fontName = ToString(nameIndex[0]); #pragma warning restore 0219 Dict topDict = Dict.Parse(topDictIndex[0]); // int encodingOffset = topDict.get(Dict.OperatorEnum.Encoding, 0, 0).intValue(); //TODO: encoding int charsetOffset = (int)topDict.Get(Dict.OperatorEnum.Charset, 0, 0); StandardCharsetEnum?charset = GetStandardCharset(charsetOffset); if (charset.HasValue) { glyphIndexes = new Dictionary <int, int>(StandardCharsets[charset.Value]); } else { glyphIndexes = new Dictionary <int, int>(); int charStringsOffset = (int)topDict.Get(Dict.OperatorEnum.CharStrings, 0); Index charStringsIndex = Index.Parse(fontData, charStringsOffset); fontData.Seek(charsetOffset); int charsetFormat = fontData.ReadByte(); for (int index = 1, count = charStringsIndex.Count; index <= count;) { switch (charsetFormat) { case 0: glyphIndexes[index++] = ToUnicode(fontData.ReadUnsignedShort()); break; case 1: case 2: { int first = fontData.ReadUnsignedShort(); int nLeft = (charsetFormat == 1 ? fontData.ReadByte() : fontData.ReadUnsignedShort()); for (int rangeItemIndex = first, rangeItemEndIndex = first + nLeft; rangeItemIndex <= rangeItemEndIndex; rangeItemIndex++) { glyphIndexes[index++] = ToUnicode(rangeItemIndex); } } break; } } } } catch (Exception e) { throw e; } }
public void TestGet() { var dict = new Dictionary <string, object> { { "my", new Dictionary <string, object> { { "name", new Dictionary <string, object> { { "is", "catlib" } } }, { "age", new Dictionary <string, object> { { "is", 18 } } }, } } }; Assert.AreEqual("catlib", Dict.Get(dict, "my.name.is")); Assert.AreEqual(18, Dict.Get(dict, "my.age.is")); Assert.AreEqual("undefiend", Dict.Get(dict, "my.age.undefiend", "undefiend")); Assert.AreEqual("undefiend", Dict.Get(null, "my.age.undefiend", "undefiend")); Assert.AreEqual(dict, Dict.Get(dict, null, "undefiend")); Assert.AreEqual("undefiend", Dict.Get(dict, "my.age.is.name", "undefiend")); }
/// <summary>快速获取对象字段值</summary> /// <param name="fieldInfo">要获取的对象字段</param> /// <param name="instance">要获取的对象实例</param> /// <returns>属性值</returns> public static object FastGetValue(this FieldInfo fieldInfo, object instance) { if (fieldInfo == null) { return(null); } if (FGC == null) { FGC = new Dict <FieldInfo, Func <object, object> >(); } var exec = FGC.Get(fieldInfo, () => { var objType = typeof(object); var instanceParameter = Expression.Parameter(objType, "instance"); var instanceCast = fieldInfo.IsStatic ? null : Expression.Convert(instanceParameter, fieldInfo.ReflectedType); var fieldAccess = Expression.Field(instanceCast, fieldInfo); var castFieldValue = Expression.Convert(fieldAccess, objType); var lambda = Expression.Lambda <Func <object, object> >(castFieldValue, instanceParameter); return(lambda.Compile()); }); return(exec(instance)); }
public void TestSetRemove() { var dict = new Dictionary <string, object>(); Dict.Set(dict, "hello.world", "hello"); Dict.Set(dict, "hello.name", "catlib"); Dict.Set(dict, "hello.world.name", "c#"); Dict.Set(dict, "hello.world.just", "j#"); Assert.AreEqual(((Dictionary <string, object>)dict["hello"])["world"], Dict.Get(dict, "hello.world")); Assert.AreEqual("c#", Dict.Get(dict, "hello.world.name")); Assert.AreEqual("j#", Dict.Get(dict, "hello.world.just")); Assert.AreEqual("catlib", Dict.Get(dict, "hello.name")); Dict.Remove(dict, "hello.world.name"); Dict.Remove(dict, "hello.world.just"); Assert.AreEqual("undefiend", Dict.Get(dict, "hello.world", "undefiend")); Assert.AreEqual("catlib", Dict.Get(dict, "hello.name", "undefiend")); dict = new Dictionary <string, object>(); Dict.Set(dict, "hello.world.name.is", "hello"); Dict.Remove(dict, "hello.world.name.is"); Assert.AreEqual("undefiend", Dict.Get(dict, "hello", "undefiend")); Assert.AreEqual(false, Dict.Remove(dict, "notexists.notexists")); Assert.AreEqual(false, Dict.Remove(dict, "hello.name.is.world")); }
/// <summary>快速设置对象字段值</summary> /// <param name="fieldInfo">要设置的对象字段</param> /// <param name="instance">要设置的对象实例</param> /// <param name="value">要设置的值</param> public static void FastSetValue(this FieldInfo fieldInfo, object instance, object value) { if (fieldInfo == null) { return; } if (FSC == null) { FSC = new Dict <FieldInfo, Action <object, object> >(); } var exec = FSC.Get(fieldInfo, () => { var objType = typeof(object); var instanceParameter = Expression.Parameter(objType, "instance"); var valueParameter = Expression.Parameter(objType, "value"); var instanceCast = fieldInfo.IsStatic ? null : Expression.Convert(instanceParameter, fieldInfo.ReflectedType); var valueCast = Expression.Convert(valueParameter, fieldInfo.FieldType); var fieldAccess = Expression.Field(instanceCast, fieldInfo); var fieldAssign = Expression.Assign(fieldAccess, valueCast); var lambda = Expression.Lambda <Action <object, object> >(fieldAssign, instanceParameter, valueParameter); return(lambda.Compile()); }); exec(instance, value); }
/// <summary>通过类的构造器信息创建对象实例</summary> /// <param name="constructorInfo">构造器信息</param> /// <param name="parameters">参数</param> /// <returns>新对象实例</returns> public static object FastInvoke(this ConstructorInfo constructorInfo, params object[] parameters) { if (OC == null) { OC = new Dict <ConstructorInfo, Func <object[], object> >(); } var exec = OC.Get(constructorInfo, () => { var parametersParameter = Expression.Parameter(typeof(object[]), "parameters"); var parameterExpressions = new List <Expression>(); var paramInfos = constructorInfo.GetParameters(); for (int i = 0, l = paramInfos.Length; i < l; i++) { var valueObj = Expression.ArrayIndex(parametersParameter, Expression.Constant(i)); var valueCast = Expression.Convert(valueObj, paramInfos[i].ParameterType); parameterExpressions.Add(valueCast); } var instanceCreate = Expression.New(constructorInfo, parameterExpressions); var instanceCreateCast = Expression.Convert(instanceCreate, typeof(object)); var lambda = Expression.Lambda <Func <object[], object> >(instanceCreateCast, parametersParameter); return(lambda.Compile()); }); return(exec(parameters)); }
public void TestDictionaryGetException() { var d = new Dict <int, int>(); d.Add(1, 2); d.Add(2, 3); d.Get(3); }
int GetFuelCost() { float amount = 0; foreach (string res in load.Keys) { if (res == "population") { amount += load.Get(res) * GameController.FUEL_COST_PER_POP; } else { amount += load.Get(res) * GameController.FUEL_COST_PER_RESOURCE; } } return((int)amount + GameController.CONSTANT_FUEL_COST); }
private void TryUpdateValue() { if (m_DictId.HaveValue) { string dictId = m_DictId.Value.Get <string>(); m_HaveValue = true; m_Value = Dict.Get(dictId); } }
private void TryUpdateValue() { if (m_DictId.HaveValue) { object dictId = m_DictId.Value; m_HaveValue = true; m_Value = Dict.Get((string)dictId); } }
private void TryUpdateValue(StoryInstance instance) { if (m_DictId.HaveValue) { m_HaveValue = true; m_Value = null; string dictId = m_DictId.Value; m_Value = Dict.Get(dictId); } }
/// <summary>快速调用对象实例的方法</summary> /// <param name="methodInfo">要调用的方法</param> /// <param name="instance">对象实例</param> /// <param name="parameters">参数</param> /// <returns>方法执行的结果</returns> public static object FastInvoke(this MethodInfo methodInfo, object instance, params object[] parameters) { if (methodInfo == null) { return(null); } if (MC == null) { MC = new Dict <MethodInfo, Func <object, object[], object> >(); } var exec = MC.Get(methodInfo, () => { var objectType = typeof(object); var objectsType = typeof(object[]); var instanceParameter = Expression.Parameter(objectType, "instance"); var parametersParameter = Expression.Parameter(objectsType, "parameters"); var parameterExpressions = new List <Expression>(); var paramInfos = methodInfo.GetParameters(); for (int i = 0, l = paramInfos.Length; i < l; i++) { var valueObj = Expression.ArrayIndex(parametersParameter, Expression.Constant(i)); var valueCast = Expression.Convert(valueObj, paramInfos[i].ParameterType); parameterExpressions.Add(valueCast); } var instanceCast = methodInfo.IsStatic ? null : Expression.Convert(instanceParameter, methodInfo.ReflectedType); var methodCall = Expression.Call(instanceCast, methodInfo, parameterExpressions); if (methodCall.Type == typeof(void)) { var lambda = Expression.Lambda <Action <object, object[]> >(methodCall, instanceParameter, parametersParameter); var act = lambda.Compile(); return((inst, para) => { act(inst, para); return null; }); } else { var castMethodCall = Expression.Convert(methodCall, objectType); var lambda = Expression.Lambda <Func <object, object[], object> >( castMethodCall, instanceParameter, parametersParameter); return(lambda.Compile()); } }); return(exec(instance, parameters)); }
public void GoToPlanet(Planet p) { foreach (string res in load.Keys) { p.ChangeAmountOf(res, load.Get(res)); } if (p != GameController.instance.GetCurrentPlanet()) { GameController.instance.SwitchToPlanet(p); } Destroy(gameObject); }
public void SetAmountVisual(string resource, int newAmount) { if (resource == "homeless") { resourceText.Get(resource) [0].text = (100f * ((float)newAmount) / GameController.instance.GetCurrentPlanet().GetAmountOf("population")).ToString("F1") + "%"; } else { resourceText.Get(resource) [0].text = newAmount.ToString(); } }
static public int Get_s(IntPtr l) { try { System.String a1; checkType(l, 1, out a1); var ret = Dict.Get(a1); pushValue(l, true); pushValue(l, ret); return(2); } catch (Exception e) { return(error(l, e)); } }
/// <summary>获取类型的访问器集合</summary> /// <param name="type">要获取的类型</param> /// <returns>类型的访问器集合</returns> public static Dictionary <string, Accessor> FastGetAccessors(this Type type) { if (AC == null) { AC = new Dict <string, Dictionary <string, Accessor> >(StringComparer.OrdinalIgnoreCase); } var typeName = type.FullName; return(AC.Get(typeName, () => { var ls = new Dictionary <string, Accessor>(StringComparer.OrdinalIgnoreCase); var props = type.GetProperties(BindingFlags.Public | BindingFlags.Instance); var name = string.Empty; foreach (var p in props) { name = p.Name; var a = new Accessor { Name = name, Member = p, DataType = p.PropertyType, AccessorType = AccessorType.Property, CanRade = p.CanRead, CanWrite = p.CanWrite, IsVirtual = p.IsVirtual_() }; ls.Add(name, a); } var fis = type.GetFields(BindingFlags.Public | BindingFlags.Instance); foreach (var f in fis) { name = f.Name; var a = new Accessor { Name = name, Member = f, DataType = f.FieldType, AccessorType = AccessorType.Field, CanRade = true, CanWrite = true, IsVirtual = false }; ls.Add(name, a); } return ls; })); }
internal Dictionary <string, JsonAccessor> GetJsonAccessors(Type type) { var typeName = type.FullName; return(AC.Get(typeName, () => { var ls = type.FastGetAccessors(); var jas = new Dictionary <string, JsonAccessor>(ls.Count, StringComparer.OrdinalIgnoreCase); foreach (var a in ls.Values) { jas.Add(a.Name, GetJsonAccessor(a)); } return jas; })); }
public string AddXObject(PdfReference xref) { var resources = Dict.Get <PdfDictionary>("/Resources"); var xobjects = resources.Get <PdfDictionary>("/XObject"); if (xobjects == null) { xobjects = new PdfDictionary(); resources["/XObject"] = xobjects; } string key = "/Xo" + xref.ObjectNumber; xobjects[key] = xref; return(key); }
/// <summary>通过类型的程序集限定名称获取类型</summary> /// <param name="typeName">要获取的类型的程序集限定名称</param> /// <returns>类型</returns> /// <exception cref="ArgumentNullOrEmptyException">类型的程序集限定名称为 null 或为空</exception> public static Type FastGetType(string typeName) { if (string.IsNullOrEmpty(typeName)) { throw new ArgumentNullException("typeName is null or empty"); } if (NTC == null) { NTC = new Dict <string, Type>(StringComparer.OrdinalIgnoreCase); } typeName = typeName.Trim(); return(NTC.Get(typeName, () => { return Type.GetType(typeName, true, true); })); }
// Generates the resource at a random location. void GenerateResource() { // First choose the resource based on the relative abundancies given. float rand = Random.Range(0f, resourceAbundancyTotal); float c = 0f; string selectedResource = ""; foreach (string resource in relativeResourceAbundancy.Keys) { c += relativeResourceAbundancy.Get(resource); if (c >= rand) { selectedResource = resource; break; } } // Now find a tile to place the resource on. int fails = 0; int x = 0; int y = 0; while (true) { // Get a random tile. x = Random.Range(0, sizeX); y = Random.Range(0, sizeY); if (GetTileAt(x, y).tileType != "water" || selectedResource == "oil") { break; } if (fails > 100) { return; } fails += 1; } GetTileAt(x, y).resource = selectedResource; }
/// <summary>快速获取对象属性值</summary> /// <param name="propertyInfo">要获取的对象属性</param> /// <param name="instance">要获取的对象实例</param> /// <returns>属性值</returns> public static object FastGetValue(this PropertyInfo propertyInfo, object instance) { if (propertyInfo == null) { return(null); } if (!propertyInfo.CanRead) { return(null); } if (PGC == null) { PGC = new Dict <PropertyInfo, Func <object, object> >(); } var exec = PGC.Get(propertyInfo, () => { if (propertyInfo.GetIndexParameters().Length > 0) { // 对索引属性直接返回默认值 return((inst) => { return null; }); } else { var objType = typeof(object); var instanceParameter = Expression.Parameter(objType, "instance"); var instanceCast = propertyInfo.GetGetMethod(true).IsStatic ? null : Expression.Convert(instanceParameter, propertyInfo.ReflectedType); var propertyAccess = Expression.Property(instanceCast, propertyInfo); var castPropertyValue = Expression.Convert(propertyAccess, objType); var lambda = Expression.Lambda <Func <object, object> >(castPropertyValue, instanceParameter); return(lambda.Compile()); } }); return(exec(instance)); }
/// <summary>快速设置对象属性值</summary> /// <param name="propertyInfo">要设置的对象属性</param> /// <param name="instance">要设置的对象实例</param> /// <param name="value">要设置的值</param> public static void FastSetValue(this PropertyInfo propertyInfo, object instance, object value) { if (propertyInfo == null) { return; } if (!propertyInfo.CanWrite) { return; } if (PSC == null) { PSC = new Dict <PropertyInfo, Action <object, object> >(); } var exec = PSC.Get(propertyInfo, () => { if (propertyInfo.GetIndexParameters().Length > 0) { // 对索引属性直接无视 return((inst, para) => { }); } else { var objType = typeof(object); var instanceParameter = Expression.Parameter(objType, "instance"); var valueParameter = Expression.Parameter(objType, "value"); var instanceCast = propertyInfo.GetSetMethod(true).IsStatic ? null : Expression.Convert(instanceParameter, propertyInfo.ReflectedType); var valueCast = Expression.Convert(valueParameter, propertyInfo.PropertyType); var propertyAccess = Expression.Property(instanceCast, propertyInfo); var propertyAssign = Expression.Assign(propertyAccess, valueCast); var lambda = Expression.Lambda <Action <object, object> >(propertyAssign, instanceParameter, valueParameter); return(lambda.Compile()); } }); exec(instance, value); }
public void OnClickQuit() { int desId = 8; if (WorldSystem.Instance.IsMultiPveScene()) { desId = 878; } LogicSystem.EventChannelForGfx.Publish("ge_show_dialog", "ui", Dict.Get(desId), null, Dict.Get(4), Dict.Get(9), (MyAction <int>)((int btn) => { if (btn == 1) { if (WorldSystem.Instance.IsMultiPveScene()) { LogicSystem.PublishLogicEvent("ge_quit_battle", "lobby", true); } else { LogicSystem.PublishLogicEvent("ge_quit_battle", "lobby", false); } } }), false); }
/// <summary> /// Set the channel properties /// </summary> /// <param name="channel"></param> public static void SetChannel(Dict channel) { // validate channel's properties var data = new Complex[BlocksPerSymbol]; foreach(var curr in channel.Keys()) { int index; double value; if (!int.TryParse(curr, out index)) throw new Exception(String.Format("Channel quality indexes must be integers. '{0}' is not a valid integer!", curr)); if (index >= data.Length) throw new Exception("Key exceeds array length"); if (!double.TryParse(channel.Get(curr), out value)) throw new Exception(String.Format("Channel quality values must be floats. '{0}' is not a valid float!", curr)); data[index] = new Complex(value, 0); } // reverse-transform to get SNRs var fft = new MathNet.Numerics.IntegralTransforms.Algorithms.DiscreteFourierTransform(); fft.BluesteinInverse(data, MathNet.Numerics.IntegralTransforms.FourierOptions.Default); ChannelQuality = data.Select(p => p.Magnitude).ToArray(); }
public int GetAmountOf(string resource) { return(stockpile.Get(resource).amount); }
Pdf.IntImage GetImage() { ReadPng(); CheckIccProfile(); ProcessTrans(); Channels = ChannelsFromColorType[ColorType]; bool needDecode = InterlaceMethod == 1 || BitDepth == 16 || (ColorType & 4) != 0 || PalShades || GenBWMask; if (needDecode) { DecodeIdat(); } else { Image = Idat.ToArray(); } int components = Channels; if ((ColorType & 4) != 0) { components -= 1; } int bpc = BitDepth == 16 ? 8 : BitDepth; // Create the PdfImage Pdf.IntImage result = new Pdf.IntImage(Width, Height, components, bpc, Image); if (!needDecode) { result.Deflated = true; Dict decodeparms = new Dict(); decodeparms.Put(DictName.BitsPerComponent, BitDepth); decodeparms.Put(DictName.Predictor, 15); decodeparms.Put(DictName.Columns, Width); decodeparms.Put(DictName.Colors, (ColorType == 3 || (ColorType & 2) == 0) ? 1 : 3); Additional.Put(DictName.DecodeParms, decodeparms); } if (Additional.Get(DictName.ColorSpace) == null) { Additional.Put(DictName.ColorSpace, GetColorspace()); } if (Intent != null) { Additional.Put(DictName.Intent, Intent); } if (Additional.D.Count > 0) { result.Additional = Additional; } if (ICCP != null) { result.ICCP = ICCP; } if (PalShades || GenBWMask) { IntImage m = new IntImage(Width, Height, 1, GenBWMask ? 1 : 8, Smask); m.IsMask = true; result.ImageMask = m; } result.SetDpi(DpiX, DpiY); result.XYRatio = XYRatio; return(result); }