private static ResolvedParameter GetQueryHandlersParameter(Reflection.Assembly queryHandlersAssembly)
        {
            return new ResolvedParameter(
                (p, c) =>
                    {
                        var parameterType = p.ParameterType.GetGenericArguments().FirstOrDefault();

                        return parameterType != null &&
                               parameterType.GetGenericTypeDefinition() == typeof (IQueryHandler<>);
                    },
                (p, c) =>
                    {
                        var queryHandlerList = new ArrayList();

                        var queryHandlerType = p.ParameterType.GetGenericArguments().First();
                        var queryHandlerEntityType = queryHandlerType.GetGenericArguments().First();

                        foreach (var queryHandler in GetQueryHandlers(queryHandlersAssembly))
                        {
                            var specificQueryHandler = queryHandler.MakeGenericType(queryHandlerEntityType);

                            queryHandlerList.Add(c.Resolve(specificQueryHandler));
                        }

                        return queryHandlerList.ToArray(queryHandlerType);
                    });
        }
Esempio n. 2
0
			public static bool Exists(REF.Assembly ass, string path, string name)
			{
				try { using(Stream s = Open(ass, path, name)) {} }
				catch (FileNotFoundException) { return false; }

				return true;
			}
Esempio n. 3
0
 public static MethodDefinition FindMatchingMethod(this TypeDefinition tdef, SR.MethodBase minf, bool throwOnNotFound = false)
 {
     if (throwOnNotFound)
         return tdef.Methods.First(mdef => mdef.MethodMatches(minf));
     else
         return tdef.Methods.FirstOrDefault(mdef => mdef.MethodMatches(minf));
 }
 private static IEnumerable<Type> GetQueryHandlers(Reflection.Assembly assembly)
 {
     return from t in assembly.GetTypes()
            from i in t.GetInterfaces()
            where i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IQueryHandler<>)
            select t;
 }
Esempio n. 5
0
 public MethodInfo(bcl.MethodBase method)
 {
     Namespace = method.Name;
     DeclaringType = method.DeclaringType.Name;
     Name = GetName(method);
     Signature = Name + " (" + GetArguments(method) + ")";
 }
        public void Map_boolean_switch_creates_boolean_value()
        {
            // Fixture setup
            var tokenPartitions = new[]
                {
                    new KeyValuePair<string, IEnumerable<string>>("x", new [] { "true" })
                };
            var specProps = new[]
                {
                    SpecificationProperty.Create(
                        new OptionSpecification("x", string.Empty, false, string.Empty, Maybe.Nothing<int>(), Maybe.Nothing<int>(), '\0', Maybe.Nothing<object>(), string.Empty, string.Empty, new List<string>(), typeof(bool), TargetType.Switch),
                        typeof(Simple_Options).GetProperties().Single(p => p.Name.Equals("BoolValue", StringComparison.Ordinal)),
                        Maybe.Nothing<object>())
                };

            // Exercize system
            var result = OptionMapper.MapValues(
                specProps.Where(pt => pt.Specification.IsOption()),
                tokenPartitions,
                (vals, type, isScalar) => TypeConverter.ChangeType(vals, type, isScalar, CultureInfo.InvariantCulture, false),
                StringComparer.Ordinal
                );

            // Verify outcome
            Assert.NotNull(((Ok<IEnumerable<SpecificationProperty>, Error>)result).Success.Single(
                a => a.Specification.IsOption()
                && ((OptionSpecification)a.Specification).ShortName.Equals("x")
                && (bool)((Just<object>)a.Value).Value));

            // Teardown
        }
Esempio n. 7
0
	private static int GetNativePointerSize(SysReflection.MethodInfo xMethodInfo)
	{
		// old code, which goof up everything for structs
		//return (int)Align(SizeOfType(xMethodInfo.DeclaringType), 4);
		// TODO native pointer size, so that COSMOS could be 64 bit OS
		return 4;
	}
Esempio n. 8
0
 public static FieldDefinition FindMatchingField(this TypeDefinition tdef, SR.FieldInfo finf, bool throwOnNotFound = false)
 {
     if (throwOnNotFound)
         return tdef.Fields.First(fdef => fdef.FieldMatches(finf));
     else
         return tdef.Fields.FirstOrDefault(fdef => fdef.FieldMatches(finf));
 }
Esempio n. 9
0
 public DecompilationTestCase(SR.MethodInfo method, TestCaseType type, string filename, string resultFilename) : base(method)
 {
     this.TestName.Name = method.DeclaringType.FullName + "." + method.Name + "." + type.ToString();
     this.TestName.FullName = this.TestName.Name;
     this.resultFilename=resultFilename;
     this.type = type;
 }
