public static TableInfo FromPoco(System.Type t) { TableInfo tableInfo = new TableInfo(); object[] customAttributes = t.GetCustomAttributes(typeof(TableNameAttribute), true); tableInfo.TableName = ((customAttributes.Length == 0) ? t.Name : (customAttributes[0] as TableNameAttribute).Value); customAttributes = t.GetCustomAttributes(typeof(PrimaryKeyAttribute), true); tableInfo.PrimaryKey = ((customAttributes.Length == 0) ? "ID" : (customAttributes[0] as PrimaryKeyAttribute).Value); tableInfo.SequenceName = ((customAttributes.Length == 0) ? null : (customAttributes[0] as PrimaryKeyAttribute).sequenceName); tableInfo.AutoIncrement = (customAttributes.Length != 0 && (customAttributes[0] as PrimaryKeyAttribute).autoIncrement); return tableInfo; }
public static bool IsWebMethod(System.Reflection.MethodInfo method) { object[] customAttributes = method.GetCustomAttributes(typeof(System.Web.Services.Protocols.SoapRpcMethodAttribute), true); if ((customAttributes != null) && (customAttributes.Length > 0)) { return true; } customAttributes = method.GetCustomAttributes(typeof(System.Web.Services.Protocols.SoapDocumentMethodAttribute), true); if ((customAttributes != null) && (customAttributes.Length > 0)) { return true; } customAttributes = method.GetCustomAttributes(typeof(System.Web.Services.Protocols.HttpMethodAttribute), true); return ((customAttributes != null) && (customAttributes.Length > 0)); }
public override IEnumerable<ITestCase> CreateTests(IFixture fixture, System.Reflection.MethodInfo method) { foreach (RowAttribute rowAttribute in method.GetCustomAttributes(typeof(RowAttribute), true)) { yield return new RowTestCase(fixture.Name, method, rowAttribute); } }
/// <summary>Allowed map lite depth.</summary> /// <param name="type">The type.</param> /// <returns>An int.</returns> public static int AllowedMapLiteDepth(System.Type type) { var attrs = type.GetCustomAttributes(typeof(DataModel.MapLiteDepthAllowedAttribute), true) .Cast<DataModel.MapLiteDepthAllowedAttribute>() .ToArray(); return !attrs.Any() ? 0 : attrs.Max(a => a.Depth); }
public static string GetFriendlyName(System.Type type) { object[] objArr = type.GetCustomAttributes(typeof(Skybound.ComponentModel.DisplayNameAttribute), false); if ((objArr == null) || (objArr.Length == 0)) return type.FullName; return (objArr[0] as Skybound.ComponentModel.DisplayNameAttribute).FriendlyName; }
string GetAttrValue(System.Reflection.Assembly assy, Type attrType, string field) { object[] ary = assy.GetCustomAttributes(attrType, false); if (ary == null || ary.Length != 1) return "(not set)"; object value = attrType.InvokeMember(field, System.Reflection.BindingFlags.GetProperty, null, ary[0], new object[] { }); return value == null ? "(not set)" : (string)value; }
private static System.Type[] GetRequiredComponents(System.Type klass) { List<System.Type> typeList = (List<System.Type>) null; System.Type baseType; for (; klass != null && klass != typeof (MonoBehaviour); klass = baseType) { RequireComponent[] customAttributes = (RequireComponent[]) klass.GetCustomAttributes(typeof (RequireComponent), false); baseType = klass.BaseType; foreach (RequireComponent requireComponent in customAttributes) { if (typeList == null && customAttributes.Length == 1 && baseType == typeof (MonoBehaviour)) return new System.Type[3]{ requireComponent.m_Type0, requireComponent.m_Type1, requireComponent.m_Type2 }; if (typeList == null) typeList = new List<System.Type>(); if (requireComponent.m_Type0 != null) typeList.Add(requireComponent.m_Type0); if (requireComponent.m_Type1 != null) typeList.Add(requireComponent.m_Type1); if (requireComponent.m_Type2 != null) typeList.Add(requireComponent.m_Type2); } } if (typeList == null) return (System.Type[]) null; return typeList.ToArray(); }
private bool _isNullable;// = false; internal void GetDecorations( System.Reflection.MemberInfo memberInfo ) { object[] attrs = memberInfo.GetCustomAttributes( true ); for( int i = 0; i < attrs.Length; i++ ) { Add( attrs[i] ); } }
private string FormatApplicationName(System.Reflection.Assembly asm) { object[] customAttributes = asm.GetCustomAttributes(typeof(ApplicationNameAttribute), true); if (customAttributes.Length > 0) { return ((ApplicationNameAttribute) customAttributes[0]).Value; } return asm.GetName().Name; }
public override bool IsPersistentId(System.Reflection.MemberInfo member) { if (member.GetCustomAttributes(typeof(IdAttribute), false).Any()) { return true; } return base.IsPersistentId(member); }
private static bool CheckIsEditorScript(System.Type klass) { for (; klass != null && klass != typeof (MonoBehaviour); klass = klass.BaseType) { if (klass.GetCustomAttributes(typeof (ExecuteInEditMode), false).Length != 0) return true; } return false; }
public string GetDocumentation(System.Web.Http.Controllers.HttpActionDescriptor actionDescriptor) { string doc = ""; var attr = actionDescriptor.GetCustomAttributes<ApiDocAttribute>().FirstOrDefault(); if (attr != null) { doc = attr.Documentation; } return doc; }
public IClass ResolveClass(System.Type systemType) { if (systemType == null) throw new ArgumentNullException("systemType"); var modelAtt = systemType.GetCustomAttributes(typeof(ModelRepresentationClassAttribute), false); if (modelAtt != null && modelAtt.Length > 0) { var representation = (ModelRepresentationClassAttribute)modelAtt[0]; return ResolveClass(representation.UriString); } return null; }
/// <summary> /// Get model name of the given type. /// </summary> /// <param name="type">The class or enum type.</param> /// <returns>The model name of the given type, specified by the attribute, or the type name itself if attribute is not present.</returns> public static string GetTypeName(System.Type type) { ModelLiteralAttribute[] literals = (ModelLiteralAttribute[])type.GetCustomAttributes(typeof(ModelLiteralAttribute), false); if (literals.Length > 0) { return literals[0].Name; } else { return type.Name; } }
public static IServiceProvider CreateServiceProvider(System.Reflection.Assembly assembly) { if (assembly == null) throw new ArgumentNullException("assembly"); var attribute = assembly.GetCustomAttributes(typeof(ServiceProviderAttribute), false).Cast<ServiceProviderAttribute>().SingleOrDefault(); if (attribute == null) return null; return (IServiceProvider)Activator.CreateInstance(attribute.ServiceType); }
/// <summary> /// Get model name of the given field or property. /// </summary> /// <param name="member">The enum field or class property.</param> /// <returns>The model name of the given member, specified by the attribute, or the mamber name itself if attribute is not present.</returns> public static string GetMemberName(System.Reflection.MemberInfo member) { ModelLiteralAttribute[] literals = (ModelLiteralAttribute[])member.GetCustomAttributes(typeof(ModelLiteralAttribute), false); if (literals.Length > 0) { return literals[0].Name; } else { return member.Name; } }
public override void ApplyTo(ColDef colDef, System.Reflection.PropertyInfo pi) { colDef.DisplayName = this.ToDisplayName() ?? colDef.Name; colDef.Sortable = this.Sortable; colDef.Visible = this.Visible; colDef.Searchable = this.Searchable; colDef.SortDirection = this.SortDirection; colDef.MRenderFunction = this.MRenderFunction; colDef.CssClass = this.CssClass; colDef.CssClassHeader = this.CssClassHeader; colDef.CustomAttributes = pi.GetCustomAttributes().ToArray(); colDef.Width = this.Width; }
/// <summary> /// returns true if the method is an extension method /// </summary> /// <param name="method"></param> /// <returns></returns> public static bool IsExtensionMethod(System.Reflection.MethodInfo method) { if ((!method.IsPublic) || (!method.IsStatic)) { // By definition an extension method must be public and static return false; } System.Type ext_attr_type = typeof(System.Runtime.CompilerServices.ExtensionAttribute); var ext_attrs = (System.Runtime.CompilerServices.ExtensionAttribute[]) method.GetCustomAttributes(ext_attr_type, false); return (ext_attrs.Length > 0); }
public override object FindLifetimeManager(System.Type type, string identifier) { object[] attributes = type.GetCustomAttributes(typeof(UseLifetimeManagerAttribute), false); foreach (object a in attributes) { UseLifetimeManagerAttribute useAttribute = (UseLifetimeManagerAttribute)a; if (string.Equals(identifier, useAttribute.Identifier)) { return useAttribute.Type; } } if ((this.NextStep != null)) { return this.NextStep.FindLifetimeManager(type, identifier); } return null; }
public override object PickRegistration(System.Type type, string identifier) { object[] mappingAttributes = type.GetCustomAttributes(typeof(MapToAttribute), false); foreach (object a in mappingAttributes) { MapToAttribute mapTo = (MapToAttribute)a; if (string.Equals(mapTo.Identifier, identifier)) { return mapTo.MappedType; } } if ((this.NextStep != null)) { return this.NextStep.PickRegistration(type, identifier); } return null; }
/** * Returns the class attribute info for an event handler class. */ public static EventHandlerInfoAttribute GetEventHandlerInfo(System.Type eventHandlerType) { object[] attributes = eventHandlerType.GetCustomAttributes(typeof(EventHandlerInfoAttribute), false); foreach (object obj in attributes) { EventHandlerInfoAttribute eventHandlerInfoAttr = obj as EventHandlerInfoAttribute; if (eventHandlerInfoAttr != null) { return eventHandlerInfoAttr; } } return null; }
public static TypeConverter GetPropertyTypeConverter(System.Reflection.PropertyInfo propertyInfo) { foreach (object attribute in propertyInfo.GetCustomAttributes(typeof(TypeConverterAttribute), false)) { TypeConverterAttribute attr = attribute as TypeConverterAttribute; if (!attr.IsDefaultAttribute()) { try { var converter = Activator.CreateInstance(Type.GetType(attr.ConverterTypeName)) as TypeConverter; return converter; } catch { } } } return null; }
public void RunTest (Test test, System.Reflection.MethodInfo method) { var startTime = DateTime.Now; test.Setup (); var attributes = (TestAttribute[])method.GetCustomAttributes (typeof(TestAttribute), false); if (attributes[0].Async) { try { method.Invoke (test, new object[] { (AsyncCallback)(result => { var t = (Test)((object[])result.AsyncState)[0]; var m = (System.Reflection.MethodInfo)((object[])result.AsyncState)[1]; var s = (DateTime)((object[])result.AsyncState)[2]; t.TearDown (); if (OnTestFinished != null) { OnTestFinished (t, m, DateTime.Now - s, null); } }), new object[] { test, method, startTime } }); } catch (Exception ex) { if (OnTestFinished != null) { OnTestFinished(test, method, DateTime.Now - startTime, ex); } } } else { Exception ex = null; try { method.Invoke (test, null); } catch (Exception e) { ex = e; } test.TearDown (); if (OnTestFinished != null) { OnTestFinished (test, method, DateTime.Now - startTime, ex); } } }
public virtual void DumpAttributes(System.Type t) { try { System.Diagnostics.Trace.WriteLine( "Dumping attributes for Type '" + t.FullName + "'..." ); object[] attributes = t.GetCustomAttributes(false); if ( attributes != null ) { foreach( object attribute in attributes ) { System.Diagnostics.Trace.WriteLine( attribute ); } } } catch(System.Exception systemException) { System.Diagnostics.Trace.WriteLine( systemException ); } }
static bool isCSMonoBehaviour(System.Type type) { if (type == null) { return false; } if (type.Namespace != null && type.Namespace.IndexOf("UnityEngine") >= 0) { return true; } // 当 源文件还未从工程中删除时这个有用 if (type.GetCustomAttributes(typeof(SharpKit.JavaScript.JsTypeAttribute), false).Length > 0) { return false; } if (!typeof(MonoBehaviour).IsAssignableFrom(type)) return false; return true; //return !typeof(MonoBehaviour).IsAssignableFrom(type); }
static bool isCSMonoBehaviour(System.Type type) { if (type == null) { return false; } if (type.Namespace != null && type.Namespace.IndexOf("UnityEngine") >= 0) { return true; } // This is useful if source c# file still exists in project if (type.GetCustomAttributes(typeof(SharpKit.JavaScript.JsTypeAttribute), false).Length > 0) { return false; } if (!typeof(MonoBehaviour).IsAssignableFrom(type)) return false; return true; //return !typeof(MonoBehaviour).IsAssignableFrom(type); }
public void DisplayTypeProperties(System.Type ThisType) { // Show name of type Label2.Text = ThisType.FullName; // Show name of class from which this type derives Label4.Text = ThisType.BaseType.FullName; // Show standard attributes Label6.Text = "0x" + ThisType.Attributes.ToString("x") + " = " + ThisType.Attributes.ToString(); // Show custom attributes foreach (object attr in ThisType.GetCustomAttributes(true)) { ListBox1.Items.Add(attr); } }
public void Before(object service, System.Reflection.MethodInfo method, params object[] args) { var states = from attr in method.GetCustomAttributes(typeof(StatesAttribute), false) select (attr as StatesAttribute).State; Type selectedFeature = null; Type baseFeature = service.GetType(); while(baseFeature!=null) { selectedFeature = baseFeature; baseFeature = baseFeature.GetInterfaces().FirstOrDefault(); } dynamic item = (from arg in args where arg != null && arg.GetType() == selectedFeature.GetGenericArguments().FirstOrDefault() select ((dynamic)arg).State).FirstOrDefault(); if(!states.Contains((object)item)) { throw new Exception(string.Format("Cannot execute {0}/{1} in [{2}] state.", service.GetType(), method, item)); } }
/// <summary> /// Creates a new instance of <see cref="JsonPropertyDefinition"/>. /// </summary> /// <param name="property"></param> internal JsonPropertyDefinition(System.Reflection.PropertyInfo property) : this(property.Name) { foreach (var att in property.GetCustomAttributes(true)) { Type t = att.GetType(); if (t == typeof(CategoryAttribute)) Category = (att as CategoryAttribute).Category; else if (t == typeof(DescriptionAttribute)) Description = (att as DescriptionAttribute).Description; else if (t == typeof(DefaultValueAttribute)) try { DefaultValue = (JsonValue)(att as DefaultValueAttribute).Value; } catch (Exception) { } else if (t == typeof(BrowsableAttribute)) Browsable = (att as BrowsableAttribute).Browsable; else if (t == typeof(ReadOnlyAttribute)) ReadOnly = (att as ReadOnlyAttribute).IsReadOnly; } }
/* matches events to GLib signal names */ private static bool SignalFilter(System.Reflection.MemberInfo m, object filterCriteria) { string signame = (filterCriteria as string); object[] attrs = m.GetCustomAttributes (typeof (GLib.SignalAttribute), true); if (attrs.Length > 0) { foreach (GLib.SignalAttribute a in attrs) { if (signame == a.CName) { return true; } } return false; } else { /* this tries to match the names when no attibutes are present. It is only a fallback. */ signame = signame.ToLower ().Replace ("_", ""); string evname = m.Name.ToLower (); return signame == evname; } }