コード例 #1
0
        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);
                    });
        }
コード例 #2
0
ファイル: Assembly.cs プロジェクト: CodeAsm/open-sauce
			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;
			}
コード例 #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));
 }
コード例 #4
0
 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;
 }
コード例 #5
0
ファイル: MethodInfo.cs プロジェクト: niik/RxSpy
 public MethodInfo(bcl.MethodBase method)
 {
     Namespace = method.Name;
     DeclaringType = method.DeclaringType.Name;
     Name = GetName(method);
     Signature = Name + " (" + GetArguments(method) + ")";
 }
コード例 #6
0
        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
        }
コード例 #7
0
ファイル: Call.cs プロジェクト: nstone101/Cosmos
	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;
	}
コード例 #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));
 }
コード例 #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;
 }
コード例 #10
0
ファイル: Assembly.cs プロジェクト: CodeAsm/open-sauce
			/// <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;
			}
コード例 #11
0
ファイル: ReflectionHelper.cs プロジェクト: nobled/mono
		AssemblyNameReference GetAssemblyNameReference (SR.AssemblyName name)
		{
			foreach (AssemblyNameReference reference in m_module.AssemblyReferences)
				if (reference.FullName == name.FullName)
					return reference;

			return null;
		}
コード例 #12
0
 public ReflectionAssemblyReference(MetadataHost host, SR.Assembly assembly)
     : base(host)
 {
     mAssembly = assembly;
     FullName = mAssembly.FullName;
     Name = mAssembly.GetName().Name;
     Location = mAssembly.Location;
 }
コード例 #13
0
ファイル: MethodInfo.cs プロジェクト: niik/RxSpy
        string GetArgument(bcl.ParameterInfo arg)
        {
            if (arg.ParameterType.IsGenericParameter)
            {
            }

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

			return reference;
		}
コード例 #15
0
		static MethodReference TestImport (SR.MethodBase method)
		{
			AssemblyDefinition assembly = GetAssembly();
			MethodReference reference = assembly.MainModule.Import (method);
			assembly.MainModule.Import (method);
			CheckForDuplicates (assembly);

			return reference;
		}
コード例 #16
0
ファイル: MethodInfo.cs プロジェクト: niik/RxSpy
        string GetName(bcl.MethodBase method)
        {
            if (method.IsGenericMethod)
            {
                var genericArgs = method.GetGenericArguments();
                return method.Name + "<" + string.Join(", ", genericArgs.Select(TypeUtils.ToFriendlyName)) + ">";
            }

            return method.Name;
        }
コード例 #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;
        }
コード例 #18
0
ファイル: MethodInfo.cs プロジェクト: niik/RxSpy
        string GetArguments(bcl.MethodBase method)
        {
            var arguments = new List<string>();

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

            return string.Join(", ", arguments);
        }
コード例 #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);
        }
コード例 #20
0
ファイル: ReflectionHelper.cs プロジェクト: nobled/mono
		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;
		}
コード例 #21
0
ファイル: Import.cs プロジェクト: jm3105/cecil
        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;
        }
コード例 #22
0
ファイル: Import.cs プロジェクト: n017/Confuser
        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;
        }
コード例 #23
0
ファイル: ReflectionHelper.cs プロジェクト: pusp/o2platform
		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;
		}
コード例 #24
0
ファイル: Method.cs プロジェクト: Kalnor/monodevelop
 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;
                 }
             }
         }
     }
 }
コード例 #25
0
ファイル: Method.cs プロジェクト: Kalnor/monodevelop
 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;
 }
コード例 #26
0
ファイル: ObjectFormatter.cs プロジェクト: GloryChou/roslyn
        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;
        }
コード例 #27
0
ファイル: ReflectionHelper.cs プロジェクト: nobled/mono
		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;
		}
コード例 #28
0
ファイル: ReflectionHelper.cs プロジェクト: nobled/mono
		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 ();
		}
コード例 #29
0
ファイル: ReflectionHelper.cs プロジェクト: nobled/mono
		public MethodReference ImportMethodInfo (SR.MethodInfo mi, ImportContext context)
		{
			return ImportMethodBase (mi, mi.ReturnType, context);
		}
コード例 #30
0
ファイル: ReflectionHelper.cs プロジェクト: nobled/mono
		public MethodReference ImportConstructorInfo (SR.ConstructorInfo ci, ImportContext context)
		{
			return ImportMethodBase (ci, typeof (void), context);
		}