public void ProvideAdvices(Weaver codeWeaver) { CustomAttributeDictionaryTask customAttributeDictionary = CustomAttributeDictionaryTask.GetTask(this.Project); IEnumerator<ICustomAttributeInstance> customAttributeEnumerator = customAttributeDictionary.GetCustomAttributesEnumerator(typeof(NotifyPropertyChangedAttribute), false); while (customAttributeEnumerator.MoveNext()) { PropertyDeclaration propertyDeclaration = customAttributeEnumerator.Current.TargetElement as PropertyDeclaration; if (propertyDeclaration == null || propertyDeclaration.Visibility == Visibility.Private) continue; MethodDefDeclaration getMethodDef; MethodDefDeclaration setMethodDef; GetPropertyAccessorDefinitions(propertyDeclaration, out getMethodDef, out setMethodDef); if (getMethodDef == null || setMethodDef == null) { continue; } NotifyPropertyChangedAdvice advice = new NotifyPropertyChangedAdvice( getMethodDef, setMethodDef); codeWeaver.AddMethodLevelAdvice(advice, new Singleton<MethodDefDeclaration>(setMethodDef), JoinPointKinds.BeforeMethodBody | JoinPointKinds.AfterMethodBodySuccess, null); } }
static void Main(string[] args) { AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve); var weaver = new Weaver(); var person = weaver.CreateProxy( x => new Person("Roger")); person.Name = "Roger"; }
public void ProvideAdvices(Weaver codeWeaver) { // Gets the dictionary of custom attributes. AnnotationRepositoryTask customAttributeDictionary = AnnotationRepositoryTask.GetTask(this.Project); // Requests an enumerator of all instances of our Singleton. IEnumerator<IAnnotationInstance> customAttributeEnumerator = customAttributeDictionary.GetAnnotationsOfType(typeof (SingletonAttribute), true); ICollection<TypeDefDeclaration> singletons = new HashSet<TypeDefDeclaration>(); // For each instance of our Singleton. while (customAttributeEnumerator.MoveNext()) { // Gets the type to which it applies. TypeDefDeclaration typeDef = customAttributeEnumerator.Current.TargetElement as TypeDefDeclaration; if (typeDef != null && !singletons.Contains(typeDef)) { singletons.Add(typeDef); codeWeaver.AddTypeLevelAdvice(new SingletonAccessorAdvice(typeDef), JoinPointKinds.BeforeStaticConstructor, new Singleton<TypeDefDeclaration>(typeDef)); codeWeaver.AddMethodLevelAdvice(new SingletonAdvice(typeDef), null, JoinPointKinds.InsteadOfNewObject, new Singleton<MetadataDeclaration>( typeDef.Methods.GetOneByName(".ctor"))); } } singletons.Clear(); foreach (AssemblyRefDeclaration assembly in this.Project.Module.AssemblyRefs) { foreach (TypeRefDeclaration type in assembly.TypeRefs) { TypeDefDeclaration def = type.GetTypeDefinition(); foreach (CustomAttributeDeclaration att in def.CustomAttributes) { if (Equals(att.Constructor.DeclaringType.GetSystemType(new Type[] {}, new Type[] {}), typeof (SingletonAttribute))) { singletons.Add(def); } } } } foreach (TypeDefDeclaration type in singletons) { codeWeaver.AddMethodLevelAdvice(new SingletonAdvice(type), null, JoinPointKinds.InsteadOfNewObject, new Singleton<MetadataDeclaration>(type.Methods.GetOneByName(".ctor"))); } }
public void ProvideAdvices(Weaver codeWeaver) { // Gets the dictionary of custom attributes. AnnotationRepositoryTask customAttributeDictionary = AnnotationRepositoryTask.GetTask(this.Project); // Requests an enumerator of all instances of our NonNullAttribute. IEnumerator<IAnnotationInstance> customAttributeEnumerator = customAttributeDictionary.GetAnnotationsOfType(typeof (NonNullAttribute), true); // Simulating a Set IDictionary<MethodDefDeclaration, MethodDefDeclaration> methods = new Dictionary<MethodDefDeclaration, MethodDefDeclaration>(); // For each instance of our NonNullAttribute. while (customAttributeEnumerator.MoveNext()) { // Gets the parameters to which it applies. ParameterDeclaration paramDef = customAttributeEnumerator.Current.TargetElement as ParameterDeclaration; if (paramDef != null) { if ((paramDef.Attributes & ParameterAttributes.Retval) == ParameterAttributes.Retval) { codeWeaver.AddMethodLevelAdvice(new NonNullReturnAdvice(), new Singleton<MethodDefDeclaration>(paramDef.Parent), JoinPointKinds.AfterMethodBodySuccess, null); } else { if (!methods.ContainsKey(paramDef.Parent)) { codeWeaver.AddMethodLevelAdvice(new NonNullParameterAdvice(paramDef), new Singleton<MethodDefDeclaration>(paramDef.Parent), JoinPointKinds.BeforeMethodBody, null); methods.Add(paramDef.Parent, paramDef.Parent); } } } } }
public void ProvideAdvices(Weaver codeWeaver) { // Gets the dictionary of custom attributes. CustomAttributeDictionaryTask customAttributeDictionary = CustomAttributeDictionaryTask.GetTask(this.Project); // Requests an enumerator of all instances of our NonEmptyAttribute. IEnumerator<ICustomAttributeInstance> customAttributeEnumerator = customAttributeDictionary.GetCustomAttributesEnumerator(typeof(NonEmptyAttribute), true); // For each instance of our NonEmptyAttribute. while (customAttributeEnumerator.MoveNext()) { // Gets the parameters to which it applies. ParameterDeclaration paramDef = customAttributeEnumerator.Current.TargetElement as ParameterDeclaration; if (paramDef != null) { if ((paramDef.Attributes & ParameterAttributes.Retval) == ParameterAttributes.Retval) { codeWeaver.AddMethodLevelAdvice(new NonEmptyReturnAdvice(), new Singleton<MethodDefDeclaration>(paramDef.Parent), JoinPointKinds.AfterMethodBodySuccess, null); } else { codeWeaver.AddMethodLevelAdvice(new NonEmptyParameterAdvice(), new Singleton<MethodDefDeclaration>(paramDef.Parent), JoinPointKinds.BeforeMethodBody, null); } } } }
static void Main(string[] args) { //全て.Net Framework上で実行したい場合はこちらをコメントアウト Weaver.Initialize(ComputeDeviceTypes.Gpu); //Weaver.Initialize(ComputeDeviceTypes.Cpu, 1); //複数デバイスがある場合は添字が必要 //MLPによるXORの学習 //Sample1.Run(); //MLPによるXORの学習【回帰版】 //Sample2.Run(); //MLPによるSin関数の学習 //Sample3.Run(); //MLPによるMNIST(手書き文字)の学習 //Sample4.Run(); //エクセルCNNの再現 //Sample5.Run(); //5層CNNによるMNISTの学習 //Sample6.Run(); //BatchNormを使った15層MLPによるMNISTの学習 //Sample7.Run(); //LSTMによるSin関数の学習 //Sample8.Run(); //SimpleなRNNによるRNNLM //Sample9.Run(); //LSTMによるRNNLM //Sample10.Run(); //Decoupled Neural Interfaces using Synthetic GradientsによるMNISTの学習 //Sample11.Run(); //Test11のDNIをcDNIとした //Sample12.Run(); //Deconvolution2Dのテスト(Winform) //new Sample13WinForm().ShowDialog(); //Test6を連結して実行 //Sample14.Run(); //CaffeモデルのVGGを読み込んで画像分類をさせるテスト //Sample15.Run(Sample15.VGGModel.VGG16); //VGG16またはVGG19を選択してください //ChainerモデルのTest5と同じ内容を読み込んで実行 //Sample16.Run(); //CaffeモデルのRESNETを読み込んで画像分類をさせるテスト //Sample17.Run(Sample17.ResnetModel.ResNet50); //任意のResnetモデルを選択してください //CIFAR-10を5層CNNを使って学習する //Sample18.Run(isCifar100:false, isFineLabel:false); //CaffeモデルのAlexNetを読み込んで画像分類をさせるテスト //Sample19.Run(); //Linearの分割実行 //SampleX.Run(); //ベンチマーク SingleBenchmark.Run(); Console.WriteLine("Test Done..."); Console.Read(); }
public void Setup() { _assembly = Weaver.Weave(Code); }