本文整理汇总了C#中Type.IsSubclassOf方法的典型用法代码示例。如果您正苦于以下问题:C# Type.IsSubclassOf方法的具体用法?C# Type.IsSubclassOf怎么用?C# Type.IsSubclassOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Type
的用法示例。
在下文中一共展示了Type.IsSubclassOf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DbMappingViewCacheTypeAttribute
/// <summary>
/// Creates a DbGeneratedViewCacheTypeAttribute instance that associates a context type
/// with a mapping view cache type.
/// <param name="contextType">A subclass of ObjectContext or DbContext.</param>
/// <param name="cacheTypeName">The assembly qualified full name of the cache type.</param>
public DbMappingViewCacheTypeAttribute(Type contextType, string cacheTypeName)
{
Check.NotNull(contextType, "contextType");
Check.NotEmpty(cacheTypeName, "cacheTypeName");
if (!contextType.IsSubclassOf(typeof(ObjectContext))
&& !contextType.IsSubclassOf(typeof(DbContext)))
{
throw new ArgumentException(
Strings.DbMappingViewCacheTypeAttribute_InvalidContextType(contextType),
"contextType");
}
_contextType = contextType;
try
{
_cacheType = Type.GetType(cacheTypeName, throwOnError: true);
}
catch (Exception ex)
{
throw new ArgumentException(
Strings.DbMappingViewCacheTypeAttribute_CacheTypeNotFound(cacheTypeName),
"cacheTypeName",
ex);
}
}
示例2: OnScanType
public static void OnScanType(Type tp)
{
if (tp.IsSubclassOf(typeof(DataCenter.AObject)) || tp.IsSubclassOf(typeof(AScriptObject)))
{
AddStaticReceivers(tp);
ProcessStaticDataEntity(tp);
}
}
示例3: CanHaveEditor
bool CanHaveEditor(Type t)
{
if (t.IsSubclassOf(typeof(MonoBehaviour)))
return true;
if (t.IsSubclassOf(typeof(ScriptableObject)))
{
if (!t.IsSubclassOf(typeof(Editor)) && !t.IsSubclassOf(typeof(EditorWindow)))
return true;
}
return false;
}
示例4: Create
/// <summary>
/// Creates a CallSite with the given delegate type and binder.
/// </summary>
/// <param name="delegateType">The CallSite delegate type.</param>
/// <param name="binder">The CallSite binder.</param>
/// <returns>The new CallSite.</returns>
public static CallSite Create(Type delegateType, CallSiteBinder binder)
{
ContractUtils.RequiresNotNull(delegateType, "delegateType");
ContractUtils.RequiresNotNull(binder, "binder");
if (!delegateType.IsSubclassOf(typeof(MulticastDelegate))) throw Error.TypeMustBeDerivedFromSystemDelegate();
var ctors = s_siteCtors;
if (ctors == null) {
// It's okay to just set this, worst case we're just throwing away some data
s_siteCtors = ctors = new CacheDict<Type, Func<CallSiteBinder, CallSite>>(100);
}
Func<CallSiteBinder, CallSite> ctor;
MethodInfo method = null;
if (!ctors.TryGetValue(delegateType, out ctor))
{
method = typeof(CallSite<>).MakeGenericType(delegateType).GetMethod("Create");
if (TypeUtils.CanCache(delegateType))
{
ctor = (Func<CallSiteBinder, CallSite>)method.CreateDelegate(typeof(Func<CallSiteBinder, CallSite>));
ctors.Add(delegateType, ctor);
}
}
if (ctor != null)
{
return ctor(binder);
}
// slow path
return (CallSite)method.Invoke(null, new object[] { binder });
}
示例5: CreateAsset
/// <summary>
/// Create a new, empty asset of the given type.
/// </summary>
/// <param name="assetType">The type of asset to create. It must be a ScriptableObject or derive from one.</param>
public static void CreateAsset(Type assetType)
{
if (!assetType.IsSubclassOf(typeof(ScriptableObject)))
throw new UnityException("Can't create an asset object from a type that does not derive from ScriptableObject!");
ScriptableObject asset = ScriptableObject.CreateInstance(assetType.Name);
string path = AssetDatabase.GetAssetPath(Selection.activeObject);
if (path == "")
{
path = "Assets";
}
else if (Path.GetExtension(path) != "")
{
path = path.Replace(Path.GetFileName(AssetDatabase.GetAssetPath(Selection.activeObject)), "");
}
string assetPathAndName = AssetDatabase.GenerateUniqueAssetPath(path + "/New " + assetType.Name + ".asset");
AssetDatabase.CreateAsset(asset, assetPathAndName);
AssetDatabase.SaveAssets();
EditorUtility.FocusProjectWindow();
Selection.activeObject = asset;
}
示例6: Add
public int Add(string name, Type type) {
if (type.IsSubclassOf(typeof(SchemaImporterExtension))) {
return Add(name, (SchemaImporterExtension)Activator.CreateInstance(type));
}
else {
throw new ArgumentException(Res.GetString(Res.XmlInvalidSchemaExtension, type));
}
}
示例7: Add
static void Add(Type componentType, GameObject go)
{
if (componentType.IsSubclassOf(typeof(UniqueIdentifier))) {
foreach (var c in go.GetComponents(typeof(UniqueIdentifier)).Cast<UniqueIdentifier>())
DestroyImmediate(c);
}
go.AddComponent(componentType);
}
示例8: GetHelpURL
/// <summary>
/// Get the URL pointing to the documentation for the specified component.
/// </summary>
static public string GetHelpURL (Type type)
{
if (type == typeof(UITexture)) return "http://www.tasharen.com/forum/index.php?topic=6703";
if (type == typeof(UISprite)) return "http://www.tasharen.com/forum/index.php?topic=6704";
if (type == typeof(UIPanel)) return "http://www.tasharen.com/forum/index.php?topic=6705";
if (type == typeof(UILabel)) return "http://www.tasharen.com/forum/index.php?topic=6706";
if (type == typeof(UIButton)) return "http://www.tasharen.com/forum/index.php?topic=6708";
if (type == typeof(UIToggle)) return "http://www.tasharen.com/forum/index.php?topic=6709";
if (type == typeof(UIRoot)) return "http://www.tasharen.com/forum/index.php?topic=6710";
if (type == typeof(UICamera)) return "http://www.tasharen.com/forum/index.php?topic=6711";
if (type == typeof(UIAnchor)) return "http://www.tasharen.com/forum/index.php?topic=6712";
if (type == typeof(UIStretch)) return "http://www.tasharen.com/forum/index.php?topic=6713";
if (type == typeof(UISlider)) return "http://www.tasharen.com/forum/index.php?topic=6715";
#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_1 && !UNITY_4_2
if (type == typeof(UI2DSprite)) return "http://www.tasharen.com/forum/index.php?topic=6729";
#endif
if (type == typeof(UIScrollBar)) return "http://www.tasharen.com/forum/index.php?topic=6733";
if (type == typeof(UIProgressBar)) return "http://www.tasharen.com/forum/index.php?topic=6738";
if (type == typeof(UIPopupList)) return "http://www.tasharen.com/forum/index.php?topic=6751";
if (type == typeof(UIInput)) return "http://www.tasharen.com/forum/index.php?topic=6752";
if (type == typeof(UIKeyBinding)) return "http://www.tasharen.com/forum/index.php?topic=6753";
if (type == typeof(UIGrid)) return "http://www.tasharen.com/forum/index.php?topic=6756";
if (type == typeof(UITable)) return "http://www.tasharen.com/forum/index.php?topic=6758";
if (type == typeof(UIKeyNavigation)) return "http://www.tasharen.com/forum/index.php?topic=8747";
if (type == typeof(PropertyBinding) || type == typeof(PropertyReference))
return "http://www.tasharen.com/forum/index.php?topic=8808";
if (type == typeof(ActiveAnimation) || type == typeof(UIPlayAnimation))
return "http://www.tasharen.com/forum/index.php?topic=6762";
if (type == typeof(UIScrollView) || type == typeof(UIDragScrollView))
return "http://www.tasharen.com/forum/index.php?topic=6763";
if (type == typeof(UIWidget) || type.IsSubclassOf(typeof(UIWidget)))
return "http://www.tasharen.com/forum/index.php?topic=6702";
if (type == typeof(UIPlayTween) || type.IsSubclassOf(typeof(UITweener)))
return "http://www.tasharen.com/forum/index.php?topic=6760";
if (type == typeof(UILocalize) || type == typeof(Localization))
return "http://www.tasharen.com/forum/index.php?topic=8092.0";
return null;
}
示例9: Create
/// <summary>
/// Creates a CallSite with the given delegate type and binder.
/// </summary>
/// <param name="delegateType">The CallSite delegate type.</param>
/// <param name="binder">The CallSite binder.</param>
/// <returns>The new CallSite.</returns>
public static CallSite Create(Type delegateType, CallSiteBinder binder) {
ContractUtils.RequiresNotNull(delegateType, "delegateType");
ContractUtils.RequiresNotNull(binder, "binder");
ContractUtils.Requires(delegateType.IsSubclassOf(typeof(Delegate)), "delegateType", Strings.TypeMustBeDerivedFromSystemDelegate);
if (_SiteCtors == null) {
// It's okay to just set this, worst case we're just throwing away some data
_SiteCtors = new CacheDict<Type, Func<CallSiteBinder, CallSite>>(100);
}
Func<CallSiteBinder, CallSite> ctor;
lock (_SiteCtors) {
if (!_SiteCtors.TryGetValue(delegateType, out ctor)) {
MethodInfo method = typeof(CallSite<>).MakeGenericType(delegateType).GetMethod("Create");
ctor = (Func<CallSiteBinder, CallSite>)Delegate.CreateDelegate(typeof(Func<CallSiteBinder, CallSite>), method);
_SiteCtors.Add(delegateType, ctor);
}
}
return ctor(binder);
}
示例10: IsTypeEquivalent
private static bool IsTypeEquivalent(Type argType, Type paramType)
{
bool result = false;
if (argType == paramType)
{
result = true;
}
else if (argType.IsSubclassOf(paramType))
{
result = true;
}
else if (argType == paramType.GetElementType())
{
result = true;
}
else if (argType.IsSubclassOf(typeof(Array)) && paramType.IsSubclassOf(typeof(Array)))
{
result = true;
}
return result;
}
示例11: GetRelationPropertyName
internal String GetRelationPropertyName( Type propertyType ) {
String name = null;
for (int i = 0; i < _savedPropertyList.Count; i++) {
var ep = _savedPropertyList[i];
if (ep.Type.FullName == propertyType.FullName) {
return ep.Name;
}
if (propertyType.IsSubclassOf( ep.Type )) {
name = ep.Name;
}
}
return name;
}
示例12: ProcessArg
static void ProcessArg(Type varType, string head, string arg, int stackPos, bool beCheckTypes = false, bool beParams = false, bool beOutArg = false)
{
varType = GetRefBaseType(varType);
string str = GetTypeStr(varType);
string checkStr = beCheckTypes ? "To" : "Check";
if (beOutArg)
{
if (varType.IsValueType)
{
sb.AppendFormat("{0}{1} {2};\r\n", head, str, arg);
}
else
{
sb.AppendFormat("{0}{1} {2} = null;\r\n", head, str, arg);
}
}
else if (varType == typeof(bool))
{
string chkstr = beCheckTypes ? "lua_toboolean" : "luaL_checkboolean";
sb.AppendFormat("{0}bool {1} = LuaDLL.{2}(L, {3});\r\n", head, arg, chkstr, stackPos);
}
else if (varType == typeof(string))
{
sb.AppendFormat("{0}string {1} = ToLua.{2}String(L, {3});\r\n", head, arg, checkStr, stackPos);
}
else if (varType == typeof(IntPtr))
{
sb.AppendFormat("{0}{1} {2} = ({1})LuaDLL.lua_touserdata(L, {3});\r\n", head, str, arg, stackPos);
}
else if (varType.IsPrimitive || IsNumberEnum(varType))
{
string chkstr = beCheckTypes ? "lua_tonumber" : "luaL_checknumber";
sb.AppendFormat("{0}{1} {2} = ({1})LuaDLL.{3}(L, {4});\r\n", head, str, arg, chkstr, stackPos);
}
else if (varType == typeof(LuaFunction))
{
sb.AppendFormat("{0}LuaFunction {1} = ToLua.{2}LuaFunction(L, {3});\r\n", head, arg, checkStr, stackPos);
}
else if (varType.IsSubclassOf(typeof(System.MulticastDelegate)))
{
sb.AppendFormat("{0}{1} {2} = null;\r\n", head, str, arg);
sb.AppendFormat("{0}LuaTypes funcType{1} = LuaDLL.lua_type(L, {1});\r\n", head, stackPos);
sb.AppendLineEx();
sb.AppendFormat("{0}if (funcType{1} != LuaTypes.LUA_TFUNCTION)\r\n", head, stackPos);
sb.AppendLineEx(head + "{");
if (beCheckTypes)
{
sb.AppendFormat("{3} {1} = ({0})ToLua.ToObject(L, {2});\r\n", str, arg, stackPos, head + "\t");
}
else
{
sb.AppendFormat("{3} {1} = ({0})ToLua.CheckObject(L, {2}, typeof({0}));\r\n", str, arg, stackPos, head + "\t");
}
sb.AppendFormat("{0}}}\r\n{0}else\r\n{0}{{\r\n", head);
sb.AppendFormat("{0}\tLuaFunction func = ToLua.ToLuaFunction(L, {1});\r\n", head, stackPos);
sb.AppendFormat("{0}\t{1} = DelegateFactory.CreateDelegate(typeof({2}), func) as {2};\r\n", head, arg, GetTypeStr(varType));
sb.AppendLineEx(head + "}");
sb.AppendLineEx();
}
else if (varType == typeof(LuaTable))
{
sb.AppendFormat("{0}LuaTable {1} = ToLua.{2}LuaTable(L, {3});\r\n", head, arg, checkStr, stackPos);
}
else if (varType == typeof(Vector2))
{
sb.AppendFormat("{0}UnityEngine.Vector2 {1} = ToLua.ToVector2(L, {2});\r\n", head, arg, stackPos);
}
else if (varType == typeof(Vector3))
{
sb.AppendFormat("{0}UnityEngine.Vector3 {1} = ToLua.ToVector3(L, {2});\r\n", head, arg, stackPos);
}
else if (varType == typeof(Vector4))
{
sb.AppendFormat("{0}UnityEngine.Vector4 {1} = ToLua.ToVector4(L, {2});\r\n", head, arg, stackPos);
}
else if (varType == typeof(Quaternion))
{
sb.AppendFormat("{0}UnityEngine.Quaternion {1} = ToLua.ToQuaternion(L, {2});\r\n", head, arg, stackPos);
}
else if (varType == typeof(Color))
{
sb.AppendFormat("{0}UnityEngine.Color {1} = ToLua.ToColor(L, {2});\r\n", head, arg, stackPos);
}
else if (varType == typeof(Ray))
{
sb.AppendFormat("{0}UnityEngine.Ray {1} = ToLua.ToRay(L, {2});\r\n", head, arg, stackPos);
}
else if (varType == typeof(Bounds))
{
sb.AppendFormat("{0}UnityEngine.Bounds {1} = ToLua.ToBounds(L, {2});\r\n", head, arg, stackPos);
}
else if (varType == typeof(LayerMask))
{
sb.AppendFormat("{0}UnityEngine.LayerMask {1} = ToLua.ToLayerMask(L, {2});\r\n", head, arg, stackPos);
}
else if (varType == typeof(LuaInteger64))
//.........这里部分代码省略.........
示例13: MakeDynamic
/// <summary>
/// Creates a <see cref="DynamicExpression" /> that represents a dynamic operation bound by the provided <see cref="CallSiteBinder" /> and four arguments.
/// </summary>
/// <param name="delegateType">The type of the delegate used by the <see cref="CallSite" />.</param>
/// <param name="binder">The runtime binder for the dynamic operation.</param>
/// <param name="arg0">The first argument to the dynamic operation.</param>
/// <param name="arg1">The second argument to the dynamic operation.</param>
/// <param name="arg2">The third argument to the dynamic operation.</param>
/// <param name="arg3">The fourth argument to the dynamic operation.</param>
/// <returns>
/// A <see cref="DynamicExpression" /> that has <see cref="NodeType" /> equal to
/// <see cref="ExpressionType.Dynamic">Dynamic</see> and has the
/// <see cref="DynamicExpression.DelegateType">DelegateType</see>,
/// <see cref="DynamicExpression.Binder">Binder</see>, and
/// <see cref="DynamicExpression.Arguments">Arguments</see> set to the specified values.
/// </returns>
public static DynamicExpression MakeDynamic(Type delegateType, CallSiteBinder binder, Expression arg0, Expression arg1, Expression arg2, Expression arg3) {
ContractUtils.RequiresNotNull(delegateType, "delegatType");
ContractUtils.RequiresNotNull(binder, "binder");
ContractUtils.Requires(delegateType.IsSubclassOf(typeof(Delegate)), "delegateType", Strings.TypeMustBeDerivedFromSystemDelegate);
var method = GetValidMethodForDynamic(delegateType);
var parameters = method.GetParametersCached();
ValidateArgumentCount(method, ExpressionType.Dynamic, 5, parameters);
ValidateDynamicArgument(arg0);
ValidateOneArgument(method, ExpressionType.Dynamic, arg0, parameters[1]);
ValidateDynamicArgument(arg1);
ValidateOneArgument(method, ExpressionType.Dynamic, arg1, parameters[2]);
ValidateDynamicArgument(arg2);
ValidateOneArgument(method, ExpressionType.Dynamic, arg2, parameters[3]);
ValidateDynamicArgument(arg2);
ValidateOneArgument(method, ExpressionType.Dynamic, arg3, parameters[4]);
return DynamicExpression.Make(method.GetReturnType(), delegateType, binder, arg0, arg1, arg2, arg3);
}
示例14: CompareCloserType
int CompareCloserType (Type t1, Type t2)
{
if (t1 == t2)
return 0;
if (t1.IsGenericParameter && !t2.IsGenericParameter)
return 1; // t2
if (!t1.IsGenericParameter && t2.IsGenericParameter)
return -1; // t1
if (t1.HasElementType && t2.HasElementType)
return CompareCloserType (
t1.GetElementType (),
t2.GetElementType ());
if (t1.IsSubclassOf (t2))
return -1; // t1
if (t2.IsSubclassOf (t1))
return 1; // t2
if (t1.IsInterface && Array.IndexOf (t2.GetInterfaces (), t1) >= 0)
return 1; // t2
if (t2.IsInterface && Array.IndexOf (t1.GetInterfaces (), t2) >= 0)
return -1; // t1
// What kind of cases could reach here?
return 0;
}
示例15: FunctionGen
//.........这里部分代码省略.........
mycsargs += GetMonoType (Type.GetTypeCode (p.ParameterType));
myargs += CsTypeToC (p.ParameterType) + KeywordAvoid (p.Name);
if (i != parameters.Length - 1) {
mycsargs += ",";
myargs += ", ";
}
}
if (myargs == String.Empty)
myargs = "void";
C.WriteLine ();
C.WriteLine (rettype + myname + " (" + myargs + ")", H, ";");
C.WriteLine ("{");
C.WriteLine ("static MonoMethod *_mono_method = NULL;");
if (ctor || !stat)
C.WriteLine ("MonoObject *" + mono_obj + ";");
if (parameters.Length != 0) C.WriteLine ("gpointer " + params_arg + "[" + parameters.Length + "];");
if (ctor) {
C.WriteLine (CurType + " *" + instance + ";");
}
if (!ctor && !stat) {
C.WriteLine ();
C.WriteLine (mono_obj + " = g_object_get_data (G_OBJECT (" + instance + "), \"mono-object\");");
}
C.WriteLine ();
C.WriteLine ("if (_mono_method == NULL) {");
if (ctor)
C.WriteLine ("MonoMethodDesc *_mono_method_desc = mono_method_desc_new (\":.ctor(" + mycsargs + ")\", FALSE);");
else
C.WriteLine ("MonoMethodDesc *_mono_method_desc = mono_method_desc_new (\":" + m.Name + "(" + mycsargs + ")" + "\", FALSE);");
C.WriteLine ("_mono_method = mono_method_desc_search_in_class (_mono_method_desc, " + cur_type + "_get_mono_class ());");
C.WriteLine ("}");
C.WriteLine ();
//assign the parameters
for (int i = 0 ; i < parameters.Length ; i++) {
ParameterInfo p = parameters[i];
C.WriteLine (params_arg + "[" + i + "] = " + GetMonoVal (p.ParameterType, KeywordAvoid (p.Name)) + ";");
}
if (parameters.Length != 0)
C.WriteLine ();
if (ctor)
C.WriteLine (mono_obj + " = (MonoObject*) mono_object_new ((MonoDomain*) " + NsToC (ns) + "_get_mono_domain ()" + ", " + cur_type + "_get_mono_class ());");
//delegates are a special case as we want their constructor to take a function pointer
if (ctor && t.IsSubclassOf (typeof (MulticastDelegate))) {
C.WriteLine ("mono_delegate_ctor (" + mono_obj + ", object, method);");
} else {
//code to invoke the method
if (!ctor && has_return)
if (IsRegisteredByVal (ret_type)) {
C.WriteLine ("{");
C.WriteLine (rettype + "* retval = (" + rettype + "*) mono_object_unbox (mono_runtime_invoke (_mono_method, " + mono_obj + ", " + params_arg + ", NULL));");
C.WriteLine ("return (" + rettype + ") *retval;");
C.WriteLine ("}");
} else if (rettype == "const gchar *")
{
//convert the MonoString to a UTF8 before returning
C.WriteLine ("return (" + rettype + ") mono_string_to_utf8 ((MonoString*) mono_runtime_invoke (_mono_method, " + mono_obj + ", " + params_arg + ", NULL));");
} else {
//TODO: this isn't right
C.WriteLine ("return (" + rettype + ") mono_runtime_invoke (_mono_method, " + mono_obj + ", " + params_arg + ", NULL);");
}
else
C.WriteLine ("mono_runtime_invoke (_mono_method, " + mono_obj + ", " + params_arg + ", NULL);");
}
if (ctor) {
C.WriteLine ();
//TODO: use ->priv, not data for better performance if not wrapping a gobject
if (wrap_gobject)
C.WriteLine (instance + " = (" + CurType + " *) " + NsToC (ns) + "_cilc_glib_mobject_get_gobject (" + mono_obj + ");");
else
C.WriteLine (instance + " = (" + CurType + " *) g_object_new (" + NsToC (ns).ToUpper () + "_TYPE_" + CamelToC (t.Name).ToUpper () + ", NULL);");
C.WriteLine ("g_object_set_data (G_OBJECT (" + instance + "), \"mono-object\", " + mono_obj + ");");
C.WriteLine ();
C.WriteLine ("return " + instance + ";");
}
C.WriteLine ("}");
}