public void LerpView(string viewName) { currentViewname = viewName; string n = viewName.ToLower(); switch (n) { case "user": LerpRotation(userRotation); LerpDistance(userDistance); LerpTarget(userTarget); return; default: for (int i = 0; i < knownCameraViews.Count; ++i) { if (knownCameraViews[i].name.ToLower().Equals(n)) { //Debug.Log("doing " + n + " "+Show.Stringify(knownCameraViews[i])); LerpTo(knownCameraViews[i]); return; } } break; } ReflectionParseExtension.TryConvertEnumWildcard(typeof(Direction3D), viewName, out object v); if (v != null) { LerpDirection((Direction3D)v); return; } Debug.LogWarning($"unkown view name \"{viewName}\""); }
public static bool TryConvert(object value, out object desiredValue, Type typeToGet) { //public static bool TryConvert(ref object value, Type typeToGet) { // if (value != null && value.GetType() == typeToGet) return true; if (value != null && value.GetType() == typeToGet) { desiredValue = value; return(true); } desiredValue = default; try { if (typeToGet.IsEnum) { string str = value as string; if (str != null && ReflectionParseExtension.TryConvertEnumWildcard(typeToGet, str, out desiredValue)) { return(true); } return(false); } switch (Type.GetTypeCode(typeToGet)) { case TypeCode.Boolean: case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Char: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: case TypeCode.UInt32: case TypeCode.Single: case TypeCode.Int64: case TypeCode.UInt64: case TypeCode.Double: case TypeCode.String: desiredValue = System.Convert.ChangeType(value, typeToGet); break; default: if (value is string s && Deserialization.TryGetValue(typeToGet, out TryParseFunction f)) { return(f.Invoke(s, out desiredValue)); } if (TryConvertIList(value, out desiredValue, typeToGet)) { return(true); } return(false); } } catch { return(false); } return(true); }
protected void AssignValueToMember() { if (memberValue != null) { switch (memberValue) { case SyntaxTree syntax: memberValue = syntax.Resolve(tok, scope); break; case Token t: if (memberType != typeof(Token)) { memberValue = t.Resolve(tok, scope); } break; } } if (dictionaryAdd != null) { string s = memberId as string; ReflectionParseExtension.TrySetValue_Dictionary(result, ref memberId, memberValue); //string error = AssignValueToDictionary(dictionaryTypes, dictionaryAdd, result, memberId, memberValue, memberType); //if (error != null) { AddError(error); } } else { if (field != null) { ReflectionParseExtension.TrySetValueCompiled(result, field, memberValue); //AssignField(result, field, memberValue); } else if (prop != null) { ReflectionParseExtension.TrySetValueCompiled(result, prop, memberValue); //AssignProperty(result, prop, memberValue); } else { throw new Exception("huh? how did we get here?"); } field = null; prop = null; memberType = dictionaryTypes.Value; } memberId = null; memberToken.Invalidate(); }
public GameObject FindItem(string name) { if (items == null) { return(null); } if (ReflectionParseExtension.HasValidWildcard(name)) { List <string> options = items.ConvertAll(o => o.name); int index = ReflectionParseExtension.FindIndexWithWildcard(options, name, false); if (index >= 0) { return(items[index]); } } GameObject found = items.Find(i => i.name == name); return(found); }
protected Type SetResultType(string typeName) { Type t = Type.GetType(typeName); if (t == null) { Type[] childTypes = resultType.GetSubClasses(); string[] typeNames = Array.ConvertAll(childTypes, ty => ty.ToString()); char wildcard = ReflectionParseExtension.Wildcard; string nameSearch = typeName[0] != wildcard ? wildcard + typeName : typeName; int index = ReflectionParseExtension.FindIndexWithWildcard(typeNames, nameSearch, false); if (index >= 0) { t = childTypes[index]; } } if (t != null && (result == null || result.GetType() != t)) { SetResultType(t); result = resultType.GetNewInstance(); } return(t); }
public PropertyInfo GetProperty(string name) { int index = ReflectionParseExtension.FindIndexWithWildcard(propNames, name, true); return((index < 0) ? null : props[index]); }
public FieldInfo GetField(string name) { int index = ReflectionParseExtension.FindIndexWithWildcard(fieldNames, name, true); return((index < 0) ? null : fields[index]); }