public static Attribute LoadAttribute( AttributeName name ) { Attribute att = new Attribute(); att.BaseValue = PlayerPrefs.GetInt(((AttributeName)name).ToString() + BASE_VALUE, 0); att.ExpToLevel = PlayerPrefs.GetInt(((AttributeName)name).ToString() + EXP_TO_LEVEL, Attribute.STARTING_EXP_COST); return att; }
public static void AppendEntityReferences(this XElement element, Eav.Entity entity, Attribute attribute) { var entityGuids = attribute.ToSIC_EAV_EntityRelationships.Where(rel => rel.ParentEntityID == entity.EntityID) .Select(rel => rel.ChildEntity.EntityGUID); var entityGuidsString = string.Join(",", entityGuids); element.Append(attribute.StaticName, entityGuidsString); }
public DatumSchema( Attribute[] attributes, Predicate<string> answerValidator) { Attributes = attributes; AnswerValidator = answerValidator; }
public Attribute AddAttribute(string name, string value, char quotechar, bool caseInsensitive) { Attribute a; for (int i = 0, n = this.attributes.Count; i < n; i++) { a = (Attribute)this.attributes[i]; if (caseInsensitive && string.Compare(a.Name, name, true) == 0) { return null; } else if ((object)a.Name == (object)name) { return null; } } a = (Attribute)this.attributes.Push(); if (a == null) { a = new Attribute(); this.attributes[this.attributes.Count - 1] = a; } a.Reset(name, value, quotechar); return a; }
private void SetupPrimaryAttributes() { for (int cnt = 0; cnt < _primaryAttribute.Length; cnt++) { _primaryAttribute[cnt] = new Attribute(); } }
public static IEnumerable<Attribute> ConvertToAttributeAstTypes(this IEnumerable<IAttribute> attributes) { foreach (var attr in attributes) { var attributeAst = attr.AttributeType.ToAstSyntaxType(); var attribute = new Attribute { Type = attributeAst, Role = Roles.Attribute }; foreach (var positionalArg in attr.PositionalArguments) { attribute.Arguments.Add(new PrimitiveExpression(positionalArg.ConstantValue)); } foreach (var namedArg in attr.NamedArguments) { attribute.Arguments.Add(new NamedExpression( namedArg.Key.Name, new PrimitiveExpression(namedArg.Value.ConstantValue))); } yield return attribute; } }
protected void DeserializePropertiesFromResources ( IDesignerSerializationManager manager, Object value, Attribute[] filter ) { }
public int this[string name] { get { foreach (Attribute attribute in this) { if (attribute.Name == name) return attribute.Value; } return int.MinValue; } set { foreach (Attribute attribute in this) { if (attribute.Name == name) { attribute.Value = value; return; } } var attr = new Attribute {Name = name, Value = value}; List.Add(attr); } }
/// <summary> /// <para>Gets a collection of properties for the type of array specified by the value parameter.</para> /// </summary> public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) { if (value == null) { return null; } PropertyDescriptor[] props = null; if (value.GetType().IsArray) { Array valueArray = (Array)value; int length = valueArray.GetLength(0); props = new PropertyDescriptor[length]; Type arrayType = value.GetType(); Type elementType = arrayType.GetElementType(); for (int i = 0; i < length; i++) { props[i] = new ArrayPropertyDescriptor(arrayType, elementType, i); } } return new PropertyDescriptorCollection(props); }
/// <summary> /// Applies a loaded attribute /// </summary> /// <param name="attribute">attribute</param> public void ApplyAttribute(Attribute attribute) { if (attribute.Key.EndsWith("Delay")) { delayBaseBox.Text = attribute.Initial.ToString(); delayBonusBox.Text = attribute.Scale.ToString(); } }
/// <summary> /// Applies a loaded attribute /// </summary> /// <param name="attribute">attribute</param> public void ApplyAttribute(Attribute attribute) { if (attribute.Key.EndsWith("Push Speed")) { pushBaseBox.Text = attribute.Initial.ToString(); pushBonusBox.Text = attribute.Scale.ToString(); } }
/// <summary> /// Applies a loaded attribute /// </summary> /// <param name="attribute">attribute</param> public void ApplyAttribute(Attribute attribute) { if (attribute.Key.EndsWith("Mana Percent")) { percentBaseBox.Text = attribute.Initial.ToString(); percentBonusBox.Text = attribute.Scale.ToString(); } }
public SingleTableQuery(int qId, List<Attribute> qProjectedAttrs, List<Table> qTables, Attribute qSelectedAttribute, String qSelectedAttributeValue, double qPercentSelection, Table qTable, int qConfig = 0) : base(qId, qProjectedAttrs, qTables, qSelectedAttribute, qSelectedAttributeValue, qPercentSelection, qConfig) { this.queryTable = qTable; }
private void AddAttribute( Attribute a) { DerObjectIdentifier oid = a.AttrType; object obj = attributes[oid]; if (obj == null) { attributes[oid] = a; } else { IList v; if (obj is Attribute) { v = Platform.CreateArrayList(); v.Add(obj); v.Add(a); } else { v = (IList) obj; v.Add(a); } attributes[oid] = v; } }
/// <summary> /// Applies a loaded attribute /// </summary> /// <param name="attribute">attribute</param> public void ApplyAttribute(Attribute attribute) { if (attribute.Key.EndsWith("Fire")) { durationBaseBox.Text = attribute.Initial.ToString(); durationBonusBox.Text = attribute.Scale.ToString(); } }
private readonly Type _receiverType; // Only set if we are an extender /// <summary> /// The main constructor for ReflectPropertyDescriptors. /// </summary> public ReflectPropertyDescriptor(Type componentClass, string name, Type type, Attribute[] attributes) : base(name, attributes) { Debug.WriteLine($"Creating ReflectPropertyDescriptor for {componentClass?.FullName}.{name}"); try { if (type == null) { Debug.WriteLine("type == null, name == " + name); throw new ArgumentException(string.Format(SR.ErrorInvalidPropertyType, name)); } if (componentClass == null) { Debug.WriteLine("componentClass == null, name == " + name); throw new ArgumentException(string.Format(SR.InvalidNullArgument, nameof(componentClass))); } _type = type; _componentClass = componentClass; } catch (Exception t) { Debug.Fail("Property '" + name + "' on component " + componentClass.FullName + " failed to init."); Debug.Fail(t.ToString()); throw; } }
public void Attribute() { Attribute inter = new Attribute(controller); inter.PositionalArguments.Add("asdfsadf"); Assert.That(inter.IsTheSame(inter.Clone(), ComparisonDepth.Outer), Is.True); }
public void AddAttribute(ref Attribute newAttribute, int indexCreation, int indexUpdate) { attributesCreation[indexCreation]=newAttribute; if (indexUpdate!=-1){ // if present only attributesUpdate[indexUpdate]=newAttribute; } }
/// <summary> /// Applies a loaded attribute /// </summary> /// <param name="attribute">attribute</param> public void ApplyAttribute(Attribute attribute) { if (attribute.Key.EndsWith("Chance")) { chanceBaseBox.Text = attribute.Initial.ToString(); chanceBonusBox.Text = attribute.Scale.ToString(); } }
/// <summary> /// Applies a loaded attribute /// </summary> /// <param name="attribute">attribute</param> public void ApplyAttribute(Attribute attribute) { if (attribute.Key.EndsWith("Mana Amount")) { manaBaseBox.Text = ((int)attribute.Initial).ToString(); manaBonusBox.Text = ((int)attribute.Scale).ToString(); } }
public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) { // TypeDescriptor.GetProperties is used here to get the sub properties of the property that we want to be able // to be expandable in the property browser PropertyDescriptorCollection subProperties = TypeDescriptor.GetProperties(value, new Attribute[] { new BrowsableAttribute(true) }); return subProperties; }
/// <summary> /// Applies a loaded attribute /// </summary> /// <param name="attribute">attribute</param> public void ApplyAttribute(Attribute attribute) { if (attribute.Key.EndsWith("Length")) { lengthBaseBox.Text = attribute.Initial.ToString(); lengthBonusBox.Text = attribute.Scale.ToString(); } }
/// <summary> /// Applies a loaded attribute /// </summary> /// <param name="attribute">attribute</param> public void ApplyAttribute(Attribute attribute) { if (attribute.Key.EndsWith("Heal")) { damageBaseBox.Text = ((int)attribute.Initial).ToString(); damageBonusBox.Text = ((int)attribute.Scale).ToString(); } }
public void TestParse() { var saxHandler = new Mock<ISaxHandler>(); using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream()) { memoryStream.Write(new System.Text.UTF8Encoding().GetBytes(_xmlToParse), 0, _xmlToParse.Length); memoryStream.Position = 0; SaxReaderImpl saxReaderImpl = new SaxReaderImpl(); saxReaderImpl.Parse(new System.IO.StreamReader(memoryStream), saxHandler.Object); } AttributeCollection element3Attributes = new AttributeCollection(); Attribute attr1Attribute = new Attribute(); attr1Attribute.LocalName = "attr1"; attr1Attribute.QName = "attr1"; attr1Attribute.Uri = string.Empty; attr1Attribute.Value = "val1"; element3Attributes.Add("attr1", attr1Attribute); saxHandler.Verify(c => c.StartDocument(), Times.Exactly(1)); saxHandler.Verify(c => c.EndDocument(), Times.Exactly(1)); saxHandler.Verify(c => c.StartElement(string.Empty, "root", "root", new AttributeCollection())); saxHandler.Verify(c => c.StartElement(string.Empty, "element1", "element1", new AttributeCollection())); saxHandler.Verify(c => c.StartElement(string.Empty, "element2", "element2", new AttributeCollection())); saxHandler.Verify(c => c.StartElement(string.Empty, "element3", "element3", element3Attributes)); saxHandler.Verify(c => c.EndElement(string.Empty, "root", "root")); saxHandler.Verify(c => c.EndElement(string.Empty, "element1", "element1")); saxHandler.Verify(c => c.EndElement(string.Empty, "element2", "element2")); saxHandler.Verify(c => c.EndElement(string.Empty, "element3", "element3")); saxHandler.Verify(c => c.Characters(It.IsAny<char[]>(), It.IsAny<int>(), It.IsAny<int>())); }
private double Gain(List<List<string>> Examples, Attribute A, string bestat) { double result; int CountPositives = 0; int[] CountPositivesA = new int[A.LValue.Count]; int[] CountNegativeA = new int[A.LValue.Count]; int Col = Attributes.IndexOf(A); for (int i = 0; i < A.LValue.Count; i++) { CountPositivesA[i] = 0; CountNegativeA[i] = 0; } for (int i = 0; i < Examples.Count; i++) { int j = A.LValue.IndexOf(Examples[i][Col].ToString()); if (Examples[i][Examples[0].Count - 1] == "yes") { CountPositives++; CountPositivesA[j]++; } else { CountNegativeA[j]++; } } result = GetEntropy(CountPositives, Examples.Count - CountPositives); for (int i = 0; i < A.LValue.Count; i++) { double RateValue = (double)(CountPositivesA[i] + CountNegativeA[i]) / Examples.Count; result = result - RateValue * GetEntropy(CountPositivesA[i], CountNegativeA[i]); } Solution = Solution + "\n * Gain(" + bestat + "," + A.Name + ") = " + result.ToString(); return result; }
public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) { PropertyDescriptorCollection newProps = new PropertyDescriptorCollection(null); newProps.Add(new RuleConditionReferenceNamePropertyDescriptor(context, TypeDescriptor.CreateProperty(typeof(RuleConditionReference), "ConditionName", typeof(string), new DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Content), DesignOnlyAttribute.Yes))); newProps.Add(new RuleConditionReferencePropertyDescriptor(context, TypeDescriptor.CreateProperty(typeof(RuleConditionReference), "Expression", typeof(CodeExpression), new DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Content), DesignOnlyAttribute.Yes))); return newProps.Sort(new string[] { "ConditionName", "Expression" }); }
public void SetBossInfo(string name_, Attribute attribute_, float max_HP_, float DEF_) { boss_name = string.Copy(name_); attribute = attribute_; max_HP = max_HP_; DEF = DEF_; ApplyStageLevel(); }
public Table(String tabName, List<Attribute> tabAttrList, List<String> tabSelectivityList, Attribute tabPrimaryKey, int tabSize) { this.tableName = tabName; this.tableAttributeList = tabAttrList; this.tablePrimaryKey = tabPrimaryKey; this.tableSize = tabSize; this.tableSelectivityList = tabSelectivityList; }
public AttributeEventArgs(Attribute _attribute, AttributeValue _newValue, AttributeValue _oldValue, NotifyCollectionChangedAction _action) : base() { this.attribute = _attribute; this.newValue = _newValue; this.oldValue = _oldValue; this.action = _action; }
// Constructor. public AttributeCollection(Attribute[] attributes) { coll = new ArrayList(); if(attributes != null) { coll.AddRange(attributes); } }
public static T GetAttribute <T>( this MemberInfo attributeHost) where T : Attribute { return((T)Attribute.GetCustomAttribute(attributeHost, typeof(T))); }
public float ratio; //the percent of the attributes AdjustedBaseValue that will be applied to the ModifiedStat /// <summary> /// Initializes a new instance of the <see cref="ModifyingAttribute"/> struct. /// </summary> /// <param name='att'> /// Att. the attribute to be used /// </param> /// <param name='rat'> /// Rat. the ratio to use /// </param> public ModifyingAttribute(Attribute att, float rat) { // UnityEngine.Debug.Log("Modifying Attribute Created:" + att.Name + " -> " + rat); attribute = att; ratio = rat; }
private static SpedRegistrosAttribute ObtemAtributoAtual(Type tipo) { return((SpedRegistrosAttribute)Attribute.GetCustomAttribute(tipo, typeof(SpedRegistrosAttribute))); }
//Only called after compilling done, only one call, for performance private static void RefreshAllVisualComponent() { //DIAttributeData.Instance.components = typeof(DIVisualComponent).Assembly.GetTypes().Where(type => type.IsSubclassOf(typeof(DIVisualComponent))).ToList(); DIAttributeData.Instance.components = (from assembly in AppDomain.CurrentDomain.GetAssemblies() from type in assembly.GetTypes() where type.IsSubclassOf(typeof(DIVisualComponent)) select(System.Type) type).ToList(); DIAttributeData.Instance.componentPathPopup.Clear(); DIAttributeData.Instance.componentPathPopup.Add("Component"); foreach (Type comp in DIAttributeData.Instance.components) { VisualComponentAttribute att = (VisualComponentAttribute)Attribute.GetCustomAttribute(comp, typeof(VisualComponentAttribute)); if (att != null) { DIAttributeData.Instance.componentPathPopup.Add(att.path + "/" + AddSpacesToSentence(comp.Name, true)); DIAttributeData.Instance.componentsWithAttribute.Add(comp); } } var propertyDrawerCandidate = (from assembly in AppDomain.CurrentDomain.GetAssemblies() from type in assembly.GetTypes() where type.IsSubclassOf(typeof(VSPropertyDrawer)) select(System.Type) type).ToArray(); DIAttributeData.Instance.propertyDrawers.Clear(); foreach (Type drawer in propertyDrawerCandidate) { VSCustomPropertyDrawerAttribute att = (VSCustomPropertyDrawerAttribute)Attribute.GetCustomAttribute(drawer, typeof(VSCustomPropertyDrawerAttribute)); if (att != null) { DIAttributeData.Instance.propertyDrawers.Add(new DIAttributeData.VSCustomPropertyDrawerAttributeData(att, drawer)); } } }
/// <summary> /// Determines whether any custom attributes are applied to an assembly. Parameters specify the assembly, the /// type of the custom attribute to search for, and an ignored search option. /// </summary> /// <param name="element">An object derived from the class that describes a reusable collection of modules.</param> /// <param name="attributeType">The type, or a base type, of the custom attribute to search for.</param> /// <param name="inherit">This parameter is ignored, and does not affect the operation of this method.</param> /// <returns>true if a custom attribute of type is applied to ; otherwise, false.</returns> public static bool IsDefined([NotNull] this Assembly element, Type attributeType, bool inherit) { return(Attribute.IsDefined(element, attributeType, inherit)); }
public static string GetEnumDescription(FieldInfo info) { var attr = Attribute.GetCustomAttribute(info, typeof(AGPEnumAttribute)) as AGPEnumAttribute; return(attr == null ? null : attr.Name); }
/// <summary> /// Retrieves a collection of custom attributes of a specified type that are applied to a specified assembly. /// </summary> /// <param name="element">The assembly to inspect.</param> /// <param name="attributeType">The type of attribute to search for.</param> /// <returns> /// A collection of the custom attributes that are applied to element and that match <paramref name="attributeType"/>, /// or an empty collection if no such attributes exist. /// </returns> public static IEnumerable <Attribute> GetCustomAttributes(this Assembly element, Type attributeType) => Attribute.GetCustomAttributes(element, attributeType);
/// <summary> /// Retrieves a collection of custom attributes that are applied to a specified parameter, /// and optionally inspects the ancestors of that parameter. /// </summary> /// <param name="element">The parameter to inspect.</param> /// <param name="inherit"><c>true</c> to inspect the ancestors of element; otherwise, <c>false</c>.</param> /// <returns> /// A collection of the custom attributes that are applied to element that match the specified criteria, /// or an empty collection if no such attributes exist. /// </returns> public static IEnumerable <Attribute> GetCustomAttributes(this ParameterInfo element, bool inherit) => Attribute.GetCustomAttributes(element, inherit);
/// <summary> /// Retrieves a collection of custom attributes that are applied to a specified member. /// </summary> /// <param name="element">The member to inspect.</param> /// <returns> /// A collection of the custom attributes that are applied to element, /// or an empty collection if no such attributes exist. /// </returns> public static IEnumerable <Attribute> GetCustomAttributes(this MemberInfo element) => Attribute.GetCustomAttributes(element);
/// <summary> /// 获取方法级过滤器特性 /// </summary> /// <returns></returns> public virtual IEnumerable <FilterAttribute> GetMethodFilterAttributes() { return(Attribute.GetCustomAttributes(this.Method, typeof(FilterAttribute), true).Cast <FilterAttribute>()); }
void PrepareType() { var mainPrepareResult = RunMethod <HarmonyPrepare, bool>(true); if (mainPrepareResult == false) { return; } var customOriginals = RunMethod <HarmonyTargetMethods, IEnumerable <MethodBase> >(null); if (customOriginals != null) { originals = customOriginals.ToList(); } else { var originalMethodType = containerAttributes.methodType; // MethodType default is Normal if (containerAttributes.methodType == null) { containerAttributes.methodType = MethodType.Normal; } var isPatchAll = Attribute.GetCustomAttribute(container, typeof(HarmonyPatchAll)) != null; if (isPatchAll) { var type = containerAttributes.declaringType; originals.AddRange(AccessTools.GetDeclaredConstructors(type).Cast <MethodBase>()); originals.AddRange(AccessTools.GetDeclaredMethods(type).Cast <MethodBase>()); var props = AccessTools.GetDeclaredProperties(type); originals.AddRange(props.Select(prop => prop.GetGetMethod(true)).Where(method => method != null).Cast <MethodBase>()); originals.AddRange(props.Select(prop => prop.GetSetMethod(true)).Where(method => method != null).Cast <MethodBase>()); } else { var original = RunMethod <HarmonyTargetMethod, MethodBase>(null); if (original == null) { original = GetOriginalMethod(); } if (original == null) { var info = "("; info += "declaringType=" + containerAttributes.declaringType + ", "; info += "methodName =" + containerAttributes.methodName + ", "; info += "methodType=" + originalMethodType + ", "; info += "argumentTypes=" + containerAttributes.argumentTypes.Description(); info += ")"; throw new ArgumentException("No target method specified for class " + container.FullName + " " + info); } originals.Add(original); } } PatchTools.GetPatches(container, out prefix.method, out postfix.method, out transpiler.method); if (prefix.method != null) { if (prefix.method.IsStatic == false) { throw new ArgumentException("Patch method " + prefix.method.FullDescription() + " must be static"); } var prefixAttributes = prefix.method.GetHarmonyMethods(); containerAttributes.Merge(HarmonyMethod.Merge(prefixAttributes)).CopyTo(prefix); } if (postfix.method != null) { if (postfix.method.IsStatic == false) { throw new ArgumentException("Patch method " + postfix.method.FullDescription() + " must be static"); } var postfixAttributes = postfix.method.GetHarmonyMethods(); containerAttributes.Merge(HarmonyMethod.Merge(postfixAttributes)).CopyTo(postfix); } if (transpiler.method != null) { if (transpiler.method.IsStatic == false) { throw new ArgumentException("Patch method " + transpiler.method.FullDescription() + " must be static"); } var infixAttributes = transpiler.method.GetHarmonyMethods(); containerAttributes.Merge(HarmonyMethod.Merge(infixAttributes)).CopyTo(transpiler); } }
public static void RegisterMessage <TMsg>(Func <MySyncLayer, ITransportCallback <TMsg> > factory, MyTransportMessageEnum messageType = MyTransportMessageEnum.Request) where TMsg : struct { Debug.Assert(Attribute.IsDefined(typeof(TMsg), typeof(MessageIdAttribute)), "Message has no MessageId"); m_registrators.Add(new Registrator <TMsg>((layer) => factory(layer), messageType)); }
public static TableAttribute GetTableAttribute(Type source) { return((TableAttribute)Attribute.GetCustomAttribute(source, typeof(TableAttribute))); }
internal static string BuildResourceKey(Type containerType, string memberName, Attribute attribute) { return(BuildResourceKey(BuildResourceKey(containerType, memberName), attribute)); }
/// <summary> /// Retrieves an array of the custom attributes applied to an assembly. Parameters specify the assembly, and the /// type of the custom attribute to search for. /// </summary> /// <param name="element">An object derived from the class that describes a reusable collection of modules.</param> /// <param name="attributeType">The type, or a base type, of the custom attribute to search for.</param> /// <returns> /// An array that contains the custom attributes of type applied to , or an empty array if no such custom /// attributes exist. /// </returns> public static Attribute[] GetCustomAttributes([NotNull] this Assembly element, Type attributeType) { return(Attribute.GetCustomAttributes(element, attributeType)); }
private bool IsHighPriority(MessageIDs ID) => Attribute.IsDefined(typeof(MessageIDs).GetField(Enum.GetName(typeof(MessageIDs), ID)), typeof(HighPriorityAttribute));
/// <summary> /// Retrieves a custom attribute applied to an assembly. Parameters specify the assembly, the type of the custom /// attribute to search for, and an ignored search option. /// </summary> /// <param name="element">An object derived from the class that describes a reusable collection of modules.</param> /// <param name="attributeType">The type, or a base type, of the custom attribute to search for.</param> /// <param name="inherit">This parameter is ignored, and does not affect the operation of this method.</param> /// <returns> /// A reference to the single custom attribute of type that is applied to , or null if there is no such /// attribute. /// </returns> public static Attribute GetCustomAttribute([NotNull] this Assembly element, Type attributeType, bool inherit) { return(Attribute.GetCustomAttribute(element, attributeType, inherit)); }
/// <summary> /// Retrieves an array of the custom attributes applied to an assembly. Parameters specify the assembly, and an /// ignored search option. /// </summary> /// <param name="element">An object derived from the class that describes a reusable collection of modules.</param> /// <param name="inherit">This parameter is ignored, and does not affect the operation of this method.</param> /// <returns> /// An array that contains the custom attributes applied to , or an empty array if no such custom attributes /// exist. /// </returns> public static Attribute[] GetCustomAttributes([NotNull] this Assembly element, bool inherit) { return(Attribute.GetCustomAttributes(element, inherit)); }
protected override bool Skip(Attribute attr) { return(base.Skip(attr)); }
private bool MethodHasIgnoreStackTraceAttribute(MethodBase method) { return(Attribute.GetCustomAttribute(method, typeof(IgnoreStackTrace)) != null); }
// Token: 0x06000E22 RID: 3618 RVA: 0x00037EE8 File Offset: 0x000360E8 public static Guid GetGuidOfType(Type type) { GuidAttribute guidAttribute = (GuidAttribute)Attribute.GetCustomAttribute(type, typeof(GuidAttribute), false); return(new Guid(guidAttribute.Value)); }
public static Attribute GetCustomAttribute(this MemberInfo self, Type type) { return(Attribute.GetCustomAttribute(self, type)); }
private string GetBindingType(Attribute scenarioStepAttr) { var attrName = scenarioStepAttr.GetType().Name; return(attrName.Remove(attrName.Length - "Attribute".Length)); }
public void AddAttribute(Attribute attribute) { attributes.Add(attribute); }
static PropertyValues ToStringValues(Type collectionType, IEnumerable collection, params DataTypeOption[] typeOptions) { var dataTypeSet = GetDatabaseTypes(); var customTypeDictionary = typeOptions.ToDictionary(o => o.PropertyType); foreach (var dt in BaseTransforms()) { if (!customTypeDictionary.ContainsKey(dt.PropertyType)) { customTypeDictionary.Add(dt.PropertyType, dt); } } List<DataTypeOption> nullables = new List<DataTypeOption>(customTypeDictionary.Count); foreach (var kv in customTypeDictionary) { if (kv.Key.IsValueType && !kv.Key.IsGenericType) { Type nullable = typeof(Nullable<>).MakeGenericType(kv.Key); if (!customTypeDictionary.ContainsKey(nullable)) { nullables.Add(new DataTypeOption(nullable, (o, attr) => o == null ? "" : kv.Value.GetString(o, attr))); } } } foreach (var n in nullables) { customTypeDictionary.Add(n.PropertyType, n); } PropertyInfo[] allProps = collectionType.GetProperties(BindingFlags.Public | BindingFlags.Instance); List<PropertyDetail> headers = new List<PropertyDetail>(allProps.Length); List<Func<object,string>> propertyConverters = new List<Func<object,string>>(allProps.Length); foreach (PropertyInfo pi in allProps) { if (pi.GetIndexParameters().Length > 0) { continue; } if (pi.CanRead && !Attribute.IsDefined(pi, typeof(NotMappedAttribute))) { if (customTypeDictionary.TryGetValue(pi.PropertyType, out DataTypeOption dto) || dataTypeSet.Contains(pi.PropertyType) || pi.PropertyType.IsEnum) { object[] atts = pi.GetCustomAttributes(false); if (dto == null) { if (pi.PropertyType.IsEnum) { propertyConverters.Add(new Func<object, string>(o => { var convert = pi.GetValue(o, null); if (convert == null) { return ""; } return Convert.ToInt32(convert).ToString(); })); } else if (pi.PropertyType.IsGenericType && pi.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>)) { propertyConverters.Add(new Func<object, string>(o => { object val = pi.GetValue(o, null); if (val == null) { return ""; } return val.ToString(); })); } else { propertyConverters.Add(new Func<object, string>(o => pi.GetValue(o, null).ToString())); } } else { propertyConverters.Add(new Func<object, string>(o => dto.GetString(pi.GetValue(o, null), atts))); } DisplayAttribute attr = (DisplayAttribute)atts.FirstOrDefault(a => a.GetType() == typeof(DisplayAttribute)); headers.Add(new PropertyDetail { Name = pi.Name, BaseType = Nullable.GetUnderlyingType(pi.PropertyType) ?? pi.PropertyType, Attributes = atts }); } } } string[][] stringVals = new string[GetCount(collection)][]; int row = 0; foreach(object o in collection) { string[] currentRow = stringVals[row++] = new string[headers.Count]; for (int col =0;col<headers.Count;col++) { currentRow[col] = propertyConverters[col](o); } } return new PropertyValues { PropertiesDetail = headers, StringValues = stringVals // collection.Select(c=>propertyConverters.Select(pc=>pc.Invoke(c)).ToArray()).ToArray() }; }
/// <summary> /// 获取类级过滤器特性 /// </summary> /// <returns></returns> public virtual IEnumerable <FilterAttribute> GetClassFilterAttributes() { return(Attribute.GetCustomAttributes(this.DeclaringService, typeof(FilterAttribute), true).Cast <FilterAttribute>()); }
/// <summary> /// Retrieves a custom attribute of a specified type that is applied to a specified parameter, /// and optionally inspects the ancestors of that parameter. /// </summary> /// <param name="element">The parameter to inspect.</param> /// <param name="attributeType">The type of attribute to search for.</param> /// <param name="inherit"><c>true</c> to inspect the ancestors of element; otherwise, <c>false</c>.</param> /// <returns>A custom attribute that matches <paramref name="attributeType"/>, or null if no such attribute is found.</returns> public static Attribute GetCustomAttribute(this ParameterInfo element, Type attributeType, bool inherit) => Attribute.GetCustomAttribute(element, attributeType, inherit);
/// <summary> /// Retrieves a collection of custom attributes that are applied to a specified module. /// </summary> /// <param name="element">The module to inspect.</param> /// <returns> /// A collection of the custom attributes that are applied to element, /// or an empty collection if no such attributes exist. /// </returns> public static IEnumerable <Attribute> GetCustomAttributes(this Module element) => Attribute.GetCustomAttributes(element);
public CustomMemberExtensions(Attribute additionalAttribute) { _additionalAttribute = additionalAttribute; }
public static XmlRpcServiceInfo CreateServiceInfo(Type type) { var svcInfo = new XmlRpcServiceInfo(); // extract service info var svcAttr = (XmlRpcServiceAttribute) Attribute.GetCustomAttribute(type, typeof(XmlRpcServiceAttribute)); if (svcAttr != null && svcAttr.Description != "") { svcInfo.Doc = svcAttr.Description; } if (svcAttr != null && svcAttr.Name != "") { svcInfo.Name = svcAttr.Name; } else { svcInfo.Name = type.Name; } // extract method info var methods = new Hashtable(); foreach (var itf in type.GetInterfaces()) { var itfAttr = (XmlRpcServiceAttribute) Attribute.GetCustomAttribute(itf, typeof(XmlRpcServiceAttribute)); if (itfAttr != null) { svcInfo.Doc = itfAttr.Description; } #if (!COMPACT_FRAMEWORK) var imap = type.GetInterfaceMap(itf); foreach (var mi in imap.InterfaceMethods) { ExtractMethodInfo(methods, mi, itf); } #else foreach (MethodInfo mi in itf.GetMethods()) { ExtractMethodInfo(methods, mi, itf); } #endif } foreach (var mi in type.GetMethods()) { var mthds = new ArrayList { mi }; var curMi = mi; while (true) { var baseMi = curMi.GetBaseDefinition(); if (baseMi.DeclaringType == curMi.DeclaringType) { break; } mthds.Insert(0, baseMi); curMi = baseMi; } foreach (MethodInfo mthd in mthds) { ExtractMethodInfo(methods, mthd, type); } } svcInfo.Methods = new XmlRpcMethodInfo[methods.Count]; methods.Values.CopyTo(svcInfo.Methods, 0); Array.Sort(svcInfo.Methods); return(svcInfo); }