public static object Bind(ISerializeData Data, Type Type) { if (Data == null) { throw new NullReferenceException("Data cannot be null"); } if (Type.IsArray != (Data is ISerializeArray)) { throw new ArgumentException("Type [" + Type + "] and [" + Data.GetType() + "] are not same"); } Type elementType = (Type.IsArray ? Type.GetElementType() : Type); if (Data is ISerializeObject) { ISerializeObject obj = (ISerializeObject)Data; if (obj.Contains(TYPE_FIELD_NAME)) { string typeName = obj.Get <string>(TYPE_FIELD_NAME); elementType = Type.GetType(typeName); if (elementType == null) { throw new ArgumentException(string.Format("Couldn't find Specified type {0}", typeName), TYPE_FIELD_NAME); } } return(Bind(obj, elementType)); } return(Bind((ISerializeArray)Data, Type)); }
public static void Override(ISerializeObject Data, ISerializeObject On) { var it = Data.GetEnumerator(); while (it.MoveNext()) { string key = it.Current.Key; object value = it.Current.Value; object onValue = On.Get <object>(key); if (value is ISerializeObject) { ISerializeObject onObj = null; if (onValue != null) { if (onValue is ISerializeObject) { onObj = (ISerializeObject)onValue; } else { Data.Remove(key); it = Data.GetEnumerator(); } } if (onObj == null) { onObj = On.AddObject(key); } Override((ISerializeData)value, onObj); } else if (value is ISerializeArray) { if (onValue != null) { Data.Remove(key); } it = Data.GetEnumerator(); Override((ISerializeData)value, On.AddArray(key)); } else { On.Set(key, value); } } }
private static object Bind(ISerializeObject Object, Type Type) { object obj = Activator.CreateInstance(Type); MemberInfo[] members = Type.GetMemberVariables(ReflectionExtensions.AllNonStaticFlags); for (int i = 0; i < members.Length; ++i) { MemberInfo member = members[i]; if (!Object.Contains(member.Name)) { continue; } Type memberType = null; if (member is FieldInfo) { memberType = ((FieldInfo)member).FieldType; } else if (member is PropertyInfo) { PropertyInfo propertyInfo = (PropertyInfo)member; if (!propertyInfo.CanWrite) { continue; } memberType = propertyInfo.PropertyType; } object value = Cast(Object.Get <object>(member.Name), memberType); if (member is FieldInfo) { ((FieldInfo)member).SetValue(obj, value); } else if (member is PropertyInfo) { ((PropertyInfo)member).SetValue(obj, value, null); } } return(obj); }
public static string GetRefreshToken(string Code, string ClientID, string ClientSecret, string RedirectURI) { Requests.ParameterMap parameters = new Requests.ParameterMap(); parameters["grant_type"] = "authorization_code"; parameters["code"] = Code; parameters["client_id"] = ClientID; parameters["client_secret"] = ClientSecret; parameters["redirect_uri"] = RedirectURI; string data = Requests.Post(TOKEN_URL, null, parameters); ISerializeObject obj = Creator.Create <ISerializeObject>(data); if (obj.Contains("refresh_token")) { return(obj.Get <string>("refresh_token")); } return(""); }
private bool MustCompile() { if (!File.Exists(EnvironmentHelper.FinalOutputDirectory + SelectedRule.TargetName + GetExtension(this))) { return(true); } string hashesFilePath = intermediateModulePath + HashesFileName; ISerializeObject hashesData = null; if (File.Exists(hashesFilePath)) { hashesData = Creator.Create <ISerializeObject>(File.ReadAllText(hashesFilePath)); } if (hashesData == null) { hashesData = Creator.Create <ISerializeObject>(); } bool result = false; string configurationTypeName = typeof(ProjectBase.ProfileBase.BuildConfigurations).Name; if (!hashesData.Contains(configurationTypeName) || hashesData.Get <int>(configurationTypeName) != (int)BuildSystem.BuildConfiguration) { result = true; } hashesData.Set(configurationTypeName, (int)BuildSystem.BuildConfiguration); string platformTypeName = typeof(ProjectBase.ProfileBase.PlatformTypes).Name; if (!hashesData.Contains(platformTypeName) || hashesData.Get <int>(platformTypeName) != (int)BuildSystem.PlatformType) { result = true; } hashesData.Set(platformTypeName, (int)BuildSystem.PlatformType); if (!result) { List <string> extensions = new List <string>(); extensions.AddRange(EnvironmentHelper.HeaderFileExtensions); extensions.AddRange(EnvironmentHelper.CompileFileExtensions); extensions.AddRange(EnvironmentHelper.CSharpFileExtensions); string[] files = FileSystemUtilites.GetAllFiles(sourcePathRoot, extensions.ToArray()); foreach (string file in files) { string filePathHash = GetHash(file).ToString(); int contentHash = GetHash(File.ReadAllText(file)); if (hashesData.Contains(filePathHash) && hashesData.Get <int>(filePathHash) == contentHash) { continue; } hashesData.Set(filePathHash, contentHash); result = true; } } File.WriteAllText(hashesFilePath, hashesData.Content); return(result); }