public static IEnumerable<Type> GetTypes() { if (Types == null) { Types = new List<Type>(); foreach (AssemblyPart part in Deployment.Current.Parts) { StreamResourceInfo info = Application.GetResourceStream(new Uri(part.Source, UriKind.Relative)); Assembly assembly = new AssemblyPart().Load(info.Stream); Types.AddRange(assembly.GetTypes()); } } return Types; }
public static List <MethodInfo> GetExtensionMethods(string name, DynamicMetaObject targetMO, DynamicMetaObject[] args) { List <MethodInfo> res = new List <MethodInfo>(); #if !SILVERLIGHT foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies()) { #else foreach (w.AssemblyPart ap in w.Deployment.Current.Parts) { StreamResourceInfo sri = w.Application.GetResourceStream(new Uri(ap.Source, UriKind.Relative)); Assembly a = new w.AssemblyPart().Load(sri.Stream); #endif Type[] types; try { types = a.GetTypes(); } catch (ReflectionTypeLoadException ex) { types = ex.Types; } foreach (Type t in types) { if (t != null && t.IsPublic && t.IsAbstract && t.IsSealed) { foreach (MethodInfo mem in t.GetMember(name, MemberTypes.Method, BindingFlags.Static | BindingFlags.Public | BindingFlags.IgnoreCase)) { //Should test using mem.IsDefined(attr) but typeof(ExtenssionAttribute) in Microsoft.Scription.Extensions and System.Core are infact two different types //Type attr = typeof(System.Runtime.CompilerServices.ExtensionAttribute); if (mem.GetParameters().Length == args.Length && mem.GetParameters()[0].ParameterType == targetMO.RuntimeType) { if (RuntimeHelpers.ParametersMatchArguments( mem.GetParameters(), args)) { res.Add(mem); } } } } } } return(res); }
public void DataTransferObject_PublicPropertySetterCallsOnPropertyChanged_Succeeds() { List<string> ignoredDtoProperties = new List<string> () { "Notifications" }; IDtoFactory dtoFactory = new DtoFactory (); foreach ( AssemblyPart assemblyPart in Deployment.Current.Parts ) { StreamResourceInfo sri = Application.GetResourceStream ( new Uri ( assemblyPart.Source, UriKind.Relative ) ); Assembly dtoAssembly = new AssemblyPart ().Load ( sri.Stream ); var allDtos = dtoAssembly.GetTypes () .Where ( t => typeof ( EditableDataTransferObject ).IsAssignableFrom ( t ) && !t.IsAbstract ) .Select ( t => new { Dto = dtoFactory.CreateDto ( t ), PropSet = t.GetProperties () .Select ( p => new { PropertyName = p.Name, PropertySetter = p.GetSetMethod () } ) .Where ( p => p.PropertySetter != null && !ignoredDtoProperties.Contains ( p.PropertyName ) ) } ); foreach ( var d in allDtos ) { INotifyPropertyChanged inpc = d.Dto; foreach ( var p in d.PropSet ) { // Setup event handler for the property being examined string changedPropertyName = String.Empty; // use named variable (as opposed to anonymous delegate) so we can unsubscribe PropertyChangedEventHandler inpcOnPropertyChanged = ( obj, e ) => changedPropertyName = e.PropertyName; inpc.PropertyChanged += inpcOnPropertyChanged; // Simulate property change by invoking setter directly p.PropertySetter.Invoke ( d.Dto, new object[] { null } ); Assert.AreEqual ( p.PropertyName, changedPropertyName, String.Format ( "Offending DTO type::property {0}::{1}", d.Dto.GetType (), p.PropertyName ) ); // Reset event handler inpc.PropertyChanged -= inpcOnPropertyChanged; } } } }