/// <summary> /// Gets an attribute of a given type and then casts and returns a specified value /// </summary> /// <typeparam name="X">The type of the attribute</typeparam> /// <typeparam name="Y">The type of the value to return</typeparam> /// <param name="o">The object to check</param> /// <param name="PropertyName">The property name to look for</param> /// <param name="Default">Default to return if property or attribute does not exist</param> /// <returns>Either the casted property, or default</returns> public static Y AttributeRef <X, Y>(this IHasAttributes o, string PropertyName, Y Default) where Y : class { if (!o.HasAttribute <X>() || !o.Attribute <X>().HasProperty(PropertyName)) { return(Default); } return(o.Attribute <X>().GetProperty(PropertyName).GetValue <Y>() ?? Default); }
/// <summary> /// Gets an attribute of a given type and returns a nullable? of its value /// </summary> /// <typeparam name="X">The type of the attribute</typeparam> /// <typeparam name="Y">The type of the value to return</typeparam> /// <param name="o">The object to check</param> /// <param name="PropertyName">The property name to look for</param> /// <returns>A nullable struct representation of its value</returns> public static Y?AttributeNullable <X, Y>(this IHasAttributes o, string PropertyName) where Y : struct { if (!o.HasAttribute <X>() || !o.Attribute <X>().HasProperty(PropertyName)) { return(null); } return(o.Attribute <X>().GetProperty(PropertyName).GetValue <Y>()); }
/// <summary> /// Retrieves a property value of an attribute of a given type (non-reference) /// </summary> /// <typeparam name="Y">The type of the property to return</typeparam> /// <param name="o">The object to check</param> /// <param name="t">The type of the attribute to search for</param> /// <param name="PropertyName">The name of the property to retrieve the value for</param> /// <param name="Default">If the property is not found, this is the default to return in place of null</param> /// <returns>Either the casted property, or default</returns> public static Y AttributeStruct <Y>(this IHasAttributes o, Type t, string PropertyName, Y Default) where Y : struct { if (!o.HasAttribute(t) || !o.Attribute(t).HasProperty(PropertyName)) { return(Default); } return(o.Attribute(t).GetProperty(PropertyName).GetValue <Y>()); }
private void ApplyAuraEffect(IHasAttributes target, AuraEffect auraEffect) { var attributeEffect = auraEffect.AttributeEffect; var attributeName = attributeEffect.AffectedAttributeName; if (!target.HasAttribute(attributeName)) { return; } target.GetAttribute(attributeName).AddAttributeEffect(attributeEffect); _affectedAuraTargets.Add(target); }
/// <summary> /// Executes data-flow analysis /// </summary> public void Run() { IHasAttributes attrs = Code as IHasAttributes; if (attrs != null && attrs.HasAttribute <BreakOnDataflowAnalysis>()) { Debugger.Break(); } // Fixpoint iteration until the set of pre- and postconditions of each // instruction is complete. IterateToFixPoint(); // Analyze load points to determine which read accesses can be inlined. DetectEliminableAccesses(); // Try to split locals into distinct variables RenameLocals(); }