Ejemplo n.º 1
0
 internal Method(MethodDefinition methodDefinition) : base(Builder.Current)
 {
     this.type             = methodDefinition.DeclaringType.ToBuilderType();
     this.methodDefinition = methodDefinition;
     this.methodReference  = methodDefinition.CreateMethodReference();
 }
Ejemplo n.º 2
0
 public void MoveTo(BuilderType type)
 {
     this.Remove();
     type.typeDefinition.CustomAttributes.Add(attribute);
 }
Ejemplo n.º 3
0
 internal Method(Builder builder, MethodReference methodReference, MethodDefinition methodDefinition) : base(builder)
 {
     this.type             = new BuilderType(builder, methodReference.DeclaringType);
     this.methodDefinition = methodDefinition;
     this.methodReference  = methodReference;
 }
Ejemplo n.º 4
0
 internal Field(BuilderType type, FieldDefinition fieldDefinition, FieldReference fieldReference) : base(type)
 {
     this.fieldDef = fieldDefinition;
     this.fieldRef = fieldReference;
     this.type     = type;
 }
Ejemplo n.º 5
0
 public static BuilderCustomAttribute Create(BuilderType attributeType, IEnumerable <CustomAttributeArgument> attributeArguments) =>
 CreateInternal(attributeType, () => attributeArguments.Select(x => new Tuple <TypeReference, object>(x.Type, x.Value)).ToArray());
Ejemplo n.º 6
0
 public BuilderType CreateType(string namespaceName, TypeAttributes attributes, string typeName, BuilderType baseType) => this.CreateType(namespaceName, attributes, typeName, baseType.typeReference);
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
 internal LocalVariable(BuilderType type, VariableDefinition variable, string name) : base(type)
 {
     this.variable = variable;
     this.type     = type;
     this.Name     = name;
 }
Ejemplo n.º 9
0
 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);
Ejemplo n.º 11
0
 internal LocalVariable(BuilderType type, VariableDefinition variable) : base(type)
 {
     this.variable = variable;
     this.type     = type;
     this.Name     = variable.Index.ToString();
 }
Ejemplo n.º 12
0
 public AttributedType(BuilderType type, BuilderCustomAttribute builderCustomAttribute) : base(type)
 {
     this.customAttribute = builderCustomAttribute.attribute;
     this.Type            = type;
     this.Attribute       = builderCustomAttribute;
 }
Ejemplo n.º 13
0
        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));
        }
Ejemplo n.º 14
0
 public static BuilderCustomAttribute Create(BuilderType attributeType, object[] parameters) =>
 CreateInternal(attributeType, () => parameters.Select(x => new Tuple <TypeReference, object>(GetTypeReference(x), x)).ToArray());
Ejemplo n.º 15
0
 static AsyncMethodHelper()
 {
     asyncStateMachineAttribute = Builder.Current.GetType("System.Runtime.CompilerServices.AsyncStateMachineAttribute");
     iAsyncStateMachine         = Builder.Current.GetType("System.Runtime.CompilerServices.IAsyncStateMachine");
 }
Ejemplo n.º 16
0
 public static bool IsSubclassOf(this BuilderType child, BuilderType parent) => child.typeDefinition != parent.typeDefinition && child.BaseClasses.Any(x => x.typeDefinition == parent.typeDefinition);
Ejemplo n.º 17
0
 public BuilderType MakeArray(BuilderType type) => new BuilderType(this, new ArrayType(this.moduleDefinition.ImportReference(type.typeReference)));
Ejemplo n.º 18
0
 public static void Log(this CecilatorObject cecilatorObject, LogTypes logTypes, BuilderType type, object arg) => cecilatorObject.Log(logTypes, type.GetRelevantConstructors().FirstOrDefault() ?? type.Methods.FirstOrDefault(), arg);
Ejemplo n.º 19
0
 public IEnumerable <AttributedType> FindTypesByAttribute(BuilderType attributeType) => this.FindTypesByAttribute(SearchContext.Module, attributeType);
Ejemplo n.º 20
0
 internal AttributedType(BuilderType type, CustomAttribute customAttribute) : base(type)
 {
     this.customAttribute = customAttribute;
     this.Type            = type;
     this.Attribute       = new BuilderCustomAttribute(type.Builder, type.typeDefinition, customAttribute);
 }
Ejemplo n.º 21
0
 internal Field(BuilderType type, FieldDefinition field) : base(type)
 {
     this.fieldDef = field;
     this.fieldRef = field.CreateFieldReference();
     this.type     = type;
 }
Ejemplo n.º 22
0
 public Field CreateField(BuilderType type, string name) => this.CreateField(type.typeReference, name);
Ejemplo n.º 23
0
 internal Method(BuilderType type, MethodReference methodReference, MethodDefinition methodDefinition) : base(type)
 {
     this.type             = type;
     this.methodDefinition = methodDefinition;
     this.methodReference  = methodReference;
 }
Ejemplo n.º 24
0
 public ICatch Catch(BuilderType exceptionType, Action <ICatchCode> body) => this.Catch(exceptionType.typeReference, body);