Esempio n. 10
0
			/// <summary>
			/// Open a manifest file from <paramref name="ass"/>
			/// </summary>
			/// <param name="ass">Assembly to get the manifest file from</param>
			/// <param name="path">Type path to the file</param>
			/// <param name="name">File name (with extension)</param>
			/// <returns>Manifest file's stream</returns>
			/// <exception cref="Debug.ExceptionLog">When a <see cref="System.IO.FileNotFoundException"/> is encountered, it is caught and rethrown as a this type of exception</exception>
			public static Stream Open(REF.Assembly ass, string path, string name)
			{
				string manifest_path = string.Format("{0}{1}{2}", BasePath, path.Replace('\\', '.'), name);
				Stream s = null;
				try { s = ass.GetManifestResourceStream(manifest_path); }
				catch (FileNotFoundException) { throw new Debug.ExceptionLog("Manifest not found! {0}+{1}", ass.FullName, manifest_path); }
				return s;
			}
Esempio n. 11
0
		AssemblyNameReference GetAssemblyNameReference (SR.AssemblyName name)
		{
			foreach (AssemblyNameReference reference in m_module.AssemblyReferences)
				if (reference.FullName == name.FullName)
					return reference;

			return null;
		}
Esempio n. 12
0
 public ReflectionAssemblyReference(MetadataHost host, SR.Assembly assembly)
     : base(host)
 {
     mAssembly = assembly;
     FullName = mAssembly.FullName;
     Name = mAssembly.GetName().Name;
     Location = mAssembly.Location;
 }
Esempio n. 13
0
        string GetArgument(bcl.ParameterInfo arg)
        {
            if (arg.ParameterType.IsGenericParameter)
            {
            }

            return TypeUtils.ToFriendlyName(arg.ParameterType) + " " + arg.Name;
        }
		static FieldReference TestImport (SR.FieldInfo field)
		{
			AssemblyDefinition assembly = GetAssembly();
			FieldReference reference = assembly.MainModule.Import (field);
			assembly.MainModule.Import (field);
			CheckForDuplicates (assembly);

			return reference;
		}
		static MethodReference TestImport (SR.MethodBase method)
		{
			AssemblyDefinition assembly = GetAssembly();
			MethodReference reference = assembly.MainModule.Import (method);
			assembly.MainModule.Import (method);
			CheckForDuplicates (assembly);

			return reference;
		}
Esempio n. 16
0
        string GetName(bcl.MethodBase method)
        {
            if (method.IsGenericMethod)
            {
                var genericArgs = method.GetGenericArguments();
                return method.Name + "<" + string.Join(", ", genericArgs.Select(TypeUtils.ToFriendlyName)) + ">";
            }

            return method.Name;
        }
Esempio n. 17
0
        public static bool FieldMatches(this FieldReference field, SR.FieldInfo matches)
        {
            if (field.Name != matches.Name)
                return false;

            if (!field.FieldType.TypeMatches(matches.FieldType))
                return false;

            return true;
        }
Esempio n. 18
0
        string GetArguments(bcl.MethodBase method)
        {
            var arguments = new List<string>();

            foreach (var arg in method.GetParameters())
            {
                arguments.Add(GetArgument(arg));
            }

            return string.Join(", ", arguments);
        }
Esempio n. 19
0
        public void ApplyInjection(SR.Assembly injectionAssembly, SR.Assembly targetAssembly, Stream assemblyWriteStream)
        {
            var targetPath = targetAssembly.GetAssemblyPath();
            _targetModule = ModuleDefinition.ReadModule(targetPath);
            _injectionModule = ModuleDefinition.ReadModule(injectionAssembly.GetAssemblyPath());

            var injectees = GetInjectees(targetAssembly, injectionAssembly);
            ApplyInjectees(injectees);

            _targetModule.Assembly.Write(assemblyWriteStream);
        }
Esempio n. 20
0
		public AssemblyNameReference ImportAssembly (SR.Assembly asm)
		{
			AssemblyNameReference asmRef = GetAssemblyNameReference (asm.GetName ());
			if (asmRef != null)
				return asmRef;

			SR.AssemblyName asmName = asm.GetName ();
			asmRef = new AssemblyNameReference (
				asmName.Name, asmName.CultureInfo.Name, asmName.Version);
			asmRef.PublicKeyToken = asmName.GetPublicKeyToken ();
			asmRef.HashAlgorithm = (AssemblyHashAlgorithm) asmName.HashAlgorithm;
			asmRef.Culture = asmName.CultureInfo.ToString ();
			m_module.AssemblyReferences.Add (asmRef);
			return asmRef;
		}
Esempio n. 21
0
        bool TryGetAssemblyNameReference(SR.AssemblyName name, out AssemblyNameReference assembly_reference)
        {
            var references = module.AssemblyReferences;

            for (int i = 0; i < references.Count; i++) {
                var reference = references [i];
                if (name.FullName != reference.FullName) // TODO compare field by field
                    continue;

                assembly_reference = reference;
                return true;
            }

            assembly_reference = null;
            return false;
        }
Esempio n. 22
0
        bool TryGetAssemblyNameReference(SR.AssemblyName name, out AssemblyNameReference assembly_reference)
        {
            var references = module.AssemblyReferences;

            var pkt = name.GetPublicKeyToken();
            for (int i = 0; i < references.Count; i++) {
                var reference = references [i];
                if (name.Name != reference.Name || (pkt != null && pkt.Equals(reference.PublicKeyToken))) // TODO compare field by field
                    continue;

                assembly_reference = reference;
                return true;
            }

            assembly_reference = null;
            return false;
        }
Esempio n. 23
0
		public AssemblyNameReference ImportAssembly (SR.Assembly asm)
		{
			ImportCache ();

			AssemblyNameReference asmRef = (AssemblyNameReference) m_asmCache [asm.FullName];
			if (asmRef != null)
				return asmRef;

			SR.AssemblyName asmName = asm.GetName ();
			asmRef = new AssemblyNameReference (
				asmName.Name, asmName.CultureInfo.Name, asmName.Version);
			asmRef.PublicKeyToken = asmName.GetPublicKeyToken ();
			asmRef.HashAlgorithm = (Mono.Cecil.AssemblyHashAlgorithm) asmName.HashAlgorithm;
			asmRef.Culture = asmName.CultureInfo.ToString ();
			asmRef.Flags = (Mono.Cecil.AssemblyFlags) asmName.Flags;
			m_module.AssemblyReferences.Add (asmRef);
			m_asmCache [asm.FullName] = asmRef;
			return asmRef;
		}
Esempio n. 24
0
 void LoadXml (Class declaring, SR.MethodInfo methodBase)
 {
    if (declaring.xmlHelp != null) {
         XmlNodeList nodes = declaring.xmlHelp.SelectNodes ("/Type/Members/Member[@MemberName='" + FullyQualifiedName + "']");
         if (nodes != null && nodes.Count > 0) {
             if (nodes.Count == 1) {
                 node = nodes[0];
             } else {
                 node = FindMatch (nodes, methodBase);
             }
             if (node != null) {
                 XmlNode docNode = node.SelectSingleNode ("Docs/summary");
                 if (docNode != null) {
                     Documentation = docNode.InnerXml;
                 }
             }
         }
     }
 }
Esempio n. 25
0
 XmlNode FindMatch (XmlNodeList nodes, SR.MethodInfo methodBase)
 {
     SR.ParameterInfo[] p = methodBase.GetParameters ();
     string s = "";
     foreach (XmlNode node in nodes) {
         XmlNodeList paramList = node.SelectNodes ("Parameters/*");
         s += paramList.Count + " - " + p.Length + "\n";
         if (p.Length == 0 && paramList.Count == 0) return node;
         if (p.Length != paramList.Count) continue;
         bool matched = true;
         for (int i = 0; i < p.Length; i++) {
             if (p[i].ParameterType.ToString () != paramList[i].Attributes["Type"].Value) {
                 matched = false;
             }
         }
         if (matched)
             return node;
     }
     return null;
 }
Esempio n. 26
0
        private static DebuggerDisplayAttribute GetApplicableDebuggerDisplayAttribute(Ref.MemberInfo member)
        {
            var result = (DebuggerDisplayAttribute)member.GetCustomAttributes(typeof(DebuggerDisplayAttribute), inherit: true).FirstOrDefault();
            if (result != null)
            {
                return result;
            }

            // TODO (tomat): which assembly should we look at for dd attributes?
            Type type = member as Type;
            if (type != null)
            {
                foreach (DebuggerDisplayAttribute attr in type.Assembly.GetCustomAttributes(typeof(DebuggerDisplayAttribute), inherit: true))
                {
                    if (IsApplicableAttribute(type, attr.Target, attr.TargetTypeName))
                    {
                        return attr;
                    }
                }
            }
            return null;
        }
Esempio n. 27
0
		public FieldReference ImportFieldInfo (SR.FieldInfo fi, ImportContext context)
		{
			string sig = GetFieldSignature (fi);
			FieldReference f = (FieldReference) GetMemberReference (sig);
			if (f != null)
				return f;

			f = new FieldReference (
				fi.Name,
				ImportSystemType (fi.DeclaringType, context),
				ImportSystemType (fi.FieldType, context));

			m_module.MemberReferences.Add (f);
			return f;
		}
Esempio n. 28
0
		static string GetFieldSignature (SR.FieldInfo field)
		{
			StringBuilder sb = new StringBuilder ();
			sb.Append (GetTypeSignature (field.FieldType));
			sb.Append (' ');
			sb.Append (GetTypeSignature (field.DeclaringType));
			sb.Append ("::");
			sb.Append (field.Name);
			return sb.ToString ();
		}
Esempio n. 29
0
		public MethodReference ImportMethodInfo (SR.MethodInfo mi, ImportContext context)
		{
			return ImportMethodBase (mi, mi.ReturnType, context);
		}
Esempio n. 30
0
		public MethodReference ImportConstructorInfo (SR.ConstructorInfo ci, ImportContext context)
		{
			return ImportMethodBase (ci, typeof (void), context);
		}