internal ILPropertyBuilder(ILTypeBuilder typeBuilder, PropertyInfo baseProperty) { this.ILTypeBuilder = typeBuilder; this.PropertyType = baseProperty.PropertyType; this.PropertyBuilder = this.ILTypeBuilder.TypeBuilder.DefineProperty(baseProperty.Name, baseProperty.Attributes, baseProperty.PropertyType, Type.EmptyTypes); this.Name = baseProperty.Name; if (baseProperty.GetGetMethod() != null) { this._getMethodBuilder = typeBuilder.DefineOverrideMethod(baseProperty.GetGetMethod()); } if (baseProperty.GetSetMethod() != null) { this._setMethodBuilder = typeBuilder.DefineOverrideMethod(baseProperty.GetSetMethod()); } if (this._setMethodBuilder == null && this._getMethodBuilder == null) { throw new BuildException("Property does not contain any method."); } if (this._setMethodBuilder == null ? false : this._setMethodBuilder.IsStatic || this._getMethodBuilder == null ? false : this._getMethodBuilder.IsStatic) { throw new BuildException("Static property cannot override."); } this.BaseProperty = baseProperty; this.IsOverride = true; }
internal ILProperty(ILCoder coding, ILVariable instance, ILPropertyBuilder propertyBuilder) { this.Coding = coding; this._instance = instance; this._getMethodBuilder = propertyBuilder.GetMethod; this._setMethodBuilder = propertyBuilder.SetMethod; this.PropertyType = propertyBuilder.PropertyType; this.GetModifier = propertyBuilder.GetMethod == null ? AccessModifiers.Private : propertyBuilder.GetModifier; this.SetModifier = propertyBuilder.SetMethod == null ? AccessModifiers.Private : propertyBuilder.SetModifier; }
public ILMethodBuilder DefineOverrideMethod(MethodInfo baseMethod) { if (this._isBuild) { throw new DefinitionException("Tip daha önce derlenmiş. Derlenmiş tipler üzerinde yeni üye eklemesi yapılamaz."); } if (baseMethod == null) { throw new ArgumentNullException("baseMethod"); } Type tempBase = baseMethod.DeclaringType; bool isMethodOnAnyBases = tempBase == typeof(object); while (!tempBase.IsInterface && tempBase != typeof(object) && !isMethodOnAnyBases) { isMethodOnAnyBases = this.BaseType == tempBase; tempBase = tempBase.BaseType; } if (!isMethodOnAnyBases && Array.IndexOf(this._interfaces, baseMethod.DeclaringType) == -1) { throw new BuildException("Temel metot, temel sınıf ya da uygulanan arabirimlerin en az bir tanesinde tanımlanmış olmalıdır."); } if (baseMethod.IsStatic) { throw new BuildException("Static metotlar geçersiz kılınamaz."); } if (baseMethod.IsFinal) { throw new BuildException("Mühürlenmiş metotlar geçersiz kılınamaz."); } if (!baseMethod.IsVirtual) { throw new BuildException("Metodun hükümsüz kılınabilmesi için sanal veya soyut olması gerekiyor."); } ILMethodBuilder builder = new ILMethodBuilder(this, baseMethod); if (this._definedMethods.ContainsKey(baseMethod.Name)) { this._definedMethods[baseMethod.Name].Add(builder); } else { List <ILMethodBuilder> list = new List <ILMethodBuilder>(); list.Add(builder); this._definedMethods.Add(baseMethod.Name, list); } return(builder); }
public void DefineSetMethod(AccessModifiers modifier) { if (this.IsDefaultProperty) { throw new DefinitionException("Özellik zaten varsayılan olarak atanmış. Yeni bir ekleme yapılamaz."); } if (this._setMethodBuilder != null) { throw new DefinitionException("Set metodu daha önce tanımlanmış. Geçersiz kılınmış bir özellik olabilir."); } MethodAttributes attributes = MethodAttributes.ReuseSlot | ILPropertyBuilder._propMethodAttributes; switch (modifier) { case AccessModifiers.Public: attributes |= MethodAttributes.Public; break; case AccessModifiers.Protected: attributes |= MethodAttributes.Family; break; case AccessModifiers.ProtectedInternal: attributes |= MethodAttributes.FamORAssem; break; case AccessModifiers.Internal: attributes |= MethodAttributes.Assembly; break; case AccessModifiers.Private: attributes |= MethodAttributes.Private; break; } if (this.IsStatic) { attributes |= MethodAttributes.Static; } ILMethodBuilder setBuilder = this.ILTypeBuilder.DefineMethod("set_" + this.Name, attributes); setBuilder.AddParameter(this.PropertyType, "value", ParameterAttributes.None); setBuilder.SetReturnType(typeof(void)); this.PropertyBuilder.SetGetMethod(setBuilder.MethodBuilder); this._setMethodBuilder = setBuilder; }
public override ILLazy Call(string methodName, Type[] genericArgs, ILData[] invokeParams) { if (((IBuilder)this.Coding).IsBuild) { throw new CodingException("Metodun tanımlandığı tip derlenmiş. Derlenmiş metotların gövdesi yeniden yazılamaz."); } if (methodName == null) { throw new ArgumentNullException("methodName"); } ILLazy push = null; Type[] parameterTypes = ILExtentionUtils.ParametersToTypeList(invokeParams); ILMethodBuilder builder = this.Coding.CurrentMethod.ILTypeBuilder.FindMethod(methodName, parameterTypes); if (builder == null) { return(this.Coding.Base.Call(methodName, genericArgs, invokeParams)); } if (builder.IsStatic) { throw new MethodNotFoundException("Hedef obje, çağrılan metodu içermiyor veya metot statik."); } else if (builder.IsGeneric && (genericArgs == null || genericArgs.Length == 0)) { throw new ArgumentNullException("genericArgs", "Çağrılan yöntem bir generic tanımlama içeriyor."); } else { push = new ILLazyInvoke(this.Coding, this, builder, genericArgs, invokeParams); } if (push.ILType == typeof(void)) { ((IILPusher)push).Push(); return(null); } else { return(push); } }
public ILLazy Invoke(ILMethodBuilder methodBuilder, Type[] genericArgs, ILData[] invokeParams) { if (((IBuilder)this.Coding).IsBuild) { throw new CodingException("Metodun tanımlandığı tip derlenmiş. Derlenmiş metotların gövdesi yeniden yazılamaz."); } if (this.PinnedState == ILEmitter.PinnedState.Base) { throw new NotSupportedException("Bu metot base işaretçisi tarafından desteklenmiyor. This işaretçisi kullanılmalı."); } if (methodBuilder == null) { throw new ArgumentNullException("methodBuilder"); } if (methodBuilder.MethodBuilder.IsGenericMethod && (genericArgs == null || genericArgs.Length == 0)) { throw new ArgumentNullException("genericArgs", "Çağrılan yöntem bir generic tanımlama içeriyor."); } ILLazy push = null; if (methodBuilder.IsStatic) { throw new CodingException("Çağrılan metot statik olmamalı."); } else { push = new ILLazyInvoke(this.Coding, this, methodBuilder, genericArgs, invokeParams); } if (push.ILType == typeof(void)) { ((IILPusher)push).Push(); return(null); } else { return(push); } }
public ILMethodBuilder DefineMethod(string methodName, MethodAttributes attributes, CallingConventions conventions) { if (this._isBuild) { throw new DefinitionException("Tip daha önce derlenmiş. Derlenmiş tipler üzerinde yeni üye eklemesi yapılamaz."); } ILMethodBuilder builder = new ILMethodBuilder(this, methodName, attributes, conventions); if (this._definedMethods.ContainsKey(methodName)) { this._definedMethods[methodName].Add(builder); } else { List <ILMethodBuilder> list = new List <ILMethodBuilder>(); list.Add(builder); this._definedMethods.Add(methodName, list); } return(builder); }
public ILMethodBuilder FindMethod(string name, Type[] parameters) { if (this._isBuild) { throw new InvalidOperationException("Tip daha önce derlenmiş. Üye aramak, getirmek ve yönetmek için System.Reflection kullanılmalıdır."); } if (this._definedMethods.ContainsKey(name)) { List <ILMethodBuilder> methodsByName = this._definedMethods[name]; List <ILMethodBuilder> competibles = new List <ILMethodBuilder>(); for (int i = 0; i < methodsByName.Count; i++) { ILMethodBuilder builder = methodsByName[i]; Type[] containedParameters = builder.GetParameterTypes(); if (containedParameters.Length == parameters.Length) { bool parameterCompetible = containedParameters.Length == 0; //ArgCount 0 ise, methotlar uyumludur. for (int j = 0; j < containedParameters.Length; j++) { Type contain = containedParameters[j]; Type parameter = parameters[j]; if (!(parameterCompetible = (contain.IsGenericParameter || contain.IsAssignableFrom(parameter)))) { break; } } if (parameterCompetible) { competibles.Add(builder); } else { continue; } } else { continue; } } if (competibles.Count == 0) { return(null); } else { for (int i = 0; i < competibles.Count; i++) { ILMethodBuilder builder = competibles[i]; Type[] containedParameters = builder.GetParameterTypes(); if (containedParameters.Length == parameters.Length) { bool parameterCompetible = containedParameters.Length == 0; //ArgCount 0 ise, methotlar uyumludur. for (int j = 0; j < containedParameters.Length; j++) { Type contain = containedParameters[j]; Type parameter = parameters[j]; if (!(parameterCompetible = (contain.IsGenericParameter || contain.IsAssignableFrom(parameter)))) { break; } } if (parameterCompetible) { return(builder); } else { continue; } } else { continue; } } return(competibles[0]); } } else { return(null); } }