Skip to content

Commit

Permalink
fix: support 2019.1
Browse files Browse the repository at this point in the history
  • Loading branch information
mob-sakai authored and mob-sakai committed Jan 28, 2020
1 parent f4b25ef commit 5ff79fb
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class AvailableVersion : IEquatable<AvailableVersion>
public string repoUrl = "";

public string refNameText { get { return version == refName ? version : version + " - " + refName; } }
public string refNameVersion { get { return version == refName ? version : version + "-" + refName; } }

bool IEquatable<AvailableVersion>.Equals(AvailableVersion other)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,7 @@ internal static SemVersion GetVersion(this PackageInfo self)
internal static void UpdateVersions(this Package self, IEnumerable<PackageInfo> versions)
{
versions.OrderBy(v => v.GetVersion()).Last().IsLatest = true;
self.source = versions;
self.UpdateSource(versions);
self.Set("source", versions);
}

internal static void UpdatePackageCollection()
Expand All @@ -245,7 +244,7 @@ internal static void UpdatePackageCollection()
internal static PackageInfo ToPackageVersion(this AvailableVersion self, PackageInfo baseInfo)
{
var newPInfo = JsonUtility.FromJson<PackageInfo>(JsonUtility.ToJson(baseInfo));
newPInfo.Version = SemVersion.Parse(self.refNameText);
newPInfo.Version = SemVersion.Parse(self.refNameVersion);
#if UNITY_2019_2_OR_NEWER
newPInfo.IsInstalled = false;
#else
Expand Down
53 changes: 53 additions & 0 deletions Packages/com.coffee.upm-git-extension/Editor/Scripts/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.IO;
using System.Linq;
using System.Diagnostics;
using System.Reflection;
#if UNITY_2019_1_OR_NEWER
using UnityEngine.UIElements;
#else
Expand Down Expand Up @@ -68,6 +69,58 @@ public static void Exception(string header, Exception e)
}
}

internal static class ReflectionExtensions
{
const BindingFlags FLAGS = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
static object Inst(this object self)
{
return (self is Type) ? null : self;
}

static Type Type(this object self)
{
return (self as Type) ?? self.GetType();
}

public static object New(this Type self, params object[] args)
{
var types = args.Select(x => x.GetType()).ToArray();
return self.Type().GetConstructor(types)
.Invoke(args);
}

public static object Call(this object self, string methodName, params object[] args)
{
var types = args.Select(x => x.GetType()).ToArray();
return self.Type().GetMethod(methodName, types)
.Invoke(self.Inst(), args);
}

public static object Call(this object self, Type[] genericTypes, string methodName, params object[] args)
{
return self.Type().GetMethod(methodName, FLAGS)
.MakeGenericMethod(genericTypes)
.Invoke(self.Inst(), args);
}

public static object Get(this object self, string memberName, MemberInfo mi = null)
{
mi = mi ?? self.Type().GetMember(memberName, FLAGS)[0];
return mi is PropertyInfo
? (mi as PropertyInfo).GetValue(self.Inst(), new object[0])
: (mi as FieldInfo).GetValue(self.Inst());
}

public static void Set(this object self, string memberName, object value, MemberInfo mi = null)
{
mi = mi ?? self.Type().GetMember(memberName, FLAGS)[0];
if (mi is PropertyInfo)
(mi as PropertyInfo).SetValue(self.Inst(), value, new object[0]);
else
(mi as FieldInfo).SetValue(self.Inst(), value);
}
}

public static class PackageUtils
{
const string kHeader = "<b><color=#c7634c>[PackageUtils]</color></b> ";
Expand Down

0 comments on commit 5ff79fb

Please sign in to comment.