Add VRChat and GitHub packages to Unity project
This commit is contained in:
1 parent
0334a52b21
commit
85538aaccc
3297 files changed
+847877
No files matched your search
@@ -0,0 +1,70 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// <copyright file="FieldInfoExtensions.cs" company="Sirenix IVS">
|
||||
// Copyright (c) 2018 Sirenix IVS
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// </copyright>
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
namespace VRC.Udon.Serialization.OdinSerializer.Utilities
|
||||
{
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
/// <summary>
|
||||
/// FieldInfo method extensions.
|
||||
/// </summary>
|
||||
public static class FieldInfoExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Determines whether the specified field is an alias.
|
||||
/// </summary>
|
||||
/// <param name="fieldInfo">The field to check.</param>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the specified field is an alias; otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
public static bool IsAliasField(this FieldInfo fieldInfo)
|
||||
{
|
||||
return fieldInfo is MemberAliasFieldInfo;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the original, backing field of an alias field if the field is an alias.
|
||||
/// </summary>
|
||||
/// <param name="fieldInfo">The field to check.</param>
|
||||
/// /// <param name="throwOnNotAliased">if set to <c>true</c> an exception will be thrown if the field is not aliased.</param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="System.ArgumentException">The field was not aliased; this only occurs if throwOnNotAliased is true.</exception>
|
||||
public static FieldInfo DeAliasField(this FieldInfo fieldInfo, bool throwOnNotAliased = false)
|
||||
{
|
||||
MemberAliasFieldInfo aliasFieldInfo = fieldInfo as MemberAliasFieldInfo;
|
||||
|
||||
if (aliasFieldInfo != null)
|
||||
{
|
||||
while (aliasFieldInfo.AliasedField is MemberAliasFieldInfo)
|
||||
{
|
||||
aliasFieldInfo = aliasFieldInfo.AliasedField as MemberAliasFieldInfo;
|
||||
}
|
||||
|
||||
return aliasFieldInfo.AliasedField;
|
||||
}
|
||||
|
||||
if (throwOnNotAliased)
|
||||
{
|
||||
throw new ArgumentException("The field " + fieldInfo.GetNiceName() + " was not aliased.");
|
||||
}
|
||||
|
||||
return fieldInfo;
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 78ce67c0b3c1975c520a08d1ff9fd24e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+330
@@ -0,0 +1,330 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// <copyright file="GarbageFreeIterators.cs" company="Sirenix IVS">
|
||||
// Copyright (c) 2018 Sirenix IVS
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// </copyright>
|
||||
//-----------------------------------------------------------------------
|
||||
namespace VRC.Udon.Serialization.OdinSerializer.Utilities
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
/// <summary>
|
||||
/// Garbage free enumerator methods.
|
||||
/// </summary>
|
||||
public static class GarbageFreeIterators
|
||||
{
|
||||
/// <summary>
|
||||
/// Garbage free enumerator for lists.
|
||||
/// </summary>
|
||||
public static ListIterator<T> GFIterator<T>(this List<T> list)
|
||||
{
|
||||
return new ListIterator<T>(list);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Garbage free enumerator for dictionaries.
|
||||
/// </summary>
|
||||
public static DictionaryIterator<T1, T2> GFIterator<T1, T2>(this Dictionary<T1, T2> dictionary)
|
||||
{
|
||||
return new DictionaryIterator<T1, T2>(dictionary);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Garbage free enumator for dictionary values.
|
||||
/// </summary>
|
||||
public static DictionaryValueIterator<T1, T2> GFValueIterator<T1, T2>(this Dictionary<T1, T2> dictionary)
|
||||
{
|
||||
return new DictionaryValueIterator<T1, T2>(dictionary);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Garbage free enumerator for hashsets.
|
||||
/// </summary>
|
||||
public static HashsetIterator<T> GFIterator<T>(this HashSet<T> hashset)
|
||||
{
|
||||
return new HashsetIterator<T>(hashset);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// List iterator.
|
||||
/// </summary>
|
||||
public struct ListIterator<T> : IDisposable
|
||||
{
|
||||
private bool isNull;
|
||||
private List<T> list;
|
||||
private List<T>.Enumerator enumerator;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list iterator.
|
||||
/// </summary>
|
||||
public ListIterator(List<T> list)
|
||||
{
|
||||
this.isNull = list == null;
|
||||
if (this.isNull)
|
||||
{
|
||||
this.list = null;
|
||||
this.enumerator = new List<T>.Enumerator();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.list = list;
|
||||
this.enumerator = this.list.GetEnumerator();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the enumerator.
|
||||
/// </summary>
|
||||
public ListIterator<T> GetEnumerator()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current value.
|
||||
/// </summary>
|
||||
public T Current
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.enumerator.Current;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves to the next value.
|
||||
/// </summary>
|
||||
public bool MoveNext()
|
||||
{
|
||||
if (this.isNull)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return this.enumerator.MoveNext();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disposes the iterator.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
this.enumerator.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hashset iterator.
|
||||
/// </summary>
|
||||
public struct HashsetIterator<T> : IDisposable
|
||||
{
|
||||
private bool isNull;
|
||||
private HashSet<T> hashset;
|
||||
private HashSet<T>.Enumerator enumerator;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a hashset iterator.
|
||||
/// </summary>
|
||||
public HashsetIterator(HashSet<T> hashset)
|
||||
{
|
||||
this.isNull = hashset == null;
|
||||
if (this.isNull)
|
||||
{
|
||||
this.hashset = null;
|
||||
this.enumerator = new HashSet<T>.Enumerator();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.hashset = hashset;
|
||||
this.enumerator = this.hashset.GetEnumerator();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the enumerator.
|
||||
/// </summary>
|
||||
public HashsetIterator<T> GetEnumerator()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current value.
|
||||
/// </summary>
|
||||
public T Current
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.enumerator.Current;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves to the next value.
|
||||
/// </summary>
|
||||
public bool MoveNext()
|
||||
{
|
||||
if (this.isNull)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return this.enumerator.MoveNext();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disposes the iterator.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
this.enumerator.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dictionary iterator.
|
||||
/// </summary>
|
||||
public struct DictionaryIterator<T1, T2> : IDisposable
|
||||
{
|
||||
private Dictionary<T1, T2> dictionary;
|
||||
private Dictionary<T1, T2>.Enumerator enumerator;
|
||||
private bool isNull;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a dictionary iterator.
|
||||
/// </summary>
|
||||
public DictionaryIterator(Dictionary<T1, T2> dictionary)
|
||||
{
|
||||
this.isNull = dictionary == null;
|
||||
|
||||
if (this.isNull)
|
||||
{
|
||||
this.dictionary = null;
|
||||
this.enumerator = new Dictionary<T1, T2>.Enumerator();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.dictionary = dictionary;
|
||||
this.enumerator = this.dictionary.GetEnumerator();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the enumerator.
|
||||
/// </summary>
|
||||
public DictionaryIterator<T1, T2> GetEnumerator()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current value.
|
||||
/// </summary>
|
||||
public KeyValuePair<T1, T2> Current
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.enumerator.Current;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves to the next value.
|
||||
/// </summary>
|
||||
public bool MoveNext()
|
||||
{
|
||||
if (this.isNull)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return this.enumerator.MoveNext();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disposes the iterator.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
this.enumerator.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dictionary value iterator.
|
||||
/// </summary>
|
||||
public struct DictionaryValueIterator<T1, T2> : IDisposable
|
||||
{
|
||||
private Dictionary<T1, T2> dictionary;
|
||||
private Dictionary<T1, T2>.Enumerator enumerator;
|
||||
private bool isNull;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a dictionary value iterator.
|
||||
/// </summary>
|
||||
public DictionaryValueIterator(Dictionary<T1, T2> dictionary)
|
||||
{
|
||||
this.isNull = dictionary == null;
|
||||
|
||||
if (this.isNull)
|
||||
{
|
||||
this.dictionary = null;
|
||||
this.enumerator = new Dictionary<T1, T2>.Enumerator();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.dictionary = dictionary;
|
||||
this.enumerator = this.dictionary.GetEnumerator();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the enumerator.
|
||||
/// </summary>
|
||||
public DictionaryValueIterator<T1, T2> GetEnumerator()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current value.
|
||||
/// </summary>
|
||||
public T2 Current
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.enumerator.Current.Value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves to the next value.
|
||||
/// </summary>
|
||||
public bool MoveNext()
|
||||
{
|
||||
if (this.isNull)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return this.enumerator.MoveNext();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disposes the iterator.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
this.enumerator.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 068f5645a5c3f9ce36a580ec57e775d1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,79 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// <copyright file="LinqExtensions.cs" company="Sirenix IVS">
|
||||
// Copyright (c) 2018 Sirenix IVS
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// </copyright>
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
namespace VRC.Udon.Serialization.OdinSerializer.Utilities
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
/// <summary>
|
||||
/// Various LinQ extensions.
|
||||
/// </summary>
|
||||
public static class LinqExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Perform an action on each item.
|
||||
/// </summary>
|
||||
/// <param name="source">The source.</param>
|
||||
/// <param name="action">The action to perform.</param>
|
||||
public static IEnumerable<T> ForEach<T>(this IEnumerable<T> source, Action<T> action)
|
||||
{
|
||||
foreach (var item in source)
|
||||
{
|
||||
action(item);
|
||||
}
|
||||
|
||||
return source;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Perform an action on each item.
|
||||
/// </summary>
|
||||
/// <param name="source">The source.</param>
|
||||
/// <param name="action">The action to perform.</param>
|
||||
public static IEnumerable<T> ForEach<T>(this IEnumerable<T> source, Action<T, int> action)
|
||||
{
|
||||
int counter = 0;
|
||||
|
||||
foreach (var item in source)
|
||||
{
|
||||
action(item, counter++);
|
||||
}
|
||||
|
||||
return source;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a collection to the end of another collection.
|
||||
/// </summary>
|
||||
/// <param name="source">The collection.</param>
|
||||
/// <param name="append">The collection to append.</param>
|
||||
public static IEnumerable<T> Append<T>(this IEnumerable<T> source, IEnumerable<T> append)
|
||||
{
|
||||
foreach (var item in source)
|
||||
{
|
||||
yield return item;
|
||||
}
|
||||
|
||||
foreach (var item in append)
|
||||
{
|
||||
yield return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0f84614827ff91701149564447a3932b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+254
@@ -0,0 +1,254 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// <copyright file="MemberInfoExtensions.cs" company="Sirenix IVS">
|
||||
// Copyright (c) 2018 Sirenix IVS
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// </copyright>
|
||||
//-----------------------------------------------------------------------
|
||||
namespace VRC.Udon.Serialization.OdinSerializer.Utilities
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Globalization;
|
||||
|
||||
/// <summary>
|
||||
/// MemberInfo method extensions.
|
||||
/// </summary>
|
||||
public static class MemberInfoExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns true if the attribute whose type is specified by the generic argument is defined on this member
|
||||
/// </summary>
|
||||
public static bool IsDefined<T>(this ICustomAttributeProvider member, bool inherit) where T : Attribute
|
||||
{
|
||||
try
|
||||
{
|
||||
return member.IsDefined(typeof(T), inherit);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the attribute whose type is specified by the generic argument is defined on this member
|
||||
/// </summary>
|
||||
public static bool IsDefined<T>(this ICustomAttributeProvider member) where T : Attribute
|
||||
{
|
||||
return IsDefined<T>(member, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the first found custom attribute of type T on this member
|
||||
/// Returns null if none was found
|
||||
/// </summary>
|
||||
public static T GetAttribute<T>(this ICustomAttributeProvider member, bool inherit) where T : Attribute
|
||||
{
|
||||
var all = GetAttributes<T>(member, inherit).ToArray();
|
||||
return (all == null || all.Length == 0) ? null : all[0];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the first found non-inherited custom attribute of type T on this member
|
||||
/// Returns null if none was found
|
||||
/// </summary>
|
||||
public static T GetAttribute<T>(this ICustomAttributeProvider member) where T : Attribute
|
||||
{
|
||||
return GetAttribute<T>(member, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all attributes of the specified generic type.
|
||||
/// </summary>
|
||||
/// <param name="member">The member.</param>
|
||||
public static IEnumerable<T> GetAttributes<T>(this ICustomAttributeProvider member) where T : Attribute
|
||||
{
|
||||
return GetAttributes<T>(member, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all attributes of the specified generic type.
|
||||
/// </summary>
|
||||
/// <param name="member">The member.</param>
|
||||
/// <param name="inherit">If true, specifies to also search the ancestors of element for custom attributes.</param>
|
||||
public static IEnumerable<T> GetAttributes<T>(this ICustomAttributeProvider member, bool inherit) where T : Attribute
|
||||
{
|
||||
try
|
||||
{
|
||||
return member.GetCustomAttributes(typeof(T), inherit).Cast<T>();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return new T[0];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all attribute instances defined on a MemeberInfo.
|
||||
/// </summary>
|
||||
/// <param name="member">The member.</param>
|
||||
public static Attribute[] GetAttributes(this ICustomAttributeProvider member)
|
||||
{
|
||||
try
|
||||
{
|
||||
return member.GetAttributes<Attribute>().ToArray();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return new Attribute[0];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all attribute instances on a MemberInfo.
|
||||
/// </summary>
|
||||
/// <param name="member">The member.</param>
|
||||
/// <param name="inherit">If true, specifies to also search the ancestors of element for custom attributes.</param>
|
||||
public static Attribute[] GetAttributes(this ICustomAttributeProvider member, bool inherit)
|
||||
{
|
||||
try
|
||||
{
|
||||
return member.GetAttributes<Attribute>(inherit).ToArray();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return new Attribute[0];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If this member is a method, returns the full method name (name + params) otherwise the member name paskal splitted
|
||||
/// </summary>
|
||||
public static string GetNiceName(this MemberInfo member)
|
||||
{
|
||||
var method = member as MethodBase;
|
||||
string result;
|
||||
if (method != null)
|
||||
{
|
||||
result = method.GetFullName();
|
||||
}
|
||||
else
|
||||
{
|
||||
result = member.Name;
|
||||
}
|
||||
|
||||
return result.ToTitleCase();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether a FieldInfo, PropertyInfo or MethodInfo is static.
|
||||
/// </summary>
|
||||
/// <param name="member">The member.</param>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the specified member is static; otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
/// <exception cref="System.NotSupportedException"></exception>
|
||||
public static bool IsStatic(this MemberInfo member)
|
||||
{
|
||||
var field = member as FieldInfo;
|
||||
if (field != null)
|
||||
{
|
||||
return field.IsStatic;
|
||||
}
|
||||
|
||||
var property = member as PropertyInfo;
|
||||
if (property != null)
|
||||
{
|
||||
return property.CanRead ? property.GetGetMethod(true).IsStatic : property.GetSetMethod(true).IsStatic;
|
||||
}
|
||||
|
||||
var method = member as MethodBase;
|
||||
if (method != null)
|
||||
{
|
||||
return method.IsStatic;
|
||||
}
|
||||
|
||||
var @event = member as EventInfo;
|
||||
if (@event != null)
|
||||
{
|
||||
return @event.GetRaiseMethod(true).IsStatic;
|
||||
}
|
||||
|
||||
var type = member as Type;
|
||||
if (type != null)
|
||||
{
|
||||
return type.IsSealed && type.IsAbstract;
|
||||
}
|
||||
|
||||
string message = string.Format(
|
||||
CultureInfo.InvariantCulture,
|
||||
"Unable to determine IsStatic for member {0}.{1}" +
|
||||
"MemberType was {2} but only fields, properties and methods are supported.",
|
||||
member.DeclaringType.FullName,
|
||||
member.Name,
|
||||
member.GetType().FullName);
|
||||
|
||||
throw new NotSupportedException(message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the specified member is an alias.
|
||||
/// </summary>
|
||||
/// <param name="memberInfo">The member to check.</param>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the specified member is an alias; otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
public static bool IsAlias(this MemberInfo memberInfo)
|
||||
{
|
||||
return memberInfo is MemberAliasFieldInfo
|
||||
|| memberInfo is MemberAliasPropertyInfo
|
||||
|| memberInfo is MemberAliasMethodInfo;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the original, backing member of an alias member if the member is an alias.
|
||||
/// </summary>
|
||||
/// <param name="memberInfo">The member to check.</param>
|
||||
/// /// <param name="throwOnNotAliased">if set to <c>true</c> an exception will be thrown if the member is not aliased.</param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="System.ArgumentException">The member was not aliased; this only occurs if throwOnNotAliased is true.</exception>
|
||||
public static MemberInfo DeAlias(this MemberInfo memberInfo, bool throwOnNotAliased = false)
|
||||
{
|
||||
MemberAliasFieldInfo aliasFieldInfo = memberInfo as MemberAliasFieldInfo;
|
||||
|
||||
if (aliasFieldInfo != null)
|
||||
{
|
||||
return aliasFieldInfo.AliasedField;
|
||||
}
|
||||
|
||||
MemberAliasPropertyInfo aliasPropertyInfo = memberInfo as MemberAliasPropertyInfo;
|
||||
|
||||
if (aliasPropertyInfo != null)
|
||||
{
|
||||
return aliasPropertyInfo.AliasedProperty;
|
||||
}
|
||||
|
||||
MemberAliasMethodInfo aliasMethodInfo = memberInfo as MemberAliasMethodInfo;
|
||||
|
||||
if (aliasMethodInfo != null)
|
||||
{
|
||||
return aliasMethodInfo.AliasedMethod;
|
||||
}
|
||||
|
||||
if (throwOnNotAliased)
|
||||
{
|
||||
throw new ArgumentException("The member " + memberInfo.GetNiceName() + " was not aliased.");
|
||||
}
|
||||
|
||||
return memberInfo;
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 62088a9c188c943eb4035de16eb6ec32
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+139
@@ -0,0 +1,139 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// <copyright file="MethodInfoExtensions.cs" company="Sirenix IVS">
|
||||
// Copyright (c) 2018 Sirenix IVS
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// </copyright>
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
namespace VRC.Udon.Serialization.OdinSerializer.Utilities
|
||||
{
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
|
||||
/// <summary>
|
||||
/// Various extensions for MethodInfo.
|
||||
/// </summary>
|
||||
public static class MethodInfoExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns the specified method's full name "methodName(argType1 arg1, argType2 arg2, etc)"
|
||||
/// Uses the specified gauntlet to replaces type names, ex: "int" instead of "Int32"
|
||||
/// </summary>
|
||||
public static string GetFullName(this MethodBase method, string extensionMethodPrefix)
|
||||
{
|
||||
var builder = new StringBuilder();
|
||||
bool isExtensionMethod = method.IsExtensionMethod();
|
||||
|
||||
if (isExtensionMethod)
|
||||
{
|
||||
builder.Append(extensionMethodPrefix);
|
||||
}
|
||||
|
||||
builder.Append(method.Name);
|
||||
builder.Append("(");
|
||||
builder.Append(method.GetParamsNames());
|
||||
builder.Append(")");
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a string representing the passed method parameters names. Ex "int num, float damage, Transform target"
|
||||
/// </summary>
|
||||
public static string GetParamsNames(this MethodBase method)
|
||||
{
|
||||
ParameterInfo[] pinfos = method.IsExtensionMethod() ? method.GetParameters().Skip(1).ToArray() : method.GetParameters();
|
||||
var builder = new StringBuilder();
|
||||
|
||||
for (int i = 0, len = pinfos.Length; i < len; i++)
|
||||
{
|
||||
var param = pinfos[i];
|
||||
var paramTypeName = param.ParameterType.GetNiceName();
|
||||
builder.Append(paramTypeName);
|
||||
builder.Append(" ");
|
||||
builder.Append(param.Name);
|
||||
|
||||
if (i < len - 1)
|
||||
{
|
||||
builder.Append(", ");
|
||||
}
|
||||
}
|
||||
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the specified method's full name.
|
||||
/// </summary>
|
||||
public static string GetFullName(this MethodBase method)
|
||||
{
|
||||
return GetFullName(method, "[ext] ");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests if a method is an extension method.
|
||||
/// </summary>
|
||||
public static bool IsExtensionMethod(this MethodBase method)
|
||||
{
|
||||
var type = method.DeclaringType;
|
||||
return type.IsSealed &&
|
||||
!type.IsGenericType &&
|
||||
!type.IsNested &&
|
||||
method.IsDefined(typeof(ExtensionAttribute), false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the specified method is an alias.
|
||||
/// </summary>
|
||||
/// <param name="methodInfo">The method to check.</param>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the specified method is an alias; otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
public static bool IsAliasMethod(this MethodInfo methodInfo)
|
||||
{
|
||||
return methodInfo is MemberAliasMethodInfo;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the original, backing method of an alias method if the method is an alias.
|
||||
/// </summary>
|
||||
/// <param name="methodInfo">The method to check.</param>
|
||||
/// /// <param name="throwOnNotAliased">if set to <c>true</c> an exception will be thrown if the method is not aliased.</param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="System.ArgumentException">The method was not aliased; this only occurs if throwOnNotAliased is true.</exception>
|
||||
public static MethodInfo DeAliasMethod(this MethodInfo methodInfo, bool throwOnNotAliased = false)
|
||||
{
|
||||
MemberAliasMethodInfo aliasMethodInfo = methodInfo as MemberAliasMethodInfo;
|
||||
|
||||
if (aliasMethodInfo != null)
|
||||
{
|
||||
while (aliasMethodInfo.AliasedMethod is MemberAliasMethodInfo)
|
||||
{
|
||||
aliasMethodInfo = aliasMethodInfo.AliasedMethod as MemberAliasMethodInfo;
|
||||
}
|
||||
|
||||
return aliasMethodInfo.AliasedMethod;
|
||||
}
|
||||
|
||||
if (throwOnNotAliased)
|
||||
{
|
||||
throw new ArgumentException("The method " + methodInfo.GetNiceName() + " was not aliased.");
|
||||
}
|
||||
|
||||
return methodInfo;
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 63a9a0384a6fe66fb04f82f325895b30
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,126 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// <copyright file="Operator.cs" company="Sirenix IVS">
|
||||
// Copyright (c) 2018 Sirenix IVS
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// </copyright>
|
||||
//-----------------------------------------------------------------------
|
||||
namespace VRC.Udon.Serialization.OdinSerializer.Utilities
|
||||
{
|
||||
/// <summary>
|
||||
/// Determines the type of operator.
|
||||
/// </summary>
|
||||
/// <seealso cref="TypeExtensions" />
|
||||
public enum Operator
|
||||
{
|
||||
/// <summary>
|
||||
/// The == operator.
|
||||
/// </summary>
|
||||
Equality,
|
||||
|
||||
/// <summary>
|
||||
/// The != operator.
|
||||
/// </summary>
|
||||
Inequality,
|
||||
|
||||
/// <summary>
|
||||
/// The + operator.
|
||||
/// </summary>
|
||||
Addition,
|
||||
|
||||
/// <summary>
|
||||
/// The - operator.
|
||||
/// </summary>
|
||||
Subtraction,
|
||||
|
||||
/// <summary>
|
||||
/// The * operator.
|
||||
/// </summary>
|
||||
Multiply,
|
||||
|
||||
/// <summary>
|
||||
/// The / operator.
|
||||
/// </summary>
|
||||
Division,
|
||||
|
||||
/// <summary>
|
||||
/// The < operator.
|
||||
/// </summary>
|
||||
LessThan,
|
||||
|
||||
/// <summary>
|
||||
/// The > operator.
|
||||
/// </summary>
|
||||
GreaterThan,
|
||||
|
||||
/// <summary>
|
||||
/// The <= operator.
|
||||
/// </summary>
|
||||
LessThanOrEqual,
|
||||
|
||||
/// <summary>
|
||||
/// The >= operator.
|
||||
/// </summary>
|
||||
GreaterThanOrEqual,
|
||||
|
||||
/// <summary>
|
||||
/// The % operator.
|
||||
/// </summary>
|
||||
Modulus,
|
||||
|
||||
/// <summary>
|
||||
/// The >> operator.
|
||||
/// </summary>
|
||||
RightShift,
|
||||
|
||||
/// <summary>
|
||||
/// The << operator.
|
||||
/// </summary>
|
||||
LeftShift,
|
||||
|
||||
/// <summary>
|
||||
/// The & operator.
|
||||
/// </summary>
|
||||
BitwiseAnd,
|
||||
|
||||
/// <summary>
|
||||
/// The | operator.
|
||||
/// </summary>
|
||||
BitwiseOr,
|
||||
|
||||
/// <summary>
|
||||
/// The ^ operator.
|
||||
/// </summary>
|
||||
ExclusiveOr,
|
||||
|
||||
/// <summary>
|
||||
/// The ~ operator.
|
||||
/// </summary>
|
||||
BitwiseComplement,
|
||||
|
||||
/// <summary>
|
||||
/// The && operator.
|
||||
/// </summary>
|
||||
LogicalAnd,
|
||||
|
||||
/// <summary>
|
||||
/// The || operator.
|
||||
/// </summary>
|
||||
LogicalOr,
|
||||
|
||||
/// <summary>
|
||||
/// The ! operator.
|
||||
/// </summary>
|
||||
LogicalNot,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1df9513f03131466eecad22d1b19c4d8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,53 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// <copyright file="PathUtilities.cs" company="Sirenix IVS">
|
||||
// Copyright (c) 2018 Sirenix IVS
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// </copyright>
|
||||
//-----------------------------------------------------------------------
|
||||
namespace VRC.Udon.Serialization.OdinSerializer.Utilities
|
||||
{
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
/// <summary>
|
||||
/// DirectoryInfo method extensions.
|
||||
/// </summary>
|
||||
public static class PathUtilities
|
||||
{
|
||||
/// <summary>
|
||||
/// Determines whether the directory has a given directory in its hierarchy of children.
|
||||
/// </summary>
|
||||
/// <param name="parentDir">The parent directory.</param>
|
||||
/// <param name="subDir">The sub directory.</param>
|
||||
public static bool HasSubDirectory(this DirectoryInfo parentDir, DirectoryInfo subDir)
|
||||
{
|
||||
var parentDirName = parentDir.FullName.TrimEnd('\\', '/');
|
||||
|
||||
while (subDir != null)
|
||||
{
|
||||
if (subDir.FullName.TrimEnd('\\', '/') == parentDirName)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
subDir = subDir.Parent;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: da8aea12015a2df5402c9e2d4f1cec5c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// <copyright file="PropertyInfoExtensions.cs" company="Sirenix IVS">
|
||||
// Copyright (c) 2018 Sirenix IVS
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// </copyright>
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
namespace VRC.Udon.Serialization.OdinSerializer.Utilities
|
||||
{
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
/// <summary>
|
||||
/// PropertyInfo method extensions.
|
||||
/// </summary>
|
||||
public static class PropertyInfoExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Determines whether a property is an auto property with a usable getter and setter.
|
||||
/// </summary>
|
||||
public static bool IsAutoProperty(this PropertyInfo propInfo, bool allowVirtual = false)
|
||||
{
|
||||
if (!(propInfo.CanWrite && propInfo.CanRead))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!allowVirtual)
|
||||
{
|
||||
var getter = propInfo.GetGetMethod(true);
|
||||
var setter = propInfo.GetSetMethod(true);
|
||||
|
||||
if ((getter != null && (getter.IsAbstract || getter.IsVirtual)) || (setter != null && (setter.IsAbstract || setter.IsVirtual)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
var flag = BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static;
|
||||
string compilerGeneratedName = "<" + propInfo.Name + ">";
|
||||
var fields = propInfo.DeclaringType.GetFields(flag);
|
||||
|
||||
for (int i = 0; i < fields.Length; i++)
|
||||
{
|
||||
if (fields[i].Name.Contains(compilerGeneratedName))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the specified property is an alias.
|
||||
/// </summary>
|
||||
/// <param name="propertyInfo">The property to check.</param>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the specified property is an alias; otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
public static bool IsAliasProperty(this PropertyInfo propertyInfo)
|
||||
{
|
||||
return propertyInfo is MemberAliasPropertyInfo;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the original, backing property of an alias property if the property is an alias.
|
||||
/// </summary>
|
||||
/// <param name="propertyInfo">The property to check.</param>
|
||||
/// /// <param name="throwOnNotAliased">if set to <c>true</c> an exception will be thrown if the property is not aliased.</param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="System.ArgumentException">The property was not aliased; this only occurs if throwOnNotAliased is true.</exception>
|
||||
public static PropertyInfo DeAliasProperty(this PropertyInfo propertyInfo, bool throwOnNotAliased = false)
|
||||
{
|
||||
MemberAliasPropertyInfo aliasPropertyInfo = propertyInfo as MemberAliasPropertyInfo;
|
||||
|
||||
if (aliasPropertyInfo != null)
|
||||
{
|
||||
while (aliasPropertyInfo.AliasedProperty is MemberAliasPropertyInfo)
|
||||
{
|
||||
aliasPropertyInfo = aliasPropertyInfo.AliasedProperty as MemberAliasPropertyInfo;
|
||||
}
|
||||
|
||||
return aliasPropertyInfo.AliasedProperty;
|
||||
}
|
||||
|
||||
if (throwOnNotAliased)
|
||||
{
|
||||
throw new ArgumentException("The property " + propertyInfo.GetNiceName() + " was not aliased.");
|
||||
}
|
||||
|
||||
return propertyInfo;
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7f13450d6fd82372ffa7ee075a8eb4c9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,80 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// <copyright file="StringExtensions.cs" company="Sirenix IVS">
|
||||
// Copyright (c) 2018 Sirenix IVS
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// </copyright>
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
namespace VRC.Udon.Serialization.OdinSerializer.Utilities
|
||||
{
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
|
||||
/// <summary>
|
||||
/// String method extensions.
|
||||
/// </summary>
|
||||
public static class StringExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Eg MY_INT_VALUE => MyIntValue
|
||||
/// </summary>
|
||||
public static string ToTitleCase(this string input)
|
||||
{
|
||||
var builder = new StringBuilder();
|
||||
for (int i = 0; i < input.Length; i++)
|
||||
{
|
||||
var current = input[i];
|
||||
if (current == '_' && i + 1 < input.Length)
|
||||
{
|
||||
var next = input[i + 1];
|
||||
if (char.IsLower(next))
|
||||
{
|
||||
next = char.ToUpper(next, CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
builder.Append(next);
|
||||
i++;
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.Append(current);
|
||||
}
|
||||
}
|
||||
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if this string is null, empty, or contains only whitespace.
|
||||
/// </summary>
|
||||
/// <param name="str">The string to check.</param>
|
||||
/// <returns><c>true</c> if this string is null, empty, or contains only whitespace; otherwise, <c>false</c>.</returns>
|
||||
public static bool IsNullOrWhitespace(this string str)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(str))
|
||||
{
|
||||
for (int i = 0; i < str.Length; i++)
|
||||
{
|
||||
if (char.IsWhiteSpace(str[i]) == false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b554cbd9469011b544a2d92ae85a3b60
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a6a172cef14a88c7fb714df37bbecedb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,67 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// <copyright file="UnityExtensions.cs" company="Sirenix IVS">
|
||||
// Copyright (c) 2018 Sirenix IVS
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// </copyright>
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
namespace VRC.Udon.Serialization.OdinSerializer.Utilities
|
||||
{
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
/// <summary>
|
||||
/// Extends various Unity classes.
|
||||
/// </summary>
|
||||
public static class UnityExtensions
|
||||
{
|
||||
private static readonly ValueGetter<UnityEngine.Object, IntPtr> UnityObjectCachedPtrFieldGetter;
|
||||
|
||||
static UnityExtensions()
|
||||
{
|
||||
var field = typeof(UnityEngine.Object).GetField("m_CachedPtr", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
|
||||
if (field != null)
|
||||
{
|
||||
UnityObjectCachedPtrFieldGetter = EmitUtilities.CreateInstanceFieldGetter<UnityEngine.Object, IntPtr>(field);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether a Unity object is null or "fake null",
|
||||
/// without ever calling Unity's own equality operators.
|
||||
/// This method is useful for checking if a Unity object is
|
||||
/// null, destroyed or missing at times when it is not allowed
|
||||
/// to call Unity's own equality operators, for example when
|
||||
/// not running on the main thread.
|
||||
/// </summary>
|
||||
/// <param name="obj">The Unity object to check.</param>
|
||||
/// <returns>True if the object is null, missing or destroyed; otherwise false.</returns>
|
||||
public static bool SafeIsUnityNull(this UnityEngine.Object obj)
|
||||
{
|
||||
if (object.ReferenceEquals(obj, null))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (UnityObjectCachedPtrFieldGetter == null)
|
||||
{
|
||||
throw new NotSupportedException("Could not find the field 'm_CachedPtr' in the class UnityEngine.Object; cannot perform a special null check.");
|
||||
}
|
||||
|
||||
IntPtr ptr = UnityObjectCachedPtrFieldGetter(ref obj);
|
||||
return ptr == IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eb77f5278e425e91b71e186df29a5f16
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in new issue
Block a user