internal Method(MethodDefinition methodDefinition) : base(Builder.Current) { this.type = methodDefinition.DeclaringType.ToBuilderType(); this.methodDefinition = methodDefinition; this.methodReference = methodDefinition.CreateMethodReference(); }
public void MoveTo(BuilderType type) { this.Remove(); type.typeDefinition.CustomAttributes.Add(attribute); }
internal Method(Builder builder, MethodReference methodReference, MethodDefinition methodDefinition) : base(builder) { this.type = new BuilderType(builder, methodReference.DeclaringType); this.methodDefinition = methodDefinition; this.methodReference = methodReference; }
internal Field(BuilderType type, FieldDefinition fieldDefinition, FieldReference fieldReference) : base(type) { this.fieldDef = fieldDefinition; this.fieldRef = fieldReference; this.type = type; }
public static BuilderCustomAttribute Create(BuilderType attributeType, IEnumerable <CustomAttributeArgument> attributeArguments) => CreateInternal(attributeType, () => attributeArguments.Select(x => new Tuple <TypeReference, object>(x.Type, x.Value)).ToArray());
public BuilderType CreateType(string namespaceName, TypeAttributes attributes, string typeName, BuilderType baseType) => this.CreateType(namespaceName, attributes, typeName, baseType.typeReference);
public IEnumerable <AttributedType> FindTypesByAttribute(SearchContext searchContext, BuilderType attributeType) { var result = new ConcurrentBag <AttributedType>(); Parallel.ForEach(this.GetTypes(searchContext), type => { for (int i = 0; i < type.typeDefinition.CustomAttributes.Count; i++) { var name = type.typeDefinition.CustomAttributes[i].AttributeType.Resolve().FullName; if (attributeType.Fullname.GetHashCode() == name.GetHashCode() && attributeType.Fullname == name) { result.Add(new AttributedType(type, type.typeDefinition.CustomAttributes[i])); } } }); return(result); }
internal LocalVariable(BuilderType type, VariableDefinition variable, string name) : base(type) { this.variable = variable; this.type = type; this.Name = name; }
public static bool IsAssignableFrom(this BuilderType target, BuilderType source) => target == source || target.typeDefinition == source.typeDefinition || source.IsSubclassOf(target) || target.IsInterface && source.BaseClasses.Any(x => x.Implements(target));
public void Add(BuilderType customAttributeType, params object[] parameters) => this.Add(customAttributeType.typeReference, parameters);
internal LocalVariable(BuilderType type, VariableDefinition variable) : base(type) { this.variable = variable; this.type = type; this.Name = variable.Index.ToString(); }
public AttributedType(BuilderType type, BuilderCustomAttribute builderCustomAttribute) : base(type) { this.customAttribute = builderCustomAttribute.attribute; this.Type = type; this.Attribute = builderCustomAttribute; }
private static BuilderCustomAttribute CreateInternal(BuilderType attributeType, Func <Tuple <TypeReference, object>[]> paramFunc) { object ConvertToAttributeParameter(object value) { switch (value) { case Type systemtype: return(Builder.Current.Import(systemtype.ToBuilderType().typeReference)); default: return(value); } } Method ctor = null; var type = attributeType.Import(); var parameters = paramFunc(); if (parameters == null || parameters.Length == 0) { ctor = type.ParameterlessContructor; } else { ctor = type.Methods.FirstOrDefault(x => { if (x.Name != ".ctor") { return(false); } var @param = x.Parameters; if (@param.Length != parameters.Length) { return(false); } for (int i = 0; i < @param.Length; i++) { var parameterType = parameters[i]?.Item1; if (!@param[i].typeReference.AreReferenceAssignable(parameterType)) { return(false); } } return(true); }); } if (ctor == null) { throw new ArgumentException($"Unable to find matching ctor in '{attributeType.Name}' for parameters: '{ string.Join(", ", parameters.Select(x => x?.Item1?.FullName ?? "null"))}'."); } var attribute = new CustomAttribute(Builder.Current.Import(ctor.methodReference)); var ctorMethodReference = ctor.methodReference; if (ctorMethodReference.Parameters.Count > 0) { for (int i = 0; i < ctorMethodReference.Parameters.Count; i++) { attribute.ConstructorArguments.Add(new CustomAttributeArgument(Builder.Current.Import(ctorMethodReference.Parameters[i].ParameterType), ConvertToAttributeParameter(parameters[i].Item2))); } } return(new BuilderCustomAttribute(type.Builder, null, attribute)); }
public static BuilderCustomAttribute Create(BuilderType attributeType, object[] parameters) => CreateInternal(attributeType, () => parameters.Select(x => new Tuple <TypeReference, object>(GetTypeReference(x), x)).ToArray());
static AsyncMethodHelper() { asyncStateMachineAttribute = Builder.Current.GetType("System.Runtime.CompilerServices.AsyncStateMachineAttribute"); iAsyncStateMachine = Builder.Current.GetType("System.Runtime.CompilerServices.IAsyncStateMachine"); }
public static bool IsSubclassOf(this BuilderType child, BuilderType parent) => child.typeDefinition != parent.typeDefinition && child.BaseClasses.Any(x => x.typeDefinition == parent.typeDefinition);
public BuilderType MakeArray(BuilderType type) => new BuilderType(this, new ArrayType(this.moduleDefinition.ImportReference(type.typeReference)));
public static void Log(this CecilatorObject cecilatorObject, LogTypes logTypes, BuilderType type, object arg) => cecilatorObject.Log(logTypes, type.GetRelevantConstructors().FirstOrDefault() ?? type.Methods.FirstOrDefault(), arg);
public IEnumerable <AttributedType> FindTypesByAttribute(BuilderType attributeType) => this.FindTypesByAttribute(SearchContext.Module, attributeType);
internal AttributedType(BuilderType type, CustomAttribute customAttribute) : base(type) { this.customAttribute = customAttribute; this.Type = type; this.Attribute = new BuilderCustomAttribute(type.Builder, type.typeDefinition, customAttribute); }
internal Field(BuilderType type, FieldDefinition field) : base(type) { this.fieldDef = field; this.fieldRef = field.CreateFieldReference(); this.type = type; }
public Field CreateField(BuilderType type, string name) => this.CreateField(type.typeReference, name);
internal Method(BuilderType type, MethodReference methodReference, MethodDefinition methodDefinition) : base(type) { this.type = type; this.methodDefinition = methodDefinition; this.methodReference = methodReference; }
public ICatch Catch(BuilderType exceptionType, Action <ICatchCode> body) => this.Catch(exceptionType.typeReference, body